From b12c53d96002a1d164d52d667c843c6c34e98e53 Mon Sep 17 00:00:00 2001 From: dydwo0740 <80679257+dydwo0740@users.noreply.github.com> Date: Mon, 21 Aug 2023 16:03:54 +0900 Subject: [PATCH] =?UTF-8?q?Revert=20"=EC=98=A4=EB=A5=98"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit ab006b92fd5062e462173ee7348919a87436c240, reversing changes made to 47ed90ae030c6bac6646ec6bf0e8c4f5188f6a4d. --- .github/workflows/test.yml | 16 ++-- backend/build.gradle | 30 ++------ ...CarController.java => TrimController.java} | 24 +----- .../cartag/domain/car/CarTypeDto.java | 28 ------- .../cartag/repository/CarRepository.java | 25 +------ .../autoever2/cartag/service/CarService.java | 4 - .../cartag/CartagApplicationTests.java | 13 ++++ ...ollerTest.java => TrimControllerTest.java} | 34 +-------- .../autoever2/cartag/integration/CarTest.java | 73 ------------------- .../cartag/integration/DefaultTest.java | 6 +- .../cartag/integration/TrimTest.java | 39 ++++++++++ .../cartag/repository/CarRepositoryTest.java | 38 ---------- .../cartag/service/CarServiceTest.java | 32 +------- .../{application.yml => application-test.yml} | 0 .../test/resources/insert/insertCar-h2.sql | 16 ++-- 15 files changed, 90 insertions(+), 288 deletions(-) rename backend/src/main/java/autoever2/cartag/controller/{CarController.java => TrimController.java} (70%) delete mode 100644 backend/src/main/java/autoever2/cartag/domain/car/CarTypeDto.java create mode 100644 backend/src/test/java/autoever2/cartag/CartagApplicationTests.java rename backend/src/test/java/autoever2/cartag/controller/{CarControllerTest.java => TrimControllerTest.java} (75%) delete mode 100644 backend/src/test/java/autoever2/cartag/integration/CarTest.java create mode 100644 backend/src/test/java/autoever2/cartag/integration/TrimTest.java rename backend/src/test/resources/{application.yml => application-test.yml} (100%) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index b97a18f..6630f00 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -29,16 +29,20 @@ jobs: - name: Setup Gradle uses: gradle/gradle-build-action@v2 - - name: Test with Gradle + - name: Run Coverage working-directory: ${{ env.wd }} - run: ./gradlew test - + run: | + chmod +x gradlew + ./gradlew testCoverage + - name: Add coverage to PR id: jacoco - uses: madrapps/jacoco-report@v1.2 + uses: madrapps/jacoco-report@v1.6.1 with: paths: ${{ github.workspace }}/backend/build/reports/jacoco/test/jacocoTestReport.xml token: ${{ secrets.GITHUB_TOKEN }} title: ๐Ÿ“Š ํ…Œ์ŠคํŠธ ์ปค๋ฒ„๋ฆฌ์ง€ ๊ฒฐ๊ณผ - min-coverage-overall: 80 - min-coverage-changed-files: 80 + min-coverage-overall: 50 + min-coverage-changed-files: 50 + update-comment: true + continue-on-error: true diff --git a/backend/build.gradle b/backend/build.gradle index a4e0ea3..53788db 100644 --- a/backend/build.gradle +++ b/backend/build.gradle @@ -44,36 +44,22 @@ jacoco { toolVersion = '0.8.9' } -test { - useJUnitPlatform() - finalizedBy jacocoTestReport -} - jacocoTestReport { dependsOn test reports { xml.required = true + html.required = true + csv.required = false } - finalizedBy 'jacocoTestCoverageVerification' } -jacocoTestCoverageVerification { - violationRules { - rule { - limit { - counter = 'LINE' - value = 'COVEREDRATIO' - minimum = 0.8 - } - limit { - counter = 'METHOD' - value = 'COVEREDRATIO' - minimum = 0.8 - } - } - } -} +tasks.register('testCoverage', Test) { + group 'verification' + description 'Runs the tests with covarage (Create JaCoCo report)' + dependsOn test, jacocoTestReport + tasks['jacocoTestReport'].mustRunAfter(tasks['test']) +} jar { enabled = false } diff --git a/backend/src/main/java/autoever2/cartag/controller/CarController.java b/backend/src/main/java/autoever2/cartag/controller/TrimController.java similarity index 70% rename from backend/src/main/java/autoever2/cartag/controller/CarController.java rename to backend/src/main/java/autoever2/cartag/controller/TrimController.java index 63b9d81..e114f4a 100644 --- a/backend/src/main/java/autoever2/cartag/controller/CarController.java +++ b/backend/src/main/java/autoever2/cartag/controller/TrimController.java @@ -3,12 +3,8 @@ import autoever2.cartag.domain.car.BoughtCarDto; import autoever2.cartag.domain.car.CarDefaultDto; import autoever2.cartag.domain.car.CarDto; -<<<<<<< HEAD:backend/src/main/java/autoever2/cartag/controller/TrimController.java import autoever2.cartag.domain.share.QuoteIdList; import autoever2.cartag.domain.share.QuoteInfoDto; -======= -import autoever2.cartag.domain.car.CarTypeDto; ->>>>>>> 57c527d6b6e527b4e91eff53de6936fa62b8d654:backend/src/main/java/autoever2/cartag/controller/CarController.java import autoever2.cartag.service.CarService; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -18,34 +14,18 @@ import io.swagger.v3.oas.annotations.responses.ApiResponses; import io.swagger.v3.oas.annotations.tags.Tag; import lombok.RequiredArgsConstructor; -<<<<<<< HEAD:backend/src/main/java/autoever2/cartag/controller/TrimController.java import org.springframework.web.bind.annotation.*; -======= -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; ->>>>>>> 57c527d6b6e527b4e91eff53de6936fa62b8d654:backend/src/main/java/autoever2/cartag/controller/CarController.java import java.util.List; @RestController @RequestMapping("api/cars") @RequiredArgsConstructor -@Tag(name = "CarController", description = "ํŠธ๋ฆผ ๋ฐ˜ํ™˜ api") -public class CarController { +@Tag(name = "TrimController", description = "ํŠธ๋ฆผ ๋ฐ˜ํ™˜ api") +public class TrimController { private final CarService service; - @Operation(summary = "์ฐจ์ข… ๋ฆฌ์ŠคํŠธ ์กฐํšŒ", description = "์ฐจ์ข…๋ช… + ์ด๋ฏธ์ง€ ๋ฆฌ์ŠคํŠธ ์กฐํšŒ") - @ApiResponses(value = { - @ApiResponse(responseCode = "200", description = "์„ฑ๊ณต", content = @Content(schema = @Schema(implementation = CarTypeDto.class))) - }) - @GetMapping("/list") - public List getCarTypeList() { - return service.getAllCarTypes(); - } - @Operation(summary = "trim ์กฐํšŒ", description = "trim ์กฐํšŒ method") @ApiResponses(value = { @ApiResponse(responseCode = "200", description = "์กฐํšŒ ์„ฑ๊ณต", content = @Content(schema = @Schema(implementation = CarDto.class))), diff --git a/backend/src/main/java/autoever2/cartag/domain/car/CarTypeDto.java b/backend/src/main/java/autoever2/cartag/domain/car/CarTypeDto.java deleted file mode 100644 index 6f722a4..0000000 --- a/backend/src/main/java/autoever2/cartag/domain/car/CarTypeDto.java +++ /dev/null @@ -1,28 +0,0 @@ -package autoever2.cartag.domain.car; - -import io.swagger.v3.oas.annotations.media.Schema; -import lombok.Builder; -import lombok.Getter; -import lombok.NoArgsConstructor; -import lombok.Setter; - -@Getter -@Setter -@NoArgsConstructor -@Schema(description = "์ฐจ์ข… ID์™€ ์ด๋ฆ„, ์ด๋ฏธ์ง€๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋Š” dto") -public class CarTypeDto { - - @Schema(description = "์ฐจ์ข… ID, ์ฐจ๋Ÿ‰(ํŠธ๋ฆผ) ID์™€ ๋‹ค๋ฆ„", example = "1") - private int carTypeId; - @Schema(description = "์ฐจ์ข… ์ด๋ฏธ์ง€", example = "/cartype/palisade/palisade-thumbnail.png") - private String carTypeImage; - @Schema(description = "์ฐจ์ข… ๋ช…", example = "ํŒฐ๋ฆฌ์„ธ์ด๋“œ") - private String carTypeName; - - @Builder - public CarTypeDto(int carTypeId, String carTypeImage, String carTypeName) { - this.carTypeId = carTypeId; - this.carTypeImage = carTypeImage; - this.carTypeName = carTypeName; - } -} diff --git a/backend/src/main/java/autoever2/cartag/repository/CarRepository.java b/backend/src/main/java/autoever2/cartag/repository/CarRepository.java index 83317b9..ea9ece4 100644 --- a/backend/src/main/java/autoever2/cartag/repository/CarRepository.java +++ b/backend/src/main/java/autoever2/cartag/repository/CarRepository.java @@ -2,12 +2,8 @@ import autoever2.cartag.domain.car.CarInfoDto; import autoever2.cartag.domain.car.CarPriceDto; -<<<<<<< HEAD import autoever2.cartag.domain.car.TrimInfoDto; import org.springframework.dao.DataAccessException; -======= -import autoever2.cartag.domain.car.CarTypeDto; ->>>>>>> 57c527d6b6e527b4e91eff53de6936fa62b8d654 import org.springframework.dao.support.DataAccessUtils; import org.springframework.jdbc.core.BeanPropertyRowMapper; import org.springframework.jdbc.core.RowMapper; @@ -35,11 +31,11 @@ public List findCarByCarType(int carType) { SqlParameterSource param = new MapSqlParameterSource() .addValue("carType", carType); - return template.query(sql, param, carRowMapper()); + return template.query(sql, param, CarRowMapper()); } - private RowMapper carRowMapper() { + private RowMapper CarRowMapper() { return BeanPropertyRowMapper.newInstance(CarInfoDto.class); } @@ -74,26 +70,11 @@ public List findCarPriceAndCount() { "on Car.car_id = SalesHistory.car_id inner join SubOptionData " + "on SubOptionData.car_id = Car.car_id group by SalesHistory.history_id"; - return template.query(sql, carPriceRowMapper()); + return template.query(sql, CarPriceRowMapper()); } -<<<<<<< HEAD private RowMapper CarPriceRowMapper() { -======= - public List findAllCarType() { - String sql = "select ct.car_type_id, ct.car_type_name, ct.car_type_image " + - "from CarType ct "; - - return template.query(sql, carTypeDtoRowMapper()); - } - - private RowMapper carTypeDtoRowMapper() { - return BeanPropertyRowMapper.newInstance(CarTypeDto.class); - } - - private RowMapper carPriceRowMapper() { ->>>>>>> 57c527d6b6e527b4e91eff53de6936fa62b8d654 return (rs, rowNum) -> CarPriceDto .builder() .optionList(rs.getString("SalesHistory.sold_options_id")) diff --git a/backend/src/main/java/autoever2/cartag/service/CarService.java b/backend/src/main/java/autoever2/cartag/service/CarService.java index 9584a26..1d2315e 100644 --- a/backend/src/main/java/autoever2/cartag/service/CarService.java +++ b/backend/src/main/java/autoever2/cartag/service/CarService.java @@ -33,10 +33,6 @@ public class CarService { private final ModelRepository modelRepository; - public List getAllCarTypes() { - return carRepository.findAllCarType(); - } - // TODO Optional๋กœ ๊ฐ์‹ธ์ง„ ๊ฐ’์ด empty์ผ ๊ฒฝ์šฐ ์–ด๋–ค ์˜ˆ์™ธ ๋ฐœ์ƒ์‹œํ‚ฌ์ง€ ์ •ํ•˜๊ธฐ public List findCarByCarType(int carType) { List carInfos = carRepository.findCarByCarType(carType); diff --git a/backend/src/test/java/autoever2/cartag/CartagApplicationTests.java b/backend/src/test/java/autoever2/cartag/CartagApplicationTests.java new file mode 100644 index 0000000..6802e3d --- /dev/null +++ b/backend/src/test/java/autoever2/cartag/CartagApplicationTests.java @@ -0,0 +1,13 @@ +package autoever2.cartag; + +import org.junit.jupiter.api.Test; +import org.springframework.boot.test.context.SpringBootTest; + +@SpringBootTest +class CartagApplicationTests { + + @Test + void contextLoads() { + } + +} diff --git a/backend/src/test/java/autoever2/cartag/controller/CarControllerTest.java b/backend/src/test/java/autoever2/cartag/controller/TrimControllerTest.java similarity index 75% rename from backend/src/test/java/autoever2/cartag/controller/CarControllerTest.java rename to backend/src/test/java/autoever2/cartag/controller/TrimControllerTest.java index 2b55216..073c71d 100644 --- a/backend/src/test/java/autoever2/cartag/controller/CarControllerTest.java +++ b/backend/src/test/java/autoever2/cartag/controller/TrimControllerTest.java @@ -1,7 +1,6 @@ package autoever2.cartag.controller; import autoever2.cartag.domain.car.CarDto; -import autoever2.cartag.domain.car.CarTypeDto; import autoever2.cartag.domain.car.TrimDefaultOptionDto; import autoever2.cartag.service.CarService; import org.junit.jupiter.api.BeforeEach; @@ -21,8 +20,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(CarController.class) -class CarControllerTest { +@WebMvcTest(TrimController.class) +class TrimControllerTest { @Autowired MockMvc mockMvc; @@ -120,33 +119,4 @@ void getTrimList() throws Exception { .andExpect(jsonPath("$[3].wheelImage").isEmpty()); } - - @Test - @DisplayName("์ฐจ์ข… ๋ฆฌ์ŠคํŠธ ํ˜ธ์ถœ API") - void getCarTypeList() throws Exception { - List carTypeList = new ArrayList<>(); - carTypeList.add(CarTypeDto.builder() - .carTypeId(1) - .carTypeName("ํŽ ๋ฆฌ์„ธ์ด๋“œ") - .carTypeImage("image_1") - .build()); - carTypeList.add(CarTypeDto.builder() - .carTypeId(2) - .carTypeImage("/cartype/santafe.png") - .carTypeName("์‹ผํƒ€ํŽ˜") - .build()); - carTypeList.add(CarTypeDto.builder() - .carTypeId(3) - .carTypeImage("/cartype/the-all-new-kona-hybrid.png") - .carTypeName("๋”” ์˜ฌ ๋‰ด ์ฝ”๋‚˜ Hybrid") - .build()); - given(service.getAllCarTypes()).willReturn(carTypeList); - - ResultActions resultActions = mockMvc.perform(MockMvcRequestBuilders.get("/api/cars/list")); - - resultActions.andExpect(status().isOk()) - .andExpect(jsonPath("$[0].carTypeId").value(1)) - .andExpect(jsonPath("$[1].carTypeImage").value("/cartype/santafe.png")) - .andExpect(jsonPath("$[2].carTypeName").value("๋”” ์˜ฌ ๋‰ด ์ฝ”๋‚˜ Hybrid")); - } } \ No newline at end of file diff --git a/backend/src/test/java/autoever2/cartag/integration/CarTest.java b/backend/src/test/java/autoever2/cartag/integration/CarTest.java deleted file mode 100644 index 83a441a..0000000 --- a/backend/src/test/java/autoever2/cartag/integration/CarTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package autoever2.cartag.integration; - -import autoever2.cartag.controller.CarController; -import autoever2.cartag.domain.car.CarDefaultDto; -import autoever2.cartag.domain.car.CarDto; -import autoever2.cartag.domain.car.CarTypeDto; -import autoever2.cartag.exception.EmptyDataException; -import io.swagger.v3.oas.annotations.Operation; -import io.swagger.v3.oas.annotations.Parameter; -import io.swagger.v3.oas.annotations.media.Content; -import io.swagger.v3.oas.annotations.media.Schema; -import io.swagger.v3.oas.annotations.responses.ApiResponse; -import io.swagger.v3.oas.annotations.responses.ApiResponses; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.test.context.jdbc.Sql; -import org.springframework.transaction.annotation.Transactional; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; - -import java.util.ArrayList; -import java.util.List; - -import static org.assertj.core.api.AssertionsForClassTypes.assertThat; -import static org.junit.jupiter.api.Assertions.*; - -@SpringBootTest -@Transactional -@ActiveProfiles("test") -@Sql(scripts = {"classpath:/insert/insertCar-h2.sql"}) -public class CarTest { - @Autowired - CarController controller; - - @Test - @DisplayName("/api/cars/types?cartype=1 ํ†ตํ•ฉํ…Œ์ŠคํŠธ") - void testCarTypes() { - List cars = controller.carTrimInfo(1); - assertEquals("Le Blanc", cars.get(0).getTrim()); - assertEquals(40000000, cars.get(1).getCarDefaultPrice()); - assertEquals("image_1", cars.get(2).getOuterImage()); - assertEquals("image_2", cars.get(3).getInnerImage()); - assertThrows(EmptyDataException.class, () -> { - controller.carTrimInfo(100); - }); - } - - @Test - @DisplayName("/api/cars/list ํ…Œ์ŠคํŠธ") - void testCarTypeList() { - List carTypeList = new ArrayList<>(); - carTypeList.add(CarTypeDto.builder() - .carTypeId(1) - .carTypeName("ํŽ ๋ฆฌ์„ธ์ด๋“œ") - .carTypeImage("image_1") - .build()); - carTypeList.add(CarTypeDto.builder() - .carTypeId(2) - .carTypeImage("/cartype/santafe.png") - .carTypeName("์‹ผํƒ€ํŽ˜") - .build()); - carTypeList.add(CarTypeDto.builder() - .carTypeId(3) - .carTypeImage("/cartype/the-all-new-kona-hybrid.png") - .carTypeName("๋”” ์˜ฌ ๋‰ด ์ฝ”๋‚˜ Hybrid") - .build()); - - assertThat(controller.getCarTypeList()).usingRecursiveComparison().isEqualTo(carTypeList); - } -} diff --git a/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java b/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java index c8bf800..243c8c8 100644 --- a/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java +++ b/backend/src/test/java/autoever2/cartag/integration/DefaultTest.java @@ -1,6 +1,6 @@ package autoever2.cartag.integration; -import autoever2.cartag.controller.CarController; +import autoever2.cartag.controller.TrimController; import autoever2.cartag.domain.car.CarDefaultDto; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; @@ -19,10 +19,10 @@ public class DefaultTest { @Autowired - CarController controller; + TrimController controller; @Test - @DisplayName("/api/cars/infos/defaults?carid=1 ํ…Œ์ŠคํŠธ") + @DisplayName("์ฐจ๋Ÿ‰ ๊ธฐ๋ณธ ์ •๋ณด๋“ค์„ ๋ฐ˜ํ™˜") void defaultCarInfos(){ CarDefaultDto carDefaultDto = controller.carDefaultDto(1); assertEquals("๋””์ ค2.2", carDefaultDto.getPowerTrainName()); diff --git a/backend/src/test/java/autoever2/cartag/integration/TrimTest.java b/backend/src/test/java/autoever2/cartag/integration/TrimTest.java new file mode 100644 index 0000000..92ce53c --- /dev/null +++ b/backend/src/test/java/autoever2/cartag/integration/TrimTest.java @@ -0,0 +1,39 @@ +package autoever2.cartag.integration; + +import autoever2.cartag.controller.TrimController; +import autoever2.cartag.domain.car.CarDto; +import autoever2.cartag.exception.EmptyDataException; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.jdbc.Sql; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; + +import static org.junit.jupiter.api.Assertions.*; + +@SpringBootTest +@Transactional +@ActiveProfiles("test") +@Sql(scripts = {"classpath:/insert/insertCar-h2.sql"}) +public class TrimTest { + @Autowired + TrimController controller; + + @Test + @DisplayName("cartype์— ์ข…์†์ ์ธ ์ฐจ๋Ÿ‰ ๋ฆฌ์ŠคํŠธ ๋ฐ˜ํ™˜ api๋ฅผ ํ…Œ์ŠคํŠธ ํ•ฉ๋‹ˆ๋‹ค.") + void testCarController() { + List cars = controller.carTrimInfo(1); + assertEquals("Le Blanc", cars.get(0).getTrim()); + assertEquals(40000000, cars.get(1).getCarDefaultPrice()); + assertEquals("image_1", cars.get(2).getOuterImage()); + assertEquals("image_2", cars.get(3).getInnerImage()); + assertThrows(EmptyDataException.class, () -> { + controller.carTrimInfo(2); + }); + } +} diff --git a/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java b/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java index 18dcca1..39aa2e4 100644 --- a/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java +++ b/backend/src/test/java/autoever2/cartag/repository/CarRepositoryTest.java @@ -1,20 +1,14 @@ package autoever2.cartag.repository; import autoever2.cartag.domain.car.CarInfoDto; -import autoever2.cartag.domain.car.CarTypeDto; -import org.assertj.core.api.SoftAssertions; -import org.assertj.core.api.junit.jupiter.InjectSoftAssertions; -import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension; import org.junit.jupiter.api.DisplayName; 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.autoconfigure.jdbc.JdbcTest; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.jdbc.Sql; import javax.sql.DataSource; -import java.util.ArrayList; import java.util.List; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -22,12 +16,8 @@ @JdbcTest @ActiveProfiles("test") @Sql(scripts = {"classpath:/insert/insertCar-h2.sql"}) -@ExtendWith(SoftAssertionsExtension.class) class CarRepositoryTest { - @InjectSoftAssertions - private SoftAssertions softAssertions; - private final CarRepository carRepository; @Autowired @@ -56,32 +46,4 @@ void findCarBoughtCountByCarId() { assertEquals(234L, boughtCount); } - - @Test - @DisplayName("์ฐจ์ข… ๋ฆฌ์ŠคํŠธ ๋ฐ˜ํ™˜") - void findAllCarTypeList() { - //given - List expected = new ArrayList<>(); - expected.add(CarTypeDto.builder() - .carTypeId(1) - .carTypeName("ํŽ ๋ฆฌ์„ธ์ด๋“œ") - .carTypeImage("image_1") - .build()); - expected.add(CarTypeDto.builder() - .carTypeId(2) - .carTypeImage("/cartype/santafe.png") - .carTypeName("์‹ผํƒ€ํŽ˜") - .build()); - expected.add(CarTypeDto.builder() - .carTypeId(3) - .carTypeImage("/cartype/the-all-new-kona-hybrid.png") - .carTypeName("๋”” ์˜ฌ ๋‰ด ์ฝ”๋‚˜ Hybrid") - .build()); - - //when - List result = carRepository.findAllCarType(); - - //then - softAssertions.assertThat(result).usingRecursiveComparison().isEqualTo(expected); - } } \ No newline at end of file diff --git a/backend/src/test/java/autoever2/cartag/service/CarServiceTest.java b/backend/src/test/java/autoever2/cartag/service/CarServiceTest.java index a070cb4..e52fa55 100644 --- a/backend/src/test/java/autoever2/cartag/service/CarServiceTest.java +++ b/backend/src/test/java/autoever2/cartag/service/CarServiceTest.java @@ -2,7 +2,6 @@ import autoever2.cartag.domain.car.CarDto; import autoever2.cartag.domain.car.CarInfoDto; -import autoever2.cartag.domain.car.CarTypeDto; import autoever2.cartag.domain.car.TrimDefaultOptionDto; import autoever2.cartag.exception.EmptyDataException; import autoever2.cartag.exception.ErrorCode; @@ -27,7 +26,7 @@ class CarServiceTest { @InjectMocks - private CarService carService; + private CarService service; @Mock private CarRepository carRepository; @@ -122,11 +121,11 @@ void getCarType() { when(optionRepository.findDefaultOptionByCarId(carId)).thenReturn(trimDefaultOptionDtoList); when(carRepository.findCarByCarType(2)).thenThrow(new EmptyDataException(ErrorCode.RESOURCE_NOT_FOUND)); - List carByCarType = carService.findCarByCarType(carType); + List carByCarType = service.findCarByCarType(carType); assertEquals(carByCarType.size(), 4); assertEquals(carByCarType.get(0).getOptions().size(), 3); - assertThatThrownBy(() -> carService.findCarByCarType(2)).isInstanceOf(EmptyDataException.class); + assertThatThrownBy(() -> service.findCarByCarType(2)).isInstanceOf(EmptyDataException.class); } @Test @@ -135,29 +134,4 @@ void carDefaultInfo(){ } - - @Test - @DisplayName("DB์—์„œ ๋ฐ›์•„์˜จ ์ฐจ์ข…์„ Controller๋กœ ์ „๋‹ฌ") - void carTypeList() { - List carTypeList = new ArrayList<>(); - carTypeList.add(CarTypeDto.builder() - .carTypeId(1) - .carTypeName("ํŽ ๋ฆฌ์„ธ์ด๋“œ") - .carTypeImage("image_1") - .build()); - carTypeList.add(CarTypeDto.builder() - .carTypeId(2) - .carTypeImage("/cartype/santafe.png") - .carTypeName("์‹ผํƒ€ํŽ˜") - .build()); - carTypeList.add(CarTypeDto.builder() - .carTypeId(3) - .carTypeImage("/cartype/the-all-new-kona-hybrid.png") - .carTypeName("๋”” ์˜ฌ ๋‰ด ์ฝ”๋‚˜ Hybrid") - .build()); - - when(carRepository.findAllCarType()).thenReturn(carTypeList); - - assertEquals(carTypeList, carService.getAllCarTypes()); - } } \ No newline at end of file diff --git a/backend/src/test/resources/application.yml b/backend/src/test/resources/application-test.yml similarity index 100% rename from backend/src/test/resources/application.yml rename to backend/src/test/resources/application-test.yml diff --git a/backend/src/test/resources/insert/insertCar-h2.sql b/backend/src/test/resources/insert/insertCar-h2.sql index a077262..1d7639c 100644 --- a/backend/src/test/resources/insert/insertCar-h2.sql +++ b/backend/src/test/resources/insert/insertCar-h2.sql @@ -1,10 +1,8 @@ -INSERT INTO CarType (car_type_id, car_type_image, car_type_name) VALUES (1, 'image_1', 'ํŽ ๋ฆฌ์„ธ์ด๋“œ'); -INSERT INTO CarType (car_type_id, car_type_image, car_type_name) VALUES (2, '/cartype/santafe.png', '์‹ผํƒ€ํŽ˜'); -INSERT INTO CarType (car_type_id, car_type_image, car_type_name) VALUES (3, '/cartype/the-all-new-kona-hybrid.png', '๋”” ์˜ฌ ๋‰ด ์ฝ”๋‚˜ Hybrid'); +insert into CarType values(1, 'image_1', 'ํŽ ๋ฆฌ์„ธ์ด๋“œ'); + +insert into Car values(1, 1, 'Le Blanc', 40000000, 'image_1', 'image_2', 'image_3', 234, 'Good'); +insert into Car values(2, 1, 'Exclusive', 40000000, 'image_1', 'image_2', 'image_3', 24, 'Good'); +insert into Car values(3, 1, 'Calligraphy', 40000000, 'image_1', 'image_2', 'image_3', 34, 'Good'); +insert into Car values(4, 1, 'Prestige', 40000000, 'image_1', 'image_2', 'image_3', 23499, 'Good'); + -INSERT INTO Car (car_id, car_type_id, trim, car_default_price, outer_image, inner_image, wheel_image, bought_count, car_description) VALUES (1, 1, 'Le Blanc', 40000000, 'image_1', 'image_2', 'image_3', 234, 'Good'); -INSERT INTO Car (car_id, car_type_id, trim, car_default_price, outer_image, inner_image, wheel_image, bought_count, car_description) VALUES (2, 1, 'Exclusive', 40000000, 'image_1', 'image_2', 'image_3', 24, 'Good'); -INSERT INTO Car (car_id, car_type_id, trim, car_default_price, outer_image, inner_image, wheel_image, bought_count, car_description) VALUES (3, 1, 'Prestige', 40000000, 'image_1', 'image_2', 'image_3', 34, 'Good'); -INSERT INTO Car (car_id, car_type_id, trim, car_default_price, outer_image, inner_image, wheel_image, bought_count, car_description) VALUES (4, 1, 'Calligraphy', 40000000, 'image_1', 'image_2', 'image_3', 23499, 'Good'); -INSERT INTO Car (car_id, car_type_id, trim, car_default_price, outer_image, inner_image, wheel_image, bought_count, car_description) VALUES (5, 2, 'Exclusive', 35460000, '/cartype/santafe.png', '/cartype/santafe.png', '', 150000, '์‚ฐํƒ€ํŽ˜'); -INSERT INTO Car (car_id, car_type_id, trim, car_default_price, outer_image, inner_image, wheel_image, bought_count, car_description) VALUES (6, 3, 'Inspiration', 36380000, '/cartype/the-all-new-kona-hybrid.png', '/cartype/the-all-new-kona-hybrid.png', '', 150000, '๋”” ์˜ฌ ๋‰ด ์ฝ”๋‚˜ Hybrid์ž…๋‹ˆ๋‹ค.');