Skip to content

Commit

Permalink
Merge pull request #157 from gunsight1/hotfix_repair_product_testcode
Browse files Browse the repository at this point in the history
Hotfix :: 제품 도메인 테스트코드 긴급 수정
  • Loading branch information
gunsight1 authored Feb 19, 2024
2 parents 495d4de + 45ff27a commit 4da47b4
Show file tree
Hide file tree
Showing 3 changed files with 127 additions and 71 deletions.
9 changes: 3 additions & 6 deletions module-api/src/docs/asciidoc/product-api.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,18 @@
=== <제품 목록 조회>

===== HTTP Request

include::{snippets}/products-list/get-products-list/http-request.adoc[]
include::{snippets}/products/get-products/http-request.adoc[]

==== Response
include::{snippets}/products-list/get-products-list/response-fields.adoc[]
include::{snippets}/products/get-products/response-fields.adoc[]

===== HTTP Response 예시
include::{snippets}/products-list/get-products-list/http-response.adoc[]
include::{snippets}/products/get-products/http-response.adoc[]


=== <제품 아이디로 제품 목록 조회>

===== HTTP Request

include::{snippets}/product-id/get-product-id/http-request.adoc[]

==== Response
Expand All @@ -31,7 +29,6 @@ include::{snippets}/product-id/get-product-id//http-response.adoc[]
=== <제품 키워드로 제품 목록 조회>

===== HTTP Request

include::{snippets}/products-search/get-products-by-search/http-request.adoc[]

==== Response
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package com.kernel360.product.dto;

import com.kernel360.product.entity.Product;
import jakarta.persistence.Column;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import java.time.LocalDate;

Expand Down Expand Up @@ -35,7 +39,12 @@ public record ProductDetailDto(
String manufactureType,
String manufactureMethod,
String manufactureNation,
String violationInfo
String violationInfo,
LocalDate createdAt,
String createdBy,
LocalDate modifiedAt,
String modifiedBy
//TODO 브랜드 엔티티
) {

public static ProductDetailDto of(
Expand Down Expand Up @@ -66,7 +75,11 @@ public static ProductDetailDto of(
String manufactureType,
String manufactureMethod,
String manufactureNation,
String violationInfo
String violationInfo,
LocalDate createdAt,
String createdBy,
LocalDate modifiedAt,
String modifiedBy
) {
return new ProductDetailDto(
productNo,
Expand Down Expand Up @@ -96,7 +109,11 @@ public static ProductDetailDto of(
manufactureType,
manufactureMethod,
manufactureNation,
violationInfo
violationInfo,
createdAt,
createdBy,
modifiedAt,
modifiedBy
);
}

Expand Down Expand Up @@ -129,7 +146,11 @@ public static ProductDetailDto from(Product entity) {
entity.getManufactureType(),
entity.getManufactureMethod(),
entity.getManufactureNation(),
entity.getViolationInfo()
entity.getViolationInfo(),
entity.getCreatedAt(),
entity.getCreatedBy(),
entity.getModifiedAt(),
entity.getModifiedBy()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import com.navercorp.fixturemonkey.FixtureMonkey;
import com.navercorp.fixturemonkey.api.introspector.*;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.RepeatedTest;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureWebMvc;
import org.springframework.data.domain.Page;
Expand Down Expand Up @@ -53,6 +54,7 @@ class ProductControllerTest extends ControllerTest {

@Test
void 제품목록요청_왔을때_200응답과_리스폰스가_잘반환되는지() throws Exception {
//todo 브랜드
// given
List<ProductDto> expectedDtos = fixtureMonkey.giveMeBuilder(Product.class)
.setNotNull("productNo")
Expand All @@ -62,7 +64,6 @@ class ProductControllerTest extends ControllerTest {
.setNotNull("reportNumber")
.setNotNull("safetyStatus")
.setNotNull("viewCount")
.setNotNull("brand")
.setNotNull("upperItem")
.setNotNull("createdAt")
.setNotNull("createdBy")
Expand All @@ -79,20 +80,19 @@ class ProductControllerTest extends ControllerTest {
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.value", hasSize(5)))
.andDo(document("products-list/get-products-list",
.andDo(document("products/get-products",
responseFields(
fieldWithPath("status").description("상태 코드"),
fieldWithPath("message").description("응답 메세지"),
fieldWithPath("code").description("비지니스 코드"),
fieldWithPath("value").description("제품 리스트"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("code").description("비즈니스 코드"),
subsectionWithPath("value").description("제품 목록"),
fieldWithPath("value[].productNo").description("제품번호").optional(),
fieldWithPath("value[].productName").description("제품명").optional(),
fieldWithPath("value[].barcode").description("바코드").optional(),
fieldWithPath("value[].imageSource").description("이미지 소스").optional(),
fieldWithPath("value[].reportNumber").description("보고 번호").optional(),
fieldWithPath("value[].safetyStatus").description("안전 상태").optional(),
fieldWithPath("value[].viewCount").description("조회수").optional(),
fieldWithPath("value[].brand").description("브랜드").optional(),
fieldWithPath("value[].upperItem").description("상위 분류").optional(),
fieldWithPath("value[].createdAt").description("생성 날짜").optional(),
fieldWithPath("value[].createdBy").description("생성자").optional(),
Expand All @@ -105,81 +105,119 @@ class ProductControllerTest extends ControllerTest {


@Test
void 제품아이디로_제품조회요청이왔을때_200응답과_리스폰스가_잘반환되는지() throws Exception {
void 제품고유번호로_제품상세조회요청이왔을때_200응답과_리스폰스가_잘반환되는지() throws Exception {
//TODO 브랜드, 제조국, grade, reviewCnt
// given
Product mockProduct = fixtureMonkey.giveMeBuilder(Product.class)
.set("productNo", 1L) // Assuming you want to explicitly set some values
.setNotNull("productName")
.setNotNull("companyName")
.setNotNull("productType")
.setNotNull("upperItem")
.setNotNull("manufactureType")
.setNotNull("manufactureMethod")
.setNotNull("weight")
.setNotNull("reportNumber")
.setNotNull("mainSubstance")
.setNotNull("brand")
.set("grade", 3.5)
.set("reviewCnt", 10L)
.setNotNull("viewCount")
.setNotNull("createdAt")
.setNotNull("createdBy")
.setNotNull("modifiedAt")
.setNotNull("modifiedBy")
.setNotNull("productName")
.setNotNull("barcode")
.setNotNull("imageSource")
.setNotNull("reportNumber")
.setNotNull("safetyStatus")
.setNotNull("viewCount")
.setNotNull("companyName")
.setNotNull("productType")
.setNotNull("issuedDate")
.setNotNull("safetyInspectionStandard")
.setNotNull("upperItem")
.setNotNull("item")
.setNotNull("propose")
.setNotNull("weight")
.setNotNull("usage")
.setNotNull("usagePrecaution")
.setNotNull("firstAid")
.setNotNull("mainSubstance")
.setNotNull("allergicSubstance")
.setNotNull("otherSubstance")
.setNotNull("preservative")
.setNotNull("surfactant")
.setNotNull("fluorescentWhitening")
.setNotNull("manufactureType")
.setNotNull("manufactureMethod")
.setNotNull("violationInfo")
.setNotNull("createdAt")
.setNotNull("createdBy")
.setNotNull("modifiedAt")
.setNotNull("modifiedBy")
.sample();

ProductDetailDto productDetailDto = ProductDetailDto.from(mockProduct);

when(productService.getProductById(1L)).thenReturn(productDetailDto);

// when & then
mockMvc.perform(get("/product/{id}", 1L))
mockMvc.perform(get("/product/{productNo}", 1L))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.value.productNo", notNullValue()))
.andExpect(jsonPath("$.value.productName", notNullValue()))
.andExpect(jsonPath("$.value.companyName", notNullValue()))
.andExpect(jsonPath("$.value.productType", notNullValue()))
.andExpect(jsonPath("$.value.upperItem", notNullValue()))
.andExpect(jsonPath("$.value.manufactureType", notNullValue()))
.andExpect(jsonPath("$.value.manufactureMethod", notNullValue()))
.andExpect(jsonPath("$.value.weight", notNullValue()))
.andExpect(jsonPath("$.value.reportNumber", notNullValue()))
.andExpect(jsonPath("$.value.mainSubstance", notNullValue()))
.andExpect(jsonPath("$.value.brand", notNullValue()))
.andExpect(jsonPath("$.value.grade", notNullValue()))
.andExpect(jsonPath("$.value.reviewCnt", notNullValue()))
.andExpect(jsonPath("$.value.viewCount", notNullValue()))
.andExpect(jsonPath("$.value.createdAt", notNullValue()))
.andExpect(jsonPath("$.value.createdBy", notNullValue()))
.andExpect(jsonPath("$.value.modifiedAt", notNullValue()))
.andExpect(jsonPath("$.value.modifiedBy", notNullValue()))
.andExpect(jsonPath("$.value.productName", notNullValue()))
.andExpect(jsonPath("$.value.barcode", notNullValue()))
.andExpect(jsonPath("$.value.imageSource", notNullValue()))
.andExpect(jsonPath("$.value.reportNumber", notNullValue()))
.andExpect(jsonPath("$.value.safetyStatus", notNullValue()))
.andExpect(jsonPath("$.value.viewCount", notNullValue()))
.andExpect(jsonPath("$.value.companyName", notNullValue()))
.andExpect(jsonPath("$.value.productType", notNullValue()))
.andExpect(jsonPath("$.value.issuedDate", notNullValue()))
.andExpect(jsonPath("$.value.safetyInspectionStandard", notNullValue()))
.andExpect(jsonPath("$.value.upperItem", notNullValue()))
.andExpect(jsonPath("$.value.item", notNullValue()))
.andExpect(jsonPath("$.value.propose", notNullValue()))
.andExpect(jsonPath("$.value.weight", notNullValue()))
.andExpect(jsonPath("$.value.usage", notNullValue()))
.andExpect(jsonPath("$.value.usagePrecaution", notNullValue()))
.andExpect(jsonPath("$.value.firstAid", notNullValue()))
.andExpect(jsonPath("$.value.mainSubstance", notNullValue()))
.andExpect(jsonPath("$.value.allergicSubstance", notNullValue()))
.andExpect(jsonPath("$.value.otherSubstance", notNullValue()))
.andExpect(jsonPath("$.value.preservative", notNullValue()))
.andExpect(jsonPath("$.value.surfactant", notNullValue()))
.andExpect(jsonPath("$.value.fluorescentWhitening", notNullValue()))
.andExpect(jsonPath("$.value.manufactureType", notNullValue()))
.andExpect(jsonPath("$.value.manufactureMethod", notNullValue()))
.andExpect(jsonPath("$.value.violationInfo", notNullValue()))
.andExpect(jsonPath("$.value.createdAt", notNullValue()))
.andExpect(jsonPath("$.value.createdBy", notNullValue()))
.andExpect(jsonPath("$.value.modifiedAt", notNullValue()))
.andExpect(jsonPath("$.value.modifiedBy", notNullValue()))
.andDo(document("product-id/get-product-id",
pathParameters(
parameterWithName("id").description("제품 ID")
parameterWithName("productNo").description("제품번호")
),
responseFields(
fieldWithPath("status").description("상태 코드"),
fieldWithPath("message").description("응답 메세지"),
fieldWithPath("code").description("비지니스 코드"),
fieldWithPath("value").description("제품 상세 정보"),
fieldWithPath("message").description("응답 메시지"),
fieldWithPath("code").description("비즈니스 코드"),
subsectionWithPath("value").description("제품 목록"),
fieldWithPath("value.productNo").description("제품번호"),
fieldWithPath("value.productName").description("제품명"),
fieldWithPath("value.barcode").description("바코드"),
fieldWithPath("value.imageSource").description("이미지"),
fieldWithPath("value.reportNumber").description("신고번호"),
fieldWithPath("value.safetyStatus").description("위해우려등급"),
fieldWithPath("value.viewCount").description("조회수"),
fieldWithPath("value.companyName").description("제조사"),
fieldWithPath("value.productType").description("제품 유형"),
fieldWithPath("value.upperItem").description("상위 분류"),
fieldWithPath("value.manufactureType").description("제조 타입"),
fieldWithPath("value.manufactureMethod").description("제조 방법"),
fieldWithPath("value.productType").description("제품구분"),
fieldWithPath("value.issuedDate").description("신고년월"),
fieldWithPath("value.safetyInspectionStandard").description("제품검사기준"),
fieldWithPath("value.upperItem").description("품목군"),
fieldWithPath("value.item").description("품목"),
fieldWithPath("value.propose").description("제품용도"),
fieldWithPath("value.weight").description("무게"),
fieldWithPath("value.reportNumber").description("보고 번호"),
fieldWithPath("value.usage").description("사용방법"),
fieldWithPath("value.usagePrecaution").description("사용시 주의사항"),
fieldWithPath("value.firstAid").description("응급처치법"),
fieldWithPath("value.mainSubstance").description("주요 성분"),
fieldWithPath("value.brand").description("브랜드"),
fieldWithPath("value.grade").description("평점"),
fieldWithPath("value.reviewCnt").description("리뷰 수"),
fieldWithPath("value.viewCount").description("조회수"),
fieldWithPath("value.createdAt").description("생성 날짜"),
fieldWithPath("value.allergicSubstance").description("알러지 반응 가능 물질"),
fieldWithPath("value.otherSubstance").description("기타 물질"),
fieldWithPath("value.preservative").description("보존제"),
fieldWithPath("value.surfactant").description("계면활성제"),
fieldWithPath("value.fluorescentWhitening").description("형광증백제"),
fieldWithPath("value.manufactureType").description("제조구분"),
fieldWithPath("value.manufactureMethod").description("제조방식"),
fieldWithPath("value.violationInfo").description("위반내역"),
fieldWithPath("value.createdAt").description("생성일"),
fieldWithPath("value.createdBy").description("생성자"),
fieldWithPath("value.modifiedAt").description("수정 날짜"),
fieldWithPath("value.modifiedAt").description("수정일"),
fieldWithPath("value.modifiedBy").description("수정자")
)));
verify(productService).getProductById(1L);
Expand All @@ -201,7 +239,7 @@ class ProductControllerTest extends ControllerTest {
.setNotNull("reportNumber")
.set("safetyStatus", SafetyStatus.CONCERN)
.set("viewCount", 0)
.setNotNull("brand")
// .setNotNull("brand")
.setNotNull("upperItem")
.setNotNull("createdAt")
.setNotNull("createdBy")
Expand Down Expand Up @@ -244,7 +282,7 @@ class ProductControllerTest extends ControllerTest {
fieldWithPath("value.content[*].reportNumber").description("보고서 번호"),
fieldWithPath("value.content[*].safetyStatus").description("안전 상태"),
fieldWithPath("value.content[*].viewCount").description("조회수"),
fieldWithPath("value.content[*].brand").description("브랜드"),
// fieldWithPath("value.content[*].brand").description("브랜드"),
fieldWithPath("value.content[*].upperItem").description("상위 항목 카테고리"),
fieldWithPath("value.content[*].createdAt").description("생성 날짜"),
fieldWithPath("value.content[*].createdBy").description("생성자"),
Expand Down

0 comments on commit 4da47b4

Please sign in to comment.