From a507c7a0ca115ccfc7e058f401abd207585d7c88 Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Thu, 12 Dec 2024 23:31:14 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Feat:=20#245=20genti-domain=20=EB=AA=A8?= =?UTF-8?q?=EB=93=88=EC=97=90=EC=84=9C=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20?= =?UTF-8?q?=EC=84=B8=ED=8C=85=20=EB=B0=8F=20responseexample(=EC=82=AC?= =?UTF-8?q?=EC=A7=84=20=EC=83=9D=EC=84=B1=20=EC=98=88=EC=8B=9C)=20?= =?UTF-8?q?=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8(=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EA=B3=84=EC=B8=B5)=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/gt/genti/TestConfiguration.java | 7 + .../ResponseExampleRepositoryTest.java | 125 ++++++++++++++++++ .../src/test/resources/application-test.yaml | 65 +++++++++ 3 files changed, 197 insertions(+) create mode 100644 genti-domain/src/test/java/com/gt/genti/TestConfiguration.java create mode 100644 genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java create mode 100644 genti-domain/src/test/resources/application-test.yaml diff --git a/genti-domain/src/test/java/com/gt/genti/TestConfiguration.java b/genti-domain/src/test/java/com/gt/genti/TestConfiguration.java new file mode 100644 index 00000000..ac117b1f --- /dev/null +++ b/genti-domain/src/test/java/com/gt/genti/TestConfiguration.java @@ -0,0 +1,7 @@ +package com.gt.genti; + +import org.springframework.boot.autoconfigure.SpringBootApplication; + +@SpringBootApplication +public class TestConfiguration { +} \ No newline at end of file diff --git a/genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java b/genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java new file mode 100644 index 00000000..67d173b2 --- /dev/null +++ b/genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java @@ -0,0 +1,125 @@ +package com.gt.genti.responseexample; + + +import com.gt.genti.picture.PictureRatio; +import com.gt.genti.picture.responseexample.model.ResponseExample; +import com.gt.genti.picture.responseexample.repository.ResponseExampleRepository; +import org.assertj.core.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration; +import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; +import org.springframework.context.ApplicationContext; +import org.springframework.test.context.ActiveProfiles; + +import java.util.Arrays; +import java.util.List; + +import static java.lang.Boolean.FALSE; +import static java.lang.Boolean.TRUE; +import static org.assertj.core.api.Assertions.assertThat; + +@DataJpaTest +public class ResponseExampleRepositoryTest { + + @Autowired + ResponseExampleRepository responseExampleRepository; + + private List mockResponseExamples; + +// @Autowired +// private ApplicationContext context; + +// @Test +// @DisplayName("등록된 빈 확인") +// void printLoadedBeans() { +// Arrays.stream(context.getBeanDefinitionNames()).sorted().forEach(System.out::println); +// } + + @BeforeEach + void setUp() { + mockResponseExamples = List.of( // Service 계층과 동일 + createExample("피드뷰 - 예시 프롬프트1", PictureRatio.RATIO_SERO, null, FALSE), // 피드뷰 + createExample("피드뷰 - 예시 프롬프트2", PictureRatio.RATIO_SERO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트3", PictureRatio.RATIO_SERO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트4", PictureRatio.RATIO_SERO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트5", PictureRatio.RATIO_SERO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트6", PictureRatio.RATIO_SERO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트7", PictureRatio.RATIO_SERO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트8", PictureRatio.RATIO_SERO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트9", PictureRatio.RATIO_GARO, null, FALSE), + createExample("피드뷰 - 예시 프롬프트10", PictureRatio.RATIO_GARO, null, FALSE), + createExample("생성뷰(무료) - 예시 프롬프트1", PictureRatio.NONE, "FREE_ONE", TRUE), // 생성뷰(정방형) : 무료 + createExample("생성뷰(무료) - 예시 프롬프트2", PictureRatio.NONE, "FREE_ONE", TRUE), + createExample("생성뷰(무료) - 예시 프롬프트3", PictureRatio.NONE, "FREE_ONE", TRUE), + createExample("생성뷰(무료) - 예시 프롬프트4", PictureRatio.NONE, "FREE_ONE", TRUE), + createExample("생성뷰(무료) - 예시 프롬프트5", PictureRatio.NONE, "FREE_ONE", TRUE), + createExample("생성뷰(무료) - 예시 프롬프트6", PictureRatio.NONE, "FREE_ONE", TRUE), + createExample("생성뷰(무료) - 예시 프롬프트7", PictureRatio.NONE, "FREE_ONE", TRUE), + createExample("생성뷰(유료-1인) - 예시 프롬프트1", PictureRatio.NONE, "PAID_ONE", TRUE), // 생성뷰(정방형) : 유료 + createExample("생성뷰(유료-1인) - 예시 프롬프트2", PictureRatio.NONE, "PAID_ONE", TRUE), + createExample("생성뷰(유료-1인) - 예시 프롬프트3", PictureRatio.NONE, "PAID_ONE", TRUE), + createExample("생성뷰(유료-1인) - 예시 프롬프트4", PictureRatio.NONE, "PAID_ONE", TRUE), + createExample("생성뷰(유료-1인) - 예시 프롬프트5", PictureRatio.NONE, "PAID_ONE", TRUE), + createExample("생성뷰(유료-1인) - 예시 프롬프트6", PictureRatio.NONE, "PAID_ONE", TRUE), + createExample("생성뷰(유료-1인) - 예시 프롬프트7", PictureRatio.NONE, "PAID_ONE", TRUE), + createExample("생성뷰(유료-2인) - 예시 프롬프트1", PictureRatio.NONE, "PAID_TWO", TRUE), + createExample("생성뷰(유료-2인) - 예시 프롬프트2", PictureRatio.NONE, "PAID_TWO", TRUE), + createExample("생성뷰(유료-2인) - 예시 프롬프트3", PictureRatio.NONE, "PAID_TWO", TRUE), + createExample("생성뷰(유료-2인) - 예시 프롬프트4", PictureRatio.NONE, "PAID_TWO", TRUE), + createExample("생성뷰(유료-2인) - 예시 프롬프트5", PictureRatio.NONE, "PAID_TWO", TRUE), + createExample("생성뷰(유료-2인) - 예시 프롬프트6", PictureRatio.NONE, "PAID_TWO", TRUE), + createExample("생성뷰(유료-2인) - 예시 프롬프트7", PictureRatio.NONE, "PAID_TWO", TRUE) + ); + responseExampleRepository.saveAll(mockResponseExamples); + } + + @Test + @DisplayName("피드뷰 - 모든 예시 사진이 promptOnly == false && type == null && pictureRatio != NONE 인지 검증") + void findAllFeedViewMeetsAllConditions_Then_Success() { + //when + List result = responseExampleRepository.findAllByPromptOnlyIsFalse(); + + //then + assertThat(result) + .isNotEmpty() + .allMatch(example -> !example.getPromptOnly()) + .allMatch(example -> example.getType() == null) + .allMatch(example -> + example.getPictureRatio() == PictureRatio.RATIO_GARO || + example.getPictureRatio() == PictureRatio.RATIO_SERO + ); + } + + @Test + @DisplayName("피드뷰 - 조건에 맞는 예시가 없을 때 빈 리스트가 반환되는지 검증") + void findAllFeedViewWhenNoMatchingData_Then_EmptyListReturned() { + //given + responseExampleRepository.deleteAll(); + responseExampleRepository.saveAll(mockResponseExamples.subList(10, mockResponseExamples.size())); + + //when + List result = responseExampleRepository.findAllByPromptOnlyIsFalse(); + + //then + assertThat(result).isEmpty(); + } + + + + + private ResponseExample createExample(String prompt, PictureRatio ratio, String type, Boolean promptOnly) { + return ResponseExample.builder() + .key("/ADMIN_UPLOAD/test.png") + .prompt(prompt) + .pictureRatio(ratio) + .promptOnly(promptOnly) + .type(type) + .build(); + } + + +} diff --git a/genti-domain/src/test/resources/application-test.yaml b/genti-domain/src/test/resources/application-test.yaml new file mode 100644 index 00000000..f4f7cf81 --- /dev/null +++ b/genti-domain/src/test/resources/application-test.yaml @@ -0,0 +1,65 @@ +spring: + h2: + console: + path: /h2-console + enabled: true + settings: + web-allow-others: true + datasource: + url: jdbc:h2:mem:test;MODE=MySQL;DATABASE_TO_UPPER=false;CASE_INSENSITIVE_IDENTIFIERS=true;DB_CLOSE_DELAY=-1 + username: sa + password: + driver-class-name: org.h2.Driver + jpa: + hibernate: + ddl-auto: update + properties: + hibernate: + format_sql: 'true' + use_sql_comments: 'true' + show_sql: 'true' + dialect: org.hibernate.dialect.MySQLDialect +redis: + host: localhost + port: 6379 + +logging: + level: + org: + hibernate: + SQL: DEBUG + type: + descriptor: + sql: + BasicBinder: TRACE + +server: + ip: 127.0.0.1 + domain: localhost + port: 8080 + +management: + endpoints: + web: + base-path: /foflakfm + + +google: + client-id: "client-id" + redirect-url: "redirect-url" + scope: + https://www.googleapis.com/auth/userinfo.email, + https://www.googleapis.com/auth/userinfo.profile, + https://www.googleapis.com/auth/user.birthday.read +kakao: + client-id: "client-id" + redirect-uri: "redirect-uri" + +apple: + client-id: "client-id" + nonce: "nonce" + + +discord: + webhook-url: + error: /1275042855135608833/YDMWPdcQbtN7DHx2rkDGOKuhb6jO-a5scUajn5NT3ND0QdsfhNnj6F3NBycpdWMbF6KG \ No newline at end of file From fb07a9df3571b4ecb4adbf1bec1f728a72031d96 Mon Sep 17 00:00:00 2001 From: LeeJaehyung <540900@naver.com> Date: Mon, 16 Dec 2024 11:17:11 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Feat:=20#245=20responseexample(=EC=82=AC?= =?UTF-8?q?=EC=A7=84=20=EC=83=9D=EC=84=B1=20=EC=98=88=EC=8B=9C)=20?= =?UTF-8?q?=EB=8B=A8=EC=9C=84=20=ED=85=8C=EC=8A=A4=ED=8A=B8(=EB=A6=AC?= =?UTF-8?q?=ED=8F=AC=EC=A7=80=ED=86=A0=EB=A6=AC=20=EA=B3=84=EC=B8=B5)=20?= =?UTF-8?q?=EC=9E=91=EC=84=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../ResponseExampleRepositoryTest.java | 76 ++++++++++++++++--- 1 file changed, 65 insertions(+), 11 deletions(-) diff --git a/genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java b/genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java index 67d173b2..e70bd732 100644 --- a/genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java +++ b/genti-domain/src/test/java/com/gt/genti/responseexample/ResponseExampleRepositoryTest.java @@ -4,6 +4,8 @@ import com.gt.genti.picture.PictureRatio; import com.gt.genti.picture.responseexample.model.ResponseExample; import com.gt.genti.picture.responseexample.repository.ResponseExampleRepository; +import jakarta.persistence.EntityManager; +import jakarta.persistence.PersistenceContext; import org.assertj.core.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; @@ -14,9 +16,12 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.context.ApplicationContext; import org.springframework.test.context.ActiveProfiles; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; import static java.lang.Boolean.FALSE; import static java.lang.Boolean.TRUE; @@ -30,15 +35,6 @@ public class ResponseExampleRepositoryTest { private List mockResponseExamples; -// @Autowired -// private ApplicationContext context; - -// @Test -// @DisplayName("등록된 빈 확인") -// void printLoadedBeans() { -// Arrays.stream(context.getBeanDefinitionNames()).sorted().forEach(System.out::println); -// } - @BeforeEach void setUp() { mockResponseExamples = List.of( // Service 계층과 동일 @@ -94,11 +90,16 @@ void findAllFeedViewMeetsAllConditions_Then_Success() { ); } + @PersistenceContext + private EntityManager entityManager; + @Test @DisplayName("피드뷰 - 조건에 맞는 예시가 없을 때 빈 리스트가 반환되는지 검증") void findAllFeedViewWhenNoMatchingData_Then_EmptyListReturned() { //given responseExampleRepository.deleteAll(); + entityManager.flush(); // DB와 동기화 + entityManager.clear(); // 영속성 컨텍스트 초기화 responseExampleRepository.saveAll(mockResponseExamples.subList(10, mockResponseExamples.size())); //when @@ -108,8 +109,63 @@ void findAllFeedViewWhenNoMatchingData_Then_EmptyListReturned() { assertThat(result).isEmpty(); } + @Test + @DisplayName("생성뷰 - type으로 예시 사진들 검색 검증") + void findAllGenerateViewByType() { + //when + List freeOne = responseExampleRepository.findAllByType("FREE_ONE"); + List paidOne = responseExampleRepository.findAllByType("PAID_ONE"); + List paidTwo = responseExampleRepository.findAllByType("PAID_TWO"); + + //then + assertThat(freeOne) + .isNotNull() + .hasSize(7) + .extracting("type") + .containsOnly("FREE_ONE"); + + assertThat(paidOne) + .isNotNull() + .hasSize(7) + .extracting("type") + .containsOnly("PAID_ONE"); + + assertThat(paidTwo) + .isNotNull() + .hasSize(7) + .extracting("type") + .containsOnly("PAID_TWO"); + } + + @Test + @DisplayName("생성뷰 - 잘못된 type으로 검색 시 빈 리스트가 반환되는지 검증") + void findAllGenerateViewByWrongTypeInput() { + //when + List result = responseExampleRepository.findAllByType("WRONG_INPUT"); + + //then + assertThat(result).isEmpty(); + } + + @Test + @DisplayName("생성뷰 - 조건에 맞는 예시가 없을 때 빈 리스트가 반환되는지 검증") + void findAllGenerateViewByTypeWhenNoMatchingData_Then_EmptyListReturned() { + //given + responseExampleRepository.deleteAll(); + entityManager.flush(); // DB와 동기화 + entityManager.clear(); // 영속성 컨텍스트 초기화 + responseExampleRepository.saveAll(mockResponseExamples.subList(0, 10)); + //when + List freeOne = responseExampleRepository.findAllByType("FREE_ONE"); + List paidOne = responseExampleRepository.findAllByType("PAID_ONE"); + List paidTwo = responseExampleRepository.findAllByType("PAID_TWO"); + //then + assertThat(freeOne).isEmpty(); + assertThat(paidOne).isEmpty(); + assertThat(paidTwo).isEmpty(); + } private ResponseExample createExample(String prompt, PictureRatio ratio, String type, Boolean promptOnly) { return ResponseExample.builder() @@ -120,6 +176,4 @@ private ResponseExample createExample(String prompt, PictureRatio ratio, String .type(type) .build(); } - - }