From 35a8c6fb0269065156b1cf266527919e9ca12f17 Mon Sep 17 00:00:00 2001 From: Mooooooo Date: Thu, 12 Oct 2023 10:54:19 +0900 Subject: [PATCH] =?UTF-8?q?refactor:=20=ED=8E=AB=ED=91=B8=EB=93=9C=20?= =?UTF-8?q?=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=BD=94=EB=93=9C=20=EB=A6=AC?= =?UTF-8?q?=ED=8C=A9=ED=84=B0=EB=A7=81=20(#459)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * refactor: PetFoodQueryRepository 테스트간 독립성 보장 * refactor: PetFoodQueryService 테스트간 독립성 보장 * refactor: PetFoodController 테스트간 독립성 보장 * refactor: PetFoodQueryRepository 테스트 수정 * refactor: fixture 수정 * refactor: PetFoodQueryService 테스트 수정 * refactor: PetFoodController 테스트 수정 * refactor: QueryServiceTest 삭제 * refactor: 테스트 환경 통합 및 불필요한 컨테이너 제거 * refactor: abstract 추가 --- .../java/zipgo/ZipgoApplicationTests.java | 13 - .../application/AdminQueryServiceTest.java | 10 +- ...t.java => AdminControllerMockMvcTest.java} | 35 +-- .../presentation/AuthControllerMockTest.java | 23 +- ...erTest.java => AuthControllerMvcTest.java} | 0 .../application/BrandQueryServiceTest.java | 4 +- .../common/acceptance/AcceptanceTest.java | 2 +- .../zipgo/common/acceptance/MockMvcTest.java | 53 +++- .../common/repository/RepositoryTest.java | 9 +- .../common/service/QueryServiceTest.java | 14 - .../zipgo/common/service/ServiceTest.java | 2 +- .../image/application/ImageServiceTest.java | 13 +- ...rTest.java => ImageControllerMvcTest.java} | 18 +- .../application/MemberQueryServiceTest.java | 6 +- .../pet/application/PetQueryServiceTest.java | 7 +- .../application/PetFoodQueryServiceTest.java | 254 +++++++++++++----- .../domain/fixture/FunctionalityFixture.java | 7 - .../domain/fixture/PetFoodFixture.java | 2 + .../fixture/PetFoodFunctionalityFixture.java | 11 +- .../PetFoodPrimaryIngredientFixture.java | 11 +- .../persist/PetFoodQueryRepositoryTest.java | 94 +++---- .../presentation/PetFoodControllerTest.java | 90 ++++--- .../application/ReviewQueryServiceTest.java | 4 +- .../ReviewQueryRepositoryImplTest.java | 23 +- 24 files changed, 396 insertions(+), 309 deletions(-) delete mode 100644 backend/src/test/java/zipgo/ZipgoApplicationTests.java rename backend/src/test/java/zipgo/admin/presentation/{AdminControllerMockTest.java => AdminControllerMockMvcTest.java} (85%) rename backend/src/test/java/zipgo/auth/presentation/{AuthControllerTest.java => AuthControllerMvcTest.java} (100%) delete mode 100644 backend/src/test/java/zipgo/common/service/QueryServiceTest.java rename backend/src/test/java/zipgo/image/presentaion/{ImageControllerTest.java => ImageControllerMvcTest.java} (80%) diff --git a/backend/src/test/java/zipgo/ZipgoApplicationTests.java b/backend/src/test/java/zipgo/ZipgoApplicationTests.java deleted file mode 100644 index fbbf9e809..000000000 --- a/backend/src/test/java/zipgo/ZipgoApplicationTests.java +++ /dev/null @@ -1,13 +0,0 @@ -package zipgo; - -import org.junit.jupiter.api.Test; -import org.springframework.boot.test.context.SpringBootTest; - -@SpringBootTest -class ZipgoApplicationTests { - - @Test - void contextLoads() { - } - -} diff --git a/backend/src/test/java/zipgo/admin/application/AdminQueryServiceTest.java b/backend/src/test/java/zipgo/admin/application/AdminQueryServiceTest.java index 918e81c0f..1065b5041 100644 --- a/backend/src/test/java/zipgo/admin/application/AdminQueryServiceTest.java +++ b/backend/src/test/java/zipgo/admin/application/AdminQueryServiceTest.java @@ -1,15 +1,14 @@ package zipgo.admin.application; -import java.util.List; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import zipgo.admin.dto.FunctionalitySelectResponse; import zipgo.admin.dto.PetFoodReadResponse; +import zipgo.admin.dto.PrimaryIngredientSelectResponse; import zipgo.brand.domain.Brand; import zipgo.brand.domain.fixture.BrandFixture; import zipgo.brand.domain.repository.BrandRepository; -import zipgo.common.service.QueryServiceTest; +import zipgo.common.service.ServiceTest; import zipgo.petfood.domain.PetFood; import zipgo.petfood.domain.fixture.FunctionalityFixture; import zipgo.petfood.domain.fixture.PetFoodFixture; @@ -17,12 +16,13 @@ import zipgo.petfood.domain.repository.FunctionalityRepository; import zipgo.petfood.domain.repository.PetFoodRepository; import zipgo.petfood.domain.repository.PrimaryIngredientRepository; -import zipgo.admin.dto.PrimaryIngredientSelectResponse; + +import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; -class AdminQueryServiceTest extends QueryServiceTest { +class AdminQueryServiceTest extends ServiceTest { @Autowired private FunctionalityRepository functionalityRepository; diff --git a/backend/src/test/java/zipgo/admin/presentation/AdminControllerMockTest.java b/backend/src/test/java/zipgo/admin/presentation/AdminControllerMockMvcTest.java similarity index 85% rename from backend/src/test/java/zipgo/admin/presentation/AdminControllerMockTest.java rename to backend/src/test/java/zipgo/admin/presentation/AdminControllerMockMvcTest.java index ad05e4969..402bad4c6 100644 --- a/backend/src/test/java/zipgo/admin/presentation/AdminControllerMockTest.java +++ b/backend/src/test/java/zipgo/admin/presentation/AdminControllerMockMvcTest.java @@ -1,27 +1,20 @@ package zipgo.admin.presentation; import com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper; -import com.fasterxml.jackson.databind.ObjectMapper; + +import java.nio.charset.StandardCharsets; +import java.util.List; + import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; -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.http.MediaType; import org.springframework.mock.web.MockMultipartFile; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; -import zipgo.admin.application.AdminQueryService; -import zipgo.admin.application.AdminService; +import zipgo.common.acceptance.MockMvcTest; import zipgo.admin.dto.BrandCreateRequest; import zipgo.admin.dto.PetFoodCreateRequest; -import zipgo.auth.presentation.JwtMandatoryArgumentResolver; -import zipgo.common.acceptance.MockMvcTest; -import zipgo.image.application.ImageService; import zipgo.petfood.domain.fixture.PetFoodFixture; -import java.nio.charset.StandardCharsets; -import java.util.List; - import static com.epages.restdocs.apispec.RestAssuredRestDocumentationWrapper.resourceDetails; import static org.mockito.Mockito.when; import static org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.multipart; @@ -31,23 +24,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static zipgo.brand.domain.fixture.BrandFixture.무민_브랜드_생성_요청; -@WebMvcTest(controllers = AdminController.class) -class AdminControllerMockTest extends MockMvcTest { - - @Autowired - private ObjectMapper objectMapper; - - @MockBean - private ImageService imageService; - - @MockBean - private AdminService adminService; - - @MockBean - private AdminQueryService adminQueryService; - - @MockBean - private JwtMandatoryArgumentResolver argumentResolver; +class AdminControllerMockMvcTest extends MockMvcTest { @Test void 브랜드를_생성하면_201이_반환된다() throws Exception { diff --git a/backend/src/test/java/zipgo/auth/presentation/AuthControllerMockTest.java b/backend/src/test/java/zipgo/auth/presentation/AuthControllerMockTest.java index 12289e9ad..cdb6dd717 100644 --- a/backend/src/test/java/zipgo/auth/presentation/AuthControllerMockTest.java +++ b/backend/src/test/java/zipgo/auth/presentation/AuthControllerMockTest.java @@ -1,25 +1,19 @@ package zipgo.auth.presentation; -import java.util.List; - import com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper; import com.epages.restdocs.apispec.ResourceSnippetDetails; import com.epages.restdocs.apispec.Schema; import org.junit.jupiter.api.Test; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.http.ResponseCookie; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.restdocs.payload.JsonFieldType; -import zipgo.auth.application.AuthService; import zipgo.auth.dto.TokenDto; import zipgo.auth.exception.OAuthTokenNotBringException; -import zipgo.auth.support.RefreshTokenCookieProvider; import zipgo.common.acceptance.MockMvcTest; -import zipgo.member.application.MemberQueryService; -import zipgo.pet.application.PetQueryService; import zipgo.pet.domain.fixture.PetFixture; +import java.util.List; + import static com.epages.restdocs.apispec.RestAssuredRestDocumentationWrapper.resourceDetails; import static java.util.Collections.EMPTY_LIST; import static org.mockito.Mockito.when; @@ -31,7 +25,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static zipgo.member.domain.fixture.MemberFixture.식별자_있는_멤버; -@WebMvcTest(controllers = AuthController.class) class AuthControllerMockTest extends MockMvcTest { private static final Schema 응답_형식 = Schema.schema("TokenResponse"); @@ -39,18 +32,6 @@ class AuthControllerMockTest extends MockMvcTest { .description("로그인 합니다.") .responseSchema(응답_형식); - @MockBean - private MemberQueryService memberQueryService; - - @MockBean - private PetQueryService petQueryService; - - @MockBean - private RefreshTokenCookieProvider refreshTokenCookieProvider; - - @MockBean - private AuthService authService; - @Test void 로그인_성공() throws Exception { // given diff --git a/backend/src/test/java/zipgo/auth/presentation/AuthControllerTest.java b/backend/src/test/java/zipgo/auth/presentation/AuthControllerMvcTest.java similarity index 100% rename from backend/src/test/java/zipgo/auth/presentation/AuthControllerTest.java rename to backend/src/test/java/zipgo/auth/presentation/AuthControllerMvcTest.java diff --git a/backend/src/test/java/zipgo/brand/application/BrandQueryServiceTest.java b/backend/src/test/java/zipgo/brand/application/BrandQueryServiceTest.java index 198990ac9..0a2d6da98 100644 --- a/backend/src/test/java/zipgo/brand/application/BrandQueryServiceTest.java +++ b/backend/src/test/java/zipgo/brand/application/BrandQueryServiceTest.java @@ -5,11 +5,11 @@ import zipgo.brand.domain.Brand; import zipgo.brand.domain.fixture.BrandFixture; import zipgo.brand.domain.repository.BrandRepository; -import zipgo.common.service.QueryServiceTest; +import zipgo.common.service.ServiceTest; import static org.assertj.core.api.Assertions.assertThat; -class BrandQueryServiceTest extends QueryServiceTest { +class BrandQueryServiceTest extends ServiceTest { @Autowired private BrandRepository brandRepository; diff --git a/backend/src/test/java/zipgo/common/acceptance/AcceptanceTest.java b/backend/src/test/java/zipgo/common/acceptance/AcceptanceTest.java index 99fea925b..8cb1af3b6 100644 --- a/backend/src/test/java/zipgo/common/acceptance/AcceptanceTest.java +++ b/backend/src/test/java/zipgo/common/acceptance/AcceptanceTest.java @@ -23,10 +23,10 @@ import static org.springframework.test.context.jdbc.Sql.ExecutionPhase.AFTER_TEST_METHOD; @SuppressWarnings("NonAsciiCharacters") -@Sql(scripts = {"classpath:truncate.sql"}, executionPhase = AFTER_TEST_METHOD) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) @ExtendWith({RestDocumentationExtension.class, SpringExtension.class}) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) +@Sql(scripts = {"classpath:truncate.sql"}, executionPhase = AFTER_TEST_METHOD) public abstract class AcceptanceTest { protected RequestSpecification spec; diff --git a/backend/src/test/java/zipgo/common/acceptance/MockMvcTest.java b/backend/src/test/java/zipgo/common/acceptance/MockMvcTest.java index d432b803f..51a8ee5a3 100644 --- a/backend/src/test/java/zipgo/common/acceptance/MockMvcTest.java +++ b/backend/src/test/java/zipgo/common/acceptance/MockMvcTest.java @@ -1,5 +1,6 @@ package zipgo.common.acceptance; +import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.extension.ExtendWith; @@ -9,22 +10,70 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.web.servlet.MockMvc; +import zipgo.admin.application.AdminQueryService; +import zipgo.admin.application.AdminService; +import zipgo.admin.presentation.AdminController; import zipgo.aspect.QueryCounter; +import zipgo.auth.application.AuthService; +import zipgo.auth.presentation.AuthController; +import zipgo.auth.presentation.AuthInterceptor; +import zipgo.auth.presentation.JwtMandatoryArgumentResolver; import zipgo.auth.support.JwtProvider; +import zipgo.auth.support.RefreshTokenCookieProvider; +import zipgo.image.application.ImageService; +import zipgo.image.presentaion.ImageController; +import zipgo.member.application.MemberQueryService; +import zipgo.pet.application.PetQueryService; -@WebMvcTest @AutoConfigureRestDocs @ExtendWith(SpringExtension.class) @SuppressWarnings("NonAsciiCharacters") +@WebMvcTest( + controllers = { + AdminController.class, + AuthController.class, + ImageController.class + } +) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -public class MockMvcTest { +public abstract class MockMvcTest { + + @Autowired + protected ObjectMapper objectMapper; @Autowired protected MockMvc mockMvc; + @MockBean + protected ImageService imageService; + + @MockBean + protected AdminService adminService; + + @MockBean + protected AdminQueryService adminQueryService; + @MockBean protected JwtProvider jwtProvider; + @MockBean + protected AuthInterceptor authInterceptor; + + @MockBean + protected JwtMandatoryArgumentResolver argumentResolver; + + @MockBean + protected MemberQueryService memberQueryService; + + @MockBean + protected PetQueryService petQueryService; + + @MockBean + protected AuthService authService; + + @MockBean + protected RefreshTokenCookieProvider refreshTokenCookieProvider; + @MockBean protected QueryCounter queryCounter; diff --git a/backend/src/test/java/zipgo/common/repository/RepositoryTest.java b/backend/src/test/java/zipgo/common/repository/RepositoryTest.java index d3b621058..fc23ae3e7 100644 --- a/backend/src/test/java/zipgo/common/repository/RepositoryTest.java +++ b/backend/src/test/java/zipgo/common/repository/RepositoryTest.java @@ -5,11 +5,16 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.annotation.Import; import zipgo.common.config.JpaConfig; +import zipgo.common.config.QueryDslTestConfig; + @DataJpaTest -@Import(JpaConfig.class) +@Import({ + JpaConfig.class, + QueryDslTestConfig.class +}) @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -public class RepositoryTest { +public abstract class RepositoryTest { } diff --git a/backend/src/test/java/zipgo/common/service/QueryServiceTest.java b/backend/src/test/java/zipgo/common/service/QueryServiceTest.java deleted file mode 100644 index ccc2866f1..000000000 --- a/backend/src/test/java/zipgo/common/service/QueryServiceTest.java +++ /dev/null @@ -1,14 +0,0 @@ -package zipgo.common.service; - -import org.junit.jupiter.api.DisplayNameGeneration; -import org.junit.jupiter.api.DisplayNameGenerator; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.transaction.annotation.Transactional; - -@Transactional -@SuppressWarnings("NonAsciiCharacters") -@SpringBootTest(properties = {"spring.sql.init.mode=never"}) -@DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -public class QueryServiceTest { - -} diff --git a/backend/src/test/java/zipgo/common/service/ServiceTest.java b/backend/src/test/java/zipgo/common/service/ServiceTest.java index fe4a13152..c00d01e58 100644 --- a/backend/src/test/java/zipgo/common/service/ServiceTest.java +++ b/backend/src/test/java/zipgo/common/service/ServiceTest.java @@ -9,6 +9,6 @@ @SuppressWarnings("NonAsciiCharacters") @SpringBootTest(properties = {"spring.sql.init.mode=never"}) @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) -public class ServiceTest { +public abstract class ServiceTest { } diff --git a/backend/src/test/java/zipgo/image/application/ImageServiceTest.java b/backend/src/test/java/zipgo/image/application/ImageServiceTest.java index 81115ae01..cb52644ea 100644 --- a/backend/src/test/java/zipgo/image/application/ImageServiceTest.java +++ b/backend/src/test/java/zipgo/image/application/ImageServiceTest.java @@ -4,24 +4,25 @@ import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.mock.mockito.MockBean; +import org.junit.jupiter.api.extension.ExtendWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.mock.web.MockMultipartFile; import static org.mockito.Mockito.any; import static org.mockito.Mockito.when; -@SpringBootTest +@ExtendWith(MockitoExtension.class) @SuppressWarnings("NonAsciiCharacters") @DisplayNameGeneration(DisplayNameGenerator.ReplaceUnderscores.class) class ImageServiceTest { - @MockBean + @Mock private ImageClient imageClient; - @Autowired + @InjectMocks private ImageService imageService; @Test diff --git a/backend/src/test/java/zipgo/image/presentaion/ImageControllerTest.java b/backend/src/test/java/zipgo/image/presentaion/ImageControllerMvcTest.java similarity index 80% rename from backend/src/test/java/zipgo/image/presentaion/ImageControllerTest.java rename to backend/src/test/java/zipgo/image/presentaion/ImageControllerMvcTest.java index 9f8b72d25..48b78d65f 100644 --- a/backend/src/test/java/zipgo/image/presentaion/ImageControllerTest.java +++ b/backend/src/test/java/zipgo/image/presentaion/ImageControllerMvcTest.java @@ -2,18 +2,12 @@ import com.epages.restdocs.apispec.MockMvcRestDocumentationWrapper; import org.junit.jupiter.api.Test; -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.http.MediaType; import org.springframework.mock.web.MockMultipartFile; import org.springframework.restdocs.mockmvc.RestDocumentationResultHandler; import org.springframework.restdocs.payload.JsonFieldType; -import org.springframework.test.web.servlet.MockMvc; -import zipgo.auth.presentation.JwtMandatoryArgumentResolver; import zipgo.common.acceptance.MockMvcTest; import zipgo.image.ImageDirectoryUrl; -import zipgo.image.application.ImageService; import static com.epages.restdocs.apispec.RestAssuredRestDocumentationWrapper.resourceDetails; import static org.mockito.Mockito.when; @@ -26,17 +20,7 @@ import static org.springframework.restdocs.request.RequestDocumentation.requestParts; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -@WebMvcTest(controllers = ImageController.class) -class ImageControllerTest extends MockMvcTest { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private ImageService imageService; - - @MockBean - private JwtMandatoryArgumentResolver argumentResolver; +class ImageControllerMvcTest extends MockMvcTest { @Test void 사진_등록_성공하면_201_반환() throws Exception { diff --git a/backend/src/test/java/zipgo/member/application/MemberQueryServiceTest.java b/backend/src/test/java/zipgo/member/application/MemberQueryServiceTest.java index 1c196396f..0abba2e01 100644 --- a/backend/src/test/java/zipgo/member/application/MemberQueryServiceTest.java +++ b/backend/src/test/java/zipgo/member/application/MemberQueryServiceTest.java @@ -2,14 +2,14 @@ import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import zipgo.common.service.QueryServiceTest; +import zipgo.common.service.ServiceTest; import zipgo.member.domain.Member; import zipgo.member.domain.repository.MemberRepository; import static org.assertj.core.api.Assertions.assertThat; import static zipgo.member.domain.fixture.MemberFixture.식별자_없는_멤버; -class MemberQueryServiceTest extends QueryServiceTest { +class MemberQueryServiceTest extends ServiceTest { @Autowired private MemberRepository memberRepository; @@ -30,4 +30,4 @@ class MemberQueryServiceTest extends QueryServiceTest { assertThat(찾은_멤버).isEqualTo(저장된_멤버); } -} \ No newline at end of file +} diff --git a/backend/src/test/java/zipgo/pet/application/PetQueryServiceTest.java b/backend/src/test/java/zipgo/pet/application/PetQueryServiceTest.java index 5a403aa44..2c36fb1f9 100644 --- a/backend/src/test/java/zipgo/pet/application/PetQueryServiceTest.java +++ b/backend/src/test/java/zipgo/pet/application/PetQueryServiceTest.java @@ -1,10 +1,9 @@ package zipgo.pet.application; -import java.util.List; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import zipgo.common.service.QueryServiceTest; +import zipgo.common.service.ServiceTest; import zipgo.member.domain.Member; import zipgo.member.domain.repository.MemberRepository; import zipgo.pet.domain.Breed; @@ -15,11 +14,13 @@ import zipgo.pet.domain.repository.PetRepository; import zipgo.pet.domain.repository.PetSizeRepository; +import java.util.List; + import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertAll; import static zipgo.review.fixture.MemberFixture.멤버_이름; -class PetQueryServiceTest extends QueryServiceTest { +class PetQueryServiceTest extends ServiceTest { @Autowired private BreedRepository breedRepository; diff --git a/backend/src/test/java/zipgo/petfood/application/PetFoodQueryServiceTest.java b/backend/src/test/java/zipgo/petfood/application/PetFoodQueryServiceTest.java index 1b88effd3..dda3fc7aa 100644 --- a/backend/src/test/java/zipgo/petfood/application/PetFoodQueryServiceTest.java +++ b/backend/src/test/java/zipgo/petfood/application/PetFoodQueryServiceTest.java @@ -1,10 +1,8 @@ package zipgo.petfood.application; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.transaction.annotation.Transactional; import zipgo.brand.domain.Brand; import zipgo.brand.domain.repository.BrandRepository; import zipgo.common.service.ServiceTest; @@ -21,7 +19,9 @@ import zipgo.petfood.dto.response.FilterResponse.FunctionalityResponse; import zipgo.petfood.dto.response.GetPetFoodResponse; import zipgo.petfood.dto.response.GetPetFoodsResponse; +import zipgo.petfood.dto.response.PetFoodResponse; +import java.util.Arrays; import java.util.List; import static java.util.Collections.EMPTY_LIST; @@ -38,7 +38,9 @@ import static zipgo.petfood.domain.fixture.PetFoodFixture.미국_영양기준_만족_식품; import static zipgo.petfood.domain.fixture.PetFoodFixture.유럽_영양기준_만족_식품; import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.식품_기능성_연관관계_매핑; +import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.식품_기능성_추가; import static zipgo.petfood.domain.fixture.PetFoodPrimaryIngredientFixture.식품_주원료_연관관계_매핑; +import static zipgo.petfood.domain.fixture.PetFoodPrimaryIngredientFixture.식품_주원료_추가; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_닭고기; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_돼지고기; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_말미잘; @@ -65,52 +67,26 @@ class PetFoodQueryServiceTest extends ServiceTest { @Autowired private FunctionalityRepository functionalityRepository; - @BeforeEach - void setUp() { - Brand 아카나 = brandRepository.save(아카나_식품_브랜드_생성()); - Brand 오리젠 = brandRepository.save(오리젠_식품_브랜드_생성()); - Brand 퓨리나 = brandRepository.save(퓨리나_식품_브랜드_생성()); - - PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(아카나); - PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(오리젠); - PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(퓨리나); - - Functionality 기능성_튼튼 = 기능성_튼튼(); - Functionality 기능성_짱짱 = 기능성_짱짱(); - Functionality 기능성_다이어트 = 기능성_다이어트(); - - 식품_기능성_연관관계_매핑(모든_영양기준_만족_식품, 기능성_튼튼); - 식품_기능성_연관관계_매핑(미국_영양기준_만족_식품, 기능성_짱짱); - 식품_기능성_연관관계_매핑(유럽_영양기준_만족_식품, 기능성_다이어트); - - PrimaryIngredient 원재료_소고기 = 주원료_소고기(); - PrimaryIngredient 원재료_돼지고기 = 주원료_돼지고기(); - PrimaryIngredient 원재료_닭고기 = 주원료_닭고기(); - - 식품_주원료_연관관계_매핑(모든_영양기준_만족_식품, 원재료_소고기); - 식품_주원료_연관관계_매핑(미국_영양기준_만족_식품, 원재료_돼지고기); - 식품_주원료_연관관계_매핑(유럽_영양기준_만족_식품, 원재료_닭고기); - - petFoodRepository.save(모든_영양기준_만족_식품); - petFoodRepository.save(미국_영양기준_만족_식품); - petFoodRepository.save(유럽_영양기준_만족_식품); - - functionalityRepository.save(기능성_튼튼); - functionalityRepository.save(기능성_짱짱); - functionalityRepository.save(기능성_다이어트); - - primaryIngredientRepository.save(원재료_소고기); - primaryIngredientRepository.save(원재료_돼지고기); - primaryIngredientRepository.save(원재료_닭고기); - } - @Nested - @Transactional class 필터_조회 { @Test void 브랜드를_만족하는_식품만_반환한다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = getLastPetFoodId(allFoods); @@ -139,8 +115,22 @@ private Long getLastPetFoodId(List allFoods) { } @Test - void 브랜드를_만족하고_lastPetFoodId보다_작은_식품만_반환한다() { + void 브랜드를_만족하고_lastPetFoodId_보다_작은_식품만_반환한다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = getLastPetFoodId(allFoods); @@ -167,6 +157,20 @@ private Long getLastPetFoodId(List allFoods) { @Test void 영양_기준을_만족하는_식품만_반환한다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = getLastPetFoodId(allFoods); @@ -196,6 +200,20 @@ private Long getLastPetFoodId(List allFoods) { @Test void 주원료를_만족하는_식품만_반환한다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = getLastPetFoodId(allFoods); @@ -222,6 +240,20 @@ private Long getLastPetFoodId(List allFoods) { @Test void 기능성을_만족하는_식품만_반환한다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = getLastPetFoodId(allFoods); @@ -249,6 +281,20 @@ private Long getLastPetFoodId(List allFoods) { @Test void 모든_필터를_만족하는_식품만_반환한다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = allFoods.get(allFoods.size() - 1).getId(); @@ -273,8 +319,22 @@ private Long getLastPetFoodId(List allFoods) { } @Test - void 모든_정보가_NULL일_경우_모든_식품을_반환한다() { + void 모든_정보가_EMPTY_일_경우_모든_식품을_반환한다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = getLastPetFoodId(allFoods); @@ -297,8 +357,19 @@ private Long getLastPetFoodId(List allFoods) { @Test void lastPetFoodId_보다_작은_식품을_반환한다() { //given - List allFoods = petFoodRepository.findAll(); - Long lastPetFoodId = getLastPetFoodId(allFoods); + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); // when GetPetFoodsResponse petFoodsResponse = petFoodQueryService.getPetFoodsByFilters( @@ -308,26 +379,24 @@ private Long getLastPetFoodId(List allFoods) { EMPTY_LIST, EMPTY_LIST ), - lastPetFoodId, + 유럽_영양기준_만족_식품.getId() - 1, size ); // then - assertThat(petFoodsResponse.petFoods()).hasSize(allFoods.size()); + assertThat(petFoodsResponse.petFoods()).hasSize(2); } @Test - void 처음_조회_시_정해진_size_이내로_반환한다() { + void 처음_조회시_식품이_최신순으로_정해진_size_이내로_반환한다() { //given Brand 인스팅트 = brandRepository.save(인스팅트_식품_브랜드_생성()); PrimaryIngredient 원재료_말미잘 = primaryIngredientRepository.save(주원료_말미잘()); - Functionality 기능성_짱짱짱 = functionalityRepository.save(FunctionalityFixture.기능성_짱짱짱()); - for (int i = 0; i < 20; i++) { - PetFood 미국_영양기준_만족_식품 = savePetFood(인스팅트); - PetFood 미국_영양기준_만족_식품1 = 미국_영양기준_만족_식품(인스팅트); - 식품_주원료_연관관계_매핑(미국_영양기준_만족_식품, 원재료_말미잘); - 식품_기능성_연관관계_매핑(미국_영양기준_만족_식품, 기능성_짱짱짱); - petFoodRepository.save(미국_영양기준_만족_식품1); + Functionality 기능성_짱짱 = functionalityRepository.save(FunctionalityFixture.기능성_짱짱()); + for (int i = 0; i < 25; i++) { + PetFood 추가_미국_영양기준_만족_식품 = savePetFood(인스팅트); + 식품_주원료_연관관계_매핑(추가_미국_영양기준_만족_식품, 원재료_말미잘); + 식품_기능성_연관관계_매핑(추가_미국_영양기준_만족_식품, 기능성_짱짱); } // when @@ -343,21 +412,49 @@ private Long getLastPetFoodId(List allFoods) { ); // then - assertThat(petFoodsResponse.petFoods()).hasSize(20); + final List petFoods = petFoodsResponse.petFoods(); + assertAll( + () -> assertThat(petFoodsResponse.totalCount()).isEqualTo(25), + () -> assertThat(petFoodsResponse.petFoods()).hasSize(20), + () -> assertThat(isLatest(petFoods.get(0).id(), petFoods)).isTrue() + ); } private PetFood savePetFood(Brand 브랜드) { return petFoodRepository.save(미국_영양기준_만족_식품(브랜드)); } + private boolean isLatest(long id, List petFoodResponses) { + for (PetFoodResponse petFoodResponse : petFoodResponses) { + if (petFoodResponse.id() > id) { + return false; + } + } + return true; + } + } @Nested class 상세_조회 { @Test - void 식품_상세조회할수_있다() { + void 식품에_대한_상세조회를_할_수_있다() { //given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + PetFood 테스트용_식품 = petFoodRepository.findAll().get(0); Brand 브랜드 = brandRepository.findById(테스트용_식품.getBrand().getId()).get(); @@ -365,23 +462,30 @@ class 상세_조회 { GetPetFoodResponse 응답 = petFoodQueryService.getPetFoodResponse(테스트용_식품.getId()); //then - assertThat(응답.id()).isEqualTo(테스트용_식품.getId()); - assertThat(응답.name()).isEqualTo(테스트용_식품.getName()); - assertThat(응답.imageUrl()).isEqualTo(테스트용_식품.getImageUrl()); - assertThat(응답.purchaseUrl()).isEqualTo(테스트용_식품.getPurchaseLink()); - assertThat(응답.brand().name()).isEqualTo(브랜드.getName()); - assertThat(응답.brand().foundedYear()).isEqualTo(브랜드.getFoundedYear()); - assertThat(응답.brand().nation()).isEqualTo(브랜드.getNation()); - assertThat(응답.rating()).isEqualTo(0); - assertThat(응답.reviewCount()).isEqualTo(0); - assertThat(응답.hasStandard().hasEuStandard()).isTrue(); - assertThat(응답.hasStandard().hasUsStandard()).isTrue(); + assertAll( + () -> assertThat(응답.id()).isEqualTo(테스트용_식품.getId()), + () -> assertThat(응답.name()).isEqualTo(테스트용_식품.getName()), + () -> assertThat(응답.imageUrl()).isEqualTo(테스트용_식품.getImageUrl()), + () -> assertThat(응답.purchaseUrl()).isEqualTo(테스트용_식품.getPurchaseLink()), + () -> assertThat(응답.brand().name()).isEqualTo(브랜드.getName()), + () -> assertThat(응답.brand().foundedYear()).isEqualTo(브랜드.getFoundedYear()), + () -> assertThat(응답.brand().nation()).isEqualTo(브랜드.getNation()), + () -> assertThat(응답.rating()).isEqualTo(0), + () -> assertThat(응답.reviewCount()).isEqualTo(0), + () -> assertThat(응답.hasStandard().hasEuStandard()).isTrue(), + () -> assertThat(응답.hasStandard().hasUsStandard()).isTrue() + ); } } @Test void 필터링에_필요한_식품_데이터를_조회한다() { + // given + saveBrands(아카나_식품_브랜드_생성(), 오리젠_식품_브랜드_생성(), 퓨리나_식품_브랜드_생성()); + saveFunctionalities(기능성_튼튼(), 기능성_짱짱(), 기능성_다이어트()); + savePrimaryIngredients(주원료_소고기(), 주원료_돼지고기(), 주원료_닭고기()); + // when FilterResponse metadata = petFoodQueryService.getMetadataForFilter(); @@ -398,5 +502,17 @@ class 상세_조회 { ); } + private void saveBrands(Brand... brands) { + brandRepository.saveAll(Arrays.asList(brands)); + } + + private void saveFunctionalities(Functionality... functionalities) { + functionalityRepository.saveAll(Arrays.asList(functionalities)); + } + + private void savePrimaryIngredients(PrimaryIngredient... primaryIngredients) { + primaryIngredientRepository.saveAll(Arrays.asList(primaryIngredients)); + } + } diff --git a/backend/src/test/java/zipgo/petfood/domain/fixture/FunctionalityFixture.java b/backend/src/test/java/zipgo/petfood/domain/fixture/FunctionalityFixture.java index c53ceb9ca..4bca06002 100644 --- a/backend/src/test/java/zipgo/petfood/domain/fixture/FunctionalityFixture.java +++ b/backend/src/test/java/zipgo/petfood/domain/fixture/FunctionalityFixture.java @@ -29,11 +29,4 @@ public class FunctionalityFixture { return 짱짱; } - public static Functionality 기능성_짱짱짱() { - Functionality 짱짱 = Functionality.builder() - .name("짱짱짱") - .build(); - return 짱짱; - } - } diff --git a/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFixture.java b/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFixture.java index 2e03914cc..de498c314 100644 --- a/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFixture.java +++ b/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFixture.java @@ -1,11 +1,13 @@ package zipgo.petfood.domain.fixture; +import java.util.Arrays; import java.util.List; import zipgo.brand.domain.Brand; import zipgo.petfood.domain.HasStandard; import zipgo.petfood.domain.PetFood; import zipgo.petfood.domain.Reviews; import zipgo.admin.dto.PetFoodCreateRequest; +import zipgo.petfood.domain.repository.PetFoodRepository; import static zipgo.petfood.domain.PetFood.builder; diff --git a/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFunctionalityFixture.java b/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFunctionalityFixture.java index 203e716d0..408833f43 100644 --- a/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFunctionalityFixture.java +++ b/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodFunctionalityFixture.java @@ -3,15 +3,24 @@ import zipgo.petfood.domain.Functionality; import zipgo.petfood.domain.PetFood; import zipgo.petfood.domain.PetFoodFunctionality; +import zipgo.petfood.domain.repository.FunctionalityRepository; public class PetFoodFunctionalityFixture { - public static void 식품_기능성_연관관계_매핑(PetFood petFood, Functionality functionality) { + public static PetFoodFunctionality 식품_기능성_연관관계_매핑(PetFood petFood, Functionality functionality) { PetFoodFunctionality petFoodFunctionality = PetFoodFunctionality.builder() .petFood(petFood) .functionality(functionality) .build(); petFoodFunctionality.changeRelations(petFood, functionality); + return petFoodFunctionality; + } + + public static PetFoodFunctionality 식품_기능성_추가( + PetFood petFood, + Functionality functionality + ) { + return 식품_기능성_연관관계_매핑(petFood, functionality); } } diff --git a/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodPrimaryIngredientFixture.java b/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodPrimaryIngredientFixture.java index 661c7705e..b1e2b7ef3 100644 --- a/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodPrimaryIngredientFixture.java +++ b/backend/src/test/java/zipgo/petfood/domain/fixture/PetFoodPrimaryIngredientFixture.java @@ -3,12 +3,21 @@ import zipgo.petfood.domain.PetFood; import zipgo.petfood.domain.PetFoodPrimaryIngredient; import zipgo.petfood.domain.PrimaryIngredient; +import zipgo.petfood.domain.repository.PrimaryIngredientRepository; public class PetFoodPrimaryIngredientFixture { - public static void 식품_주원료_연관관계_매핑(PetFood petFood, PrimaryIngredient primaryIngredient) { + public static PetFoodPrimaryIngredient 식품_주원료_연관관계_매핑(PetFood petFood, PrimaryIngredient primaryIngredient) { PetFoodPrimaryIngredient petFoodPrimaryIngredient = new PetFoodPrimaryIngredient(); petFoodPrimaryIngredient.changeRelations(petFood, primaryIngredient); + return petFoodPrimaryIngredient; + } + + public static PetFoodPrimaryIngredient 식품_주원료_추가( + PetFood petFood, + PrimaryIngredient primaryIngredient + ) { + return 식품_주원료_연관관계_매핑(petFood, primaryIngredient); } } diff --git a/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java b/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java index 371bc9476..ef5c56613 100644 --- a/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java +++ b/backend/src/test/java/zipgo/petfood/infra/persist/PetFoodQueryRepositoryTest.java @@ -1,26 +1,24 @@ package zipgo.petfood.infra.persist; -import java.util.List; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayNameGeneration; import org.junit.jupiter.api.DisplayNameGenerator; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.transaction.annotation.Transactional; -import zipgo.brand.domain.Brand; import zipgo.brand.domain.repository.BrandRepository; -import zipgo.petfood.domain.Functionality; import zipgo.petfood.domain.PetFood; -import zipgo.petfood.domain.PrimaryIngredient; import zipgo.petfood.domain.repository.FunctionalityRepository; +import zipgo.petfood.domain.repository.PetFoodQueryRepository; import zipgo.petfood.domain.repository.PetFoodRepository; import zipgo.petfood.domain.repository.PrimaryIngredientRepository; import zipgo.petfood.dto.response.GetPetFoodQueryResponse; +import java.util.List; + import static java.util.Collections.EMPTY_LIST; import static org.assertj.core.api.Assertions.assertThat; +import static org.junit.jupiter.api.Assertions.assertAll; import static zipgo.brand.domain.fixture.BrandFixture.아카나_식품_브랜드_생성; import static zipgo.brand.domain.fixture.BrandFixture.오리젠_식품_브랜드_생성; import static zipgo.brand.domain.fixture.BrandFixture.퓨리나_식품_브랜드_생성; @@ -31,7 +29,9 @@ import static zipgo.petfood.domain.fixture.PetFoodFixture.미국_영양기준_만족_식품; import static zipgo.petfood.domain.fixture.PetFoodFixture.유럽_영양기준_만족_식품; import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.식품_기능성_연관관계_매핑; +import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.식품_기능성_추가; import static zipgo.petfood.domain.fixture.PetFoodPrimaryIngredientFixture.식품_주원료_연관관계_매핑; +import static zipgo.petfood.domain.fixture.PetFoodPrimaryIngredientFixture.식품_주원료_추가; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_닭고기; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_돼지고기; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_말미잘; @@ -47,7 +47,7 @@ class PetFoodQueryRepositoryTest { private PetFoodRepository petFoodRepository; @Autowired - private PetFoodQueryRepositoryImpl petFoodQueryRepository; + private PetFoodQueryRepository petFoodQueryRepository; @Autowired private BrandRepository brandRepository; @@ -58,48 +58,23 @@ class PetFoodQueryRepositoryTest { @Autowired private PrimaryIngredientRepository primaryIngredientRepository; - @BeforeEach - void setUp() { - Brand 아카나 = brandRepository.save(아카나_식품_브랜드_생성()); - Brand 오리젠 = brandRepository.save(오리젠_식품_브랜드_생성()); - Brand 퓨리나 = brandRepository.save(퓨리나_식품_브랜드_생성()); - - PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(아카나); - PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(오리젠); - PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(퓨리나); - - Functionality 기능성_튼튼 = 기능성_튼튼(); - Functionality 기능성_짱짱 = 기능성_짱짱(); - Functionality 기능성_다이어트 = 기능성_다이어트(); - - 식품_기능성_연관관계_매핑(모든_영양기준_만족_식품, 기능성_튼튼); - 식품_기능성_연관관계_매핑(미국_영양기준_만족_식품, 기능성_짱짱); - 식품_기능성_연관관계_매핑(유럽_영양기준_만족_식품, 기능성_다이어트); - - PrimaryIngredient 원재료_소고기 = 주원료_소고기(); - PrimaryIngredient 원재료_돼지고기 = 주원료_돼지고기(); - PrimaryIngredient 원재료_닭고기 = 주원료_닭고기(); - - 식품_주원료_연관관계_매핑(모든_영양기준_만족_식품, 원재료_소고기); - 식품_주원료_연관관계_매핑(미국_영양기준_만족_식품, 원재료_돼지고기); - 식품_주원료_연관관계_매핑(유럽_영양기준_만족_식품, 원재료_닭고기); + @Test + void 조건에_맞는_식품을_반환한다() { + // given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); - petFoodRepository.save(모든_영양기준_만족_식품); - petFoodRepository.save(미국_영양기준_만족_식품); - petFoodRepository.save(유럽_영양기준_만족_식품); + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); - functionalityRepository.save(기능성_튼튼); - functionalityRepository.save(기능성_짱짱); - functionalityRepository.save(기능성_다이어트); + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); - primaryIngredientRepository.save(원재료_소고기); - primaryIngredientRepository.save(원재료_돼지고기); - primaryIngredientRepository.save(원재료_닭고기); - } + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); - @Test - void 조건에_맞는_식품을_필터링한다() { - // given List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = allFoods.get(allFoods.size() - 1).getId(); @@ -107,13 +82,14 @@ void setUp() { List standards = List.of("미국"); List primaryIngredientList = EMPTY_LIST; List functionalityList = EMPTY_LIST; + int size = 20; // when - List responses = petFoodQueryRepository.findPagingPetFoods(brandsName, standards, primaryIngredientList, - functionalityList, lastPetFoodId, 20); + List responses = petFoodQueryRepository.findPagingPetFoods(brandsName, standards, + primaryIngredientList, functionalityList, lastPetFoodId, size); // then - Assertions.assertAll( + assertAll( () -> assertThat(responses).hasSize(1), () -> assertThat(responses).extracting(GetPetFoodQueryResponse::foodName) .contains("미국 영양기준 만족 식품"), @@ -123,8 +99,22 @@ void setUp() { } @Test - void 같은_식품을_제거하고_limit_개수만큼_반환한다() { + void 조건에_맞는_식품의_전체_개수를_반환한다() { // given + PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + PetFood 미국_영양기준_만족_식품 = 미국_영양기준_만족_식품(brandRepository.save(오리젠_식품_브랜드_생성())); + PetFood 유럽_영양기준_만족_식품 = 유럽_영양기준_만족_식품(brandRepository.save(퓨리나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + 식품_기능성_추가(미국_영양기준_만족_식품, functionalityRepository.save(기능성_짱짱())); + 식품_기능성_추가(유럽_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_소고기())); + 식품_주원료_추가(미국_영양기준_만족_식품, primaryIngredientRepository.save(주원료_돼지고기())); + 식품_주원료_추가(유럽_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.saveAll(List.of(모든_영양기준_만족_식품, 미국_영양기준_만족_식품, 유럽_영양기준_만족_식품)); + List allFoods = petFoodRepository.findAll(); Long lastPetFoodId = allFoods.get(allFoods.size() - 1).getId(); @@ -139,11 +129,11 @@ void setUp() { List functionalityList = EMPTY_LIST; // when - List responses = petFoodQueryRepository.findPagingPetFoods(brandsName, standards, primaryIngredientList, - functionalityList, lastPetFoodId, 20); + Long petFoodsCount = petFoodQueryRepository.findPetFoodsCount(brandsName, standards, + primaryIngredientList, functionalityList); // then - assertThat(responses).hasSize(3); + assertThat(petFoodsCount).isEqualTo(3); } } diff --git a/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java b/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java index b369a7838..85798bfb9 100644 --- a/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java +++ b/backend/src/test/java/zipgo/petfood/presentation/PetFoodControllerTest.java @@ -2,19 +2,14 @@ import com.epages.restdocs.apispec.ResourceSnippetDetails; import com.epages.restdocs.apispec.Schema; -import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.restdocs.payload.JsonFieldType; import org.springframework.restdocs.restassured.RestDocumentationFilter; -import zipgo.brand.domain.Brand; import zipgo.brand.domain.repository.BrandRepository; import zipgo.common.acceptance.AcceptanceTest; -import zipgo.petfood.domain.Functionality; -import zipgo.petfood.domain.PetFood; -import zipgo.petfood.domain.PrimaryIngredient; import zipgo.petfood.domain.repository.FunctionalityRepository; import zipgo.petfood.domain.repository.PetFoodRepository; import zipgo.petfood.domain.repository.PrimaryIngredientRepository; @@ -42,8 +37,8 @@ import static zipgo.petfood.domain.fixture.FunctionalityFixture.기능성_다이어트; import static zipgo.petfood.domain.fixture.FunctionalityFixture.기능성_튼튼; import static zipgo.petfood.domain.fixture.PetFoodFixture.모든_영양기준_만족_식품; -import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.식품_기능성_연관관계_매핑; -import static zipgo.petfood.domain.fixture.PetFoodPrimaryIngredientFixture.식품_주원료_연관관계_매핑; +import static zipgo.petfood.domain.fixture.PetFoodFunctionalityFixture.식품_기능성_추가; +import static zipgo.petfood.domain.fixture.PetFoodPrimaryIngredientFixture.식품_주원료_추가; import static zipgo.petfood.domain.fixture.PrimaryIngredientFixture.주원료_닭고기; public class PetFoodControllerTest extends AcceptanceTest { @@ -60,26 +55,6 @@ public class PetFoodControllerTest extends AcceptanceTest { @Autowired private FunctionalityRepository functionalityRepository; - private PetFood 식품; - - @BeforeEach - void setUp() { - Brand 아카나 = brandRepository.save(아카나_식품_브랜드_생성()); - PetFood 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(아카나); - Functionality 기능성_다이어트 = 기능성_다이어트(); - Functionality 기능성_튼튼 = 기능성_튼튼(); - PrimaryIngredient 주원료_닭고기 = 주원료_닭고기(); - - 식품_기능성_연관관계_매핑(모든_영양기준_만족_식품, 기능성_다이어트); - 식품_기능성_연관관계_매핑(모든_영양기준_만족_식품, 기능성_튼튼); - 식품_주원료_연관관계_매핑(모든_영양기준_만족_식품, 주원료_닭고기); - - functionalityRepository.save(기능성_다이어트); - functionalityRepository.save(기능성_튼튼); - primaryIngredientRepository.save(주원료_닭고기); - 식품 = petFoodRepository.save(모든_영양기준_만족_식품); - } - @Nested @DisplayName("식품 전체 조회 API") class GetPetFoods { @@ -91,8 +66,17 @@ class GetPetFoods { .description("식품 전체를 조회합니다."); @Test - void 필터를_지정하지_않고_요청한다() { + void 필터를_지정하지_않고_요청하면_200을_반환한다() { // given + var 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.save(모든_영양기준_만족_식품); + var 요청_준비 = given(spec) .queryParam("size", 20) .filter(성공_API_문서_생성("식품 필터링 없이 조회 - 성공(전체 조회)")); @@ -107,8 +91,17 @@ class GetPetFoods { } @Test - void 필터를_지정해서_요청한다() { + void 필터를_지정해서_요청하면_200을_반환한다() { // given + var 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.save(모든_영양기준_만족_식품); + List 브랜드 = List.of("아카나"); List 영양기준 = List.of("유럽"); List 기능성 = List.of("튼튼"); @@ -164,15 +157,24 @@ class GetPetFood { .description("id에 해당하는 식품 상세정보를 조회합니다."); @Test - void 올바른_요청() { + void 식품_상세를_요청하면_200을_반환한다() { // given + var 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.save(모든_영양기준_만족_식품); + var 요청_준비 = given(spec) .contentType(JSON) .filter(식품_상세_조회_API_문서_생성()); // when var 응답 = 요청_준비.when() - .pathParam("id", 식품.getId()) + .pathParam("id", 모든_영양기준_만족_식품.getId()) .get("/pet-foods/{id}"); // then @@ -180,16 +182,6 @@ class GetPetFood { .assertThat().statusCode(OK.value()); } - private void 주원료_만들기() { - PrimaryIngredient 주원료 = 주원료_닭고기(); - primaryIngredientRepository.save(주원료); - } - - private PetFood 모의_식품_생성() { - Brand 아카나 = brandRepository.save(아카나_식품_브랜드_생성()); - return petFoodRepository.save(모든_영양기준_만족_식품(아카나)); - } - private RestDocumentationFilter 식품_상세_조회_API_문서_생성() { return document("식품 상세 조회 - 성공", 문서_정보.responseSchema(성공_응답_형식), @@ -217,7 +209,7 @@ class GetPetFood { } @Test - void 존재하지_않는_아이디로_요청한다() { + void 존재하지_않는_아이디로_요청하면_404를_반환한다() { //given var 요청_준비 = given(spec) .contentType(JSON) @@ -234,7 +226,7 @@ class GetPetFood { } @Test - void 올바르지_않은_형식의_아이디로_요청한다() { + void 올바르지_않은_형식의_아이디로_요청하면_400을_반환한다() { //given var 요청_준비 = given(spec) .contentType(JSON) @@ -289,7 +281,17 @@ class GetFilterInfo { .description("필터링에 필요한 메타데이터 정보를 조회합니다."); @Test - void 필터링에_필요한_메타데이터를_조회한다() { + void 필터링에_필요한_메타데이터를_조회하면_200을_반환한다() { + // given + var 모든_영양기준_만족_식품 = 모든_영양기준_만족_식품(brandRepository.save(아카나_식품_브랜드_생성())); + + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_다이어트())); + 식품_기능성_추가(모든_영양기준_만족_식품, functionalityRepository.save(기능성_튼튼())); + + 식품_주원료_추가(모든_영양기준_만족_식품, primaryIngredientRepository.save(주원료_닭고기())); + + petFoodRepository.save(모든_영양기준_만족_식품); + // when var 응답 = given(spec) .filter(필터링_메타데이터_API_문서_생성()) diff --git a/backend/src/test/java/zipgo/review/application/ReviewQueryServiceTest.java b/backend/src/test/java/zipgo/review/application/ReviewQueryServiceTest.java index 3888a3d7a..75ff103ee 100644 --- a/backend/src/test/java/zipgo/review/application/ReviewQueryServiceTest.java +++ b/backend/src/test/java/zipgo/review/application/ReviewQueryServiceTest.java @@ -5,7 +5,7 @@ import org.springframework.beans.factory.annotation.Autowired; import zipgo.brand.domain.Brand; import zipgo.brand.domain.repository.BrandRepository; -import zipgo.common.service.QueryServiceTest; +import zipgo.common.service.ServiceTest; import zipgo.member.domain.Member; import zipgo.member.domain.repository.MemberRepository; import zipgo.pet.domain.Breed; @@ -47,7 +47,7 @@ import static zipgo.review.fixture.ReviewFixture.극찬_리뷰_생성; import static zipgo.review.fixture.ReviewFixture.혹평_리뷰_생성; -class ReviewQueryServiceTest extends QueryServiceTest { +class ReviewQueryServiceTest extends ServiceTest { @Autowired private PetFoodRepository petFoodRepository; diff --git a/backend/src/test/java/zipgo/review/domain/repository/ReviewQueryRepositoryImplTest.java b/backend/src/test/java/zipgo/review/domain/repository/ReviewQueryRepositoryImplTest.java index 7f0bccab1..b13d17944 100644 --- a/backend/src/test/java/zipgo/review/domain/repository/ReviewQueryRepositoryImplTest.java +++ b/backend/src/test/java/zipgo/review/domain/repository/ReviewQueryRepositoryImplTest.java @@ -1,21 +1,12 @@ package zipgo.review.domain.repository; -import java.time.LocalDateTime; -import java.time.Year; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.Random; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.Import; import org.springframework.transaction.annotation.Transactional; import zipgo.brand.domain.Brand; import zipgo.brand.domain.repository.BrandRepository; -import zipgo.common.config.QueryDslTestConfig; +import zipgo.common.repository.RepositoryTest; import zipgo.member.domain.Member; import zipgo.member.domain.fixture.MemberFixture; import zipgo.member.domain.repository.MemberRepository; @@ -37,6 +28,13 @@ import zipgo.review.domain.repository.dto.ReviewHelpfulReaction; import zipgo.review.domain.type.AdverseReactionType; +import java.time.LocalDateTime; +import java.time.Year; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Random; + import static java.util.Collections.emptyList; import static java.util.Collections.reverseOrder; import static org.assertj.core.api.Assertions.assertThat; @@ -52,10 +50,7 @@ import static zipgo.review.domain.type.TastePreference.EATS_VERY_WELL; import static zipgo.review.fixture.ReviewFixture.극찬_리뷰_생성; -@Import(QueryDslTestConfig.class) -@DataJpaTest(properties = {"spring.sql.init.mode=never"}) -@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) -class ReviewQueryRepositoryImplTest { +class ReviewQueryRepositoryImplTest extends RepositoryTest { @Autowired private ReviewQueryRepository reviewQueryRepository;