package com.estate.expert.admin.service;
|
|
import com.estate.expert.admin.domain.business.car.*;
|
import com.estate.expert.admin.domain.common.EntityRef;
|
import lombok.extern.slf4j.Slf4j;
|
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.Assertions;
|
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.extension.ExtendWith;
|
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.boot.test.context.SpringBootTest;
|
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
import org.springframework.transaction.annotation.Transactional;
|
|
import javax.annotation.Resource;
|
import java.util.List;
|
|
@Slf4j
|
@SpringBootTest
|
@ExtendWith(SpringExtension.class)
|
@Transactional
|
public class CarServiceTest {
|
|
@Autowired
|
private CarService carService;
|
|
@Resource
|
private UserService userService;
|
|
|
Car currentCar;
|
|
@BeforeEach
|
public void setUp() {
|
var car = CarDto.builder()
|
.name("京ADR6379")
|
.departmentPath("/1")
|
.model("别克君越")
|
.build();
|
|
currentCar = carService.add(userService.getSystemUser(), car);
|
Assertions.assertNotNull(currentCar);
|
}
|
|
@AfterEach
|
public void tearDown() {
|
carService.deleteAllById(List.of(currentCar.getId()));
|
}
|
|
@Test
|
public void testEdit() {
|
var request = CarDto.builder()
|
.id(currentCar.getId())
|
.model("别克君越111")
|
.driver(EntityRef.of(2, "张三"))
|
.build();
|
|
carService.edit(request);
|
var car = carService.get(currentCar.getId());
|
Assertions.assertEquals("别克君越111", car.getName());
|
|
Assertions.assertNotNull(car.getDriver());
|
Assertions.assertEquals(2, car.getDriver().getId());
|
}
|
|
@Test
|
public void testList() {
|
var list = carService.list(null, "京ADR6");
|
Assertions.assertFalse(list.isEmpty());
|
|
list = carService.list(null, "京ADD37");
|
Assertions.assertTrue(list.isEmpty());
|
|
carService.deleteAllById(List.of(currentCar.getId()));
|
|
list = carService.list(null, "京ADR6");
|
Assertions.assertTrue(list.isEmpty());
|
}
|
|
|
}
|