Skip to content

Commit

Permalink
오류
Browse files Browse the repository at this point in the history
  • Loading branch information
dydwo0740 committed Aug 21, 2023
2 parents 47ed90a + 57c527d commit ab006b9
Show file tree
Hide file tree
Showing 15 changed files with 288 additions and 90 deletions.
16 changes: 6 additions & 10 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,16 @@ jobs:
- name: Setup Gradle
uses: gradle/gradle-build-action@v2

- name: Run Coverage
- name: Test with Gradle
working-directory: ${{ env.wd }}
run: |
chmod +x gradlew
./gradlew testCoverage
run: ./gradlew test

- name: Add coverage to PR
id: jacoco
uses: madrapps/jacoco-report@v1.6.1
uses: madrapps/jacoco-report@v1.2
with:
paths: ${{ github.workspace }}/backend/build/reports/jacoco/test/jacocoTestReport.xml
token: ${{ secrets.GITHUB_TOKEN }}
title: 📊 테스트 커버리지 결과
min-coverage-overall: 50
min-coverage-changed-files: 50
update-comment: true
continue-on-error: true
min-coverage-overall: 80
min-coverage-changed-files: 80
30 changes: 22 additions & 8 deletions backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -44,22 +44,36 @@ jacoco {
toolVersion = '0.8.9'
}

test {
useJUnitPlatform()
finalizedBy jacocoTestReport
}

jacocoTestReport {
dependsOn test
reports {
xml.required = true
html.required = true
csv.required = false
}
finalizedBy 'jacocoTestCoverageVerification'
}

tasks.register('testCoverage', Test) {
group 'verification'
description 'Runs the tests with covarage (Create JaCoCo report)'

dependsOn test, jacocoTestReport
tasks['jacocoTestReport'].mustRunAfter(tasks['test'])
jacocoTestCoverageVerification {
violationRules {
rule {
limit {
counter = 'LINE'
value = 'COVEREDRATIO'
minimum = 0.8
}
limit {
counter = 'METHOD'
value = 'COVEREDRATIO'
minimum = 0.8
}
}
}
}

jar {
enabled = false
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
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;
Expand All @@ -14,18 +18,34 @@
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 = "TrimController", description = "트림 반환 api")
public class TrimController {
@Tag(name = "CarController", description = "트림 반환 api")
public class CarController {

private final CarService service;

@Operation(summary = "차종 리스트 조회", description = "차종명 + 이미지 리스트 조회")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "성공", content = @Content(schema = @Schema(implementation = CarTypeDto.class)))
})
@GetMapping("/list")
public List<CarTypeDto> getCarTypeList() {
return service.getAllCarTypes();
}

@Operation(summary = "trim 조회", description = "trim 조회 method")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = "조회 성공", content = @Content(schema = @Schema(implementation = CarDto.class))),
Expand Down
28 changes: 28 additions & 0 deletions backend/src/main/java/autoever2/cartag/domain/car/CarTypeDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

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;
Expand Down Expand Up @@ -31,11 +35,11 @@ public List<CarInfoDto> findCarByCarType(int carType) {

SqlParameterSource param = new MapSqlParameterSource()
.addValue("carType", carType);
return template.query(sql, param, CarRowMapper());
return template.query(sql, param, carRowMapper());

}

private RowMapper<CarInfoDto> CarRowMapper() {
private RowMapper<CarInfoDto> carRowMapper() {
return BeanPropertyRowMapper.newInstance(CarInfoDto.class);
}

Expand Down Expand Up @@ -70,11 +74,26 @@ public List<CarPriceDto> 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<CarPriceDto> CarPriceRowMapper() {
=======
public List<CarTypeDto> 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<CarTypeDto> carTypeDtoRowMapper() {
return BeanPropertyRowMapper.newInstance(CarTypeDto.class);
}

private RowMapper<CarPriceDto> carPriceRowMapper() {
>>>>>>> 57c527d6b6e527b4e91eff53de6936fa62b8d654
return (rs, rowNum) -> CarPriceDto
.builder()
.optionList(rs.getString("SalesHistory.sold_options_id"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ public class CarService {

private final ModelRepository modelRepository;

public List<CarTypeDto> getAllCarTypes() {
return carRepository.findAllCarType();
}

// TODO Optional로 감싸진 값이 empty일 경우 어떤 예외 발생시킬지 정하기
public List<CarDto> findCarByCarType(int carType) {
List<CarInfoDto> carInfos = carRepository.findCarByCarType(carType);
Expand Down
13 changes: 0 additions & 13 deletions backend/src/test/java/autoever2/cartag/CartagApplicationTests.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
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;
Expand All @@ -20,8 +21,8 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@WebMvcTest(TrimController.class)
class TrimControllerTest {
@WebMvcTest(CarController.class)
class CarControllerTest {
@Autowired
MockMvc mockMvc;

Expand Down Expand Up @@ -119,4 +120,33 @@ void getTrimList() throws Exception {
.andExpect(jsonPath("$[3].wheelImage").isEmpty());

}

@Test
@DisplayName("차종 리스트 호출 API")
void getCarTypeList() throws Exception {
List<CarTypeDto> 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"));
}
}
73 changes: 73 additions & 0 deletions backend/src/test/java/autoever2/cartag/integration/CarTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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<CarDto> 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<CarTypeDto> 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);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package autoever2.cartag.integration;

import autoever2.cartag.controller.TrimController;
import autoever2.cartag.controller.CarController;
import autoever2.cartag.domain.car.CarDefaultDto;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -19,10 +19,10 @@
public class DefaultTest {

@Autowired
TrimController controller;
CarController controller;

@Test
@DisplayName("차량 기본 정보들을 반환")
@DisplayName("/api/cars/infos/defaults?carid=1 테스트")
void defaultCarInfos(){
CarDefaultDto carDefaultDto = controller.carDefaultDto(1);
assertEquals("디젤2.2", carDefaultDto.getPowerTrainName());
Expand Down
Loading

0 comments on commit ab006b9

Please sign in to comment.