diff --git a/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java b/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java index 40c903fa063f5653f93fdaa24096286795b53b21..3aadb019ea7f883093207a1c9d392c70234205a2 100644 --- a/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java +++ b/car/src/main/java/cz/muni/pa165/car/service/CarServiceImpl.java @@ -1,20 +1,20 @@ package cz.muni.pa165.car.service; +import static cz.muni.pa165.car.mapper.CarMapper.carConverterToDto; +import static cz.muni.pa165.car.mapper.CarMapper.carDtoConverter; + import cz.muni.pa165.car.data.model.Car; import cz.muni.pa165.car.data.repository.CarRepository; import cz.muni.pa165.car.mapper.CarMapper; -import static cz.muni.pa165.car.mapper.CarMapper.carConverterToDto; -import static cz.muni.pa165.car.mapper.CarMapper.carDtoConverter; import cz.muni.pa165.car.restemplate.DbGetter; import cz.muni.pa165.common_library.dtos.CarRequestDto; import cz.muni.pa165.common_library.dtos.CarResponseDto; import cz.muni.pa165.common_library.exception.DatabaseException; +import java.util.List; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; -import java.util.List; - /** * Service for car management. diff --git a/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java b/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java index 578d2fcf3b08d9ff6e5b6c7ae4c9dc9383ec3250..747d330f21baf1a9e8a5b5ef2efc65e4180d16b4 100644 --- a/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java +++ b/car/src/test/java/cz/muni/pa165/car/rest/CarComponentPairControllerTest.java @@ -2,6 +2,7 @@ package cz.muni.pa165.car.rest; import com.fasterxml.jackson.databind.ObjectMapper; import cz.muni.pa165.car.rest.CarDriverPairController; +import cz.muni.pa165.car.restemplate.DbGetter; import cz.muni.pa165.car.service.CarComponentPairService; import cz.muni.pa165.car.service.CarDriverPairService; import cz.muni.pa165.common_library.dtos.CarComponentResponseDto; @@ -16,6 +17,8 @@ import static org.mockito.BDDMockito.given; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; @@ -28,6 +31,7 @@ import java.util.List; @WebMvcTest(CarComponentPairController.class) +@Import(TestConfig.class) public class CarComponentPairControllerTest { @Autowired @@ -40,6 +44,7 @@ public class CarComponentPairControllerTest { private ObjectMapper objectMapper; + private static CarResponseDto carResponseDto; private static CarResponseDto carResponseDto2; // private static CarComponentRequestDto carComponentRequestDto; diff --git a/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java b/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java index 62d6b046358a47af2d6df9e31f504979c14732b7..dbe05c1b04f08b51caa1ab36b175f48bce2dcb07 100644 --- a/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java +++ b/car/src/test/java/cz/muni/pa165/car/rest/CarControllerTest.java @@ -1,30 +1,25 @@ package cz.muni.pa165.car.rest; +import static org.mockito.BDDMockito.given; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; + import com.fasterxml.jackson.databind.ObjectMapper; -import cz.muni.pa165.car.rest.CarController; import cz.muni.pa165.car.service.CarService; import cz.muni.pa165.common_library.dtos.CarRequestDto; import cz.muni.pa165.common_library.dtos.CarResponseDto; +import java.util.List; 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 static org.mockito.ArgumentMatchers.anyLong; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.BDDMockito.given; -import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.MediaType; import org.springframework.test.web.servlet.MockMvc; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; -import java.util.List; @WebMvcTest(CarController.class) @@ -90,8 +85,8 @@ public class CarControllerTest { given(carServiceMock.postCar(carRequestDto)).willReturn(carResponseDto); String response = mockMvc.perform(post("/car/") - .contentType(MediaType.APPLICATION_JSON) - .content(objectMapper.writeValueAsString(carRequestDto))) + .contentType(MediaType.APPLICATION_JSON) + .content(objectMapper.writeValueAsString(carRequestDto))) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); CarResponseDto carResponseDtoResponse = objectMapper.readValue(response, CarResponseDto.class); @@ -127,7 +122,8 @@ public class CarControllerTest { String response = mockMvc.perform(get("/car/all")) .andExpect(status().isOk()).andReturn().getResponse().getContentAsString(); - List<CarResponseDto> responseList = List.of(objectMapper.readValue(response, CarResponseDto[].class)); + List<CarResponseDto> responseList = + List.of(objectMapper.readValue(response, CarResponseDto[].class)); Assertions.assertEquals(responseList, List.of(carResponseDto2, carResponseDto3)); } } \ No newline at end of file diff --git a/car/src/test/java/cz/muni/pa165/car/rest/TestConfig.java b/car/src/test/java/cz/muni/pa165/car/rest/TestConfig.java new file mode 100644 index 0000000000000000000000000000000000000000..f34d68da5a5b02a2e9dfe5e79f5d64c305115443 --- /dev/null +++ b/car/src/test/java/cz/muni/pa165/car/rest/TestConfig.java @@ -0,0 +1,14 @@ +package cz.muni.pa165.car.rest; + +import cz.muni.pa165.car.restemplate.DbGetter; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; + +@Configuration +public class TestConfig { + + @Bean + DbGetter dbGetter() { + return new DbGetter(); + } +}