From 9c225ef19f83dc6f27c5492630a79b40f883f053 Mon Sep 17 00:00:00 2001 From: koseonje <127813439+KoSeonJe@users.noreply.github.com> Date: Fri, 16 Aug 2024 00:34:28 +0900 Subject: [PATCH] =?UTF-8?q?[DEV-32]=20=EB=A1=9C=EC=BB=AC=20db=20mysql=20?= =?UTF-8?q?=EB=B3=80=ED=99=98=20=EB=B0=8F=20TestContainer=20=EC=84=A4?= =?UTF-8?q?=EC=A0=95=20(#75)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle | 38 ++++++---- docker-compose.yml | 17 +++++ src/main/resources/application-local.yml | 15 ++-- src/main/resources/application-test.yml | 9 +-- .../ddingdongBE/common/config/TestConfig.java | 10 +++ .../common/support/DataInitializer.java | 49 +++++++++++++ .../common/support/DataJpaTestSupport.java | 13 ++++ .../common/support/TestContainerSupport.java | 51 +++++++++++++ .../support/WebApiIntegrationTestSupport.java | 24 ++++++ .../support/WebApiUnitTestSupport.java} | 73 +++++++++++-------- .../support/WithMockAuthenticatedUser.java | 2 +- ...thenticatedUserSecurityContextFactory.java | 2 +- ...a => AdminDocumentControllerUnitTest.java} | 6 +- ...t.java => DocumentControllerUnitTest.java} | 6 +- ...a => AdminQuestionControllerUnitTest.java} | 6 +- ...t.java => QuestionControllerUnitTest.java} | 6 +- ... AdminScoreHistoryControllerUnitTest.java} | 6 +- ...> ClubScoreHistoryControllerUnitTest.java} | 6 +- .../user/repository/UserRepositoryTest.java | 5 +- 19 files changed, 259 insertions(+), 85 deletions(-) create mode 100644 docker-compose.yml create mode 100644 src/test/java/ddingdong/ddingdongBE/common/config/TestConfig.java create mode 100644 src/test/java/ddingdong/ddingdongBE/common/support/DataInitializer.java create mode 100644 src/test/java/ddingdong/ddingdongBE/common/support/DataJpaTestSupport.java create mode 100644 src/test/java/ddingdong/ddingdongBE/common/support/TestContainerSupport.java create mode 100644 src/test/java/ddingdong/ddingdongBE/common/support/WebApiIntegrationTestSupport.java rename src/test/java/ddingdong/ddingdongBE/{support/WebApiTestSupport.java => common/support/WebApiUnitTestSupport.java} (56%) rename src/test/java/ddingdong/ddingdongBE/{ => common}/support/WithMockAuthenticatedUser.java (93%) rename src/test/java/ddingdong/ddingdongBE/{ => common}/support/WithMockAuthenticatedUserSecurityContextFactory.java (96%) rename src/test/java/ddingdong/ddingdongBE/domain/documents/controller/{AdminDocumentControllerTest.java => AdminDocumentControllerUnitTest.java} (96%) rename src/test/java/ddingdong/ddingdongBE/domain/documents/controller/{DocumentControllerTest.java => DocumentControllerUnitTest.java} (93%) rename src/test/java/ddingdong/ddingdongBE/domain/question/controller/{AdminQuestionControllerTest.java => AdminQuestionControllerUnitTest.java} (96%) rename src/test/java/ddingdong/ddingdongBE/domain/question/controller/{QuestionControllerTest.java => QuestionControllerUnitTest.java} (90%) rename src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/{AdminScoreHistoryControllerTest.java => AdminScoreHistoryControllerUnitTest.java} (92%) rename src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/{ClubScoreHistoryControllerTest.java => ClubScoreHistoryControllerUnitTest.java} (92%) diff --git a/build.gradle b/build.gradle index e0c82d91..b64448b4 100644 --- a/build.gradle +++ b/build.gradle @@ -26,32 +26,42 @@ repositories { } dependencies { - implementation 'org.springframework.boot:spring-boot-starter-data-jpa' + //develop implementation 'org.springframework.boot:spring-boot-starter-web' - implementation 'org.springframework.boot:spring-boot-starter-security' implementation 'org.springframework.boot:spring-boot-starter-validation' + compileOnly 'org.projectlombok:lombok' + annotationProcessor 'org.projectlombok:lombok' + implementation 'org.springdoc:springdoc-openapi-ui:1.6.11' + implementation 'org.springframework.boot:spring-boot-configuration-processor' - implementation 'io.hypersistence:hypersistence-utils-hibernate-55:3.7.2' - - implementation 'com.auth0:java-jwt:4.2.1' - - implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4' + //db + implementation 'org.springframework.boot:spring-boot-starter-data-jpa' implementation 'com.mysql:mysql-connector-j' + runtimeOnly 'com.h2database:h2' + //etc(기타) + implementation 'io.awspring.cloud:spring-cloud-starter-aws:2.4.4' implementation 'org.apache.poi:poi:5.2.0' implementation 'org.apache.poi:poi-ooxml:5.2.0' - implementation 'org.springframework.boot:spring-boot-configuration-processor' - + implementation 'io.hypersistence:hypersistence-utils-hibernate-55:3.7.2' implementation 'io.sentry:sentry-logback:7.6.0' - implementation 'org.springdoc:springdoc-openapi-ui:1.6.11' - implementation 'com.fasterxml.jackson.core:jackson-core:2.17.0' - compileOnly 'org.projectlombok:lombok' - runtimeOnly 'com.h2database:h2' - annotationProcessor 'org.projectlombok:lombok' + + //security + implementation 'org.springframework.boot:spring-boot-starter-security' + implementation 'com.auth0:java-jwt:4.2.1' + + //test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.springframework.security:spring-security-test' + testCompileOnly 'org.projectlombok:lombok' + testAnnotationProcessor 'org.projectlombok:lombok' + // TestContainer + testImplementation 'org.testcontainers:testcontainers:1.20.0' + testImplementation 'org.testcontainers:junit-jupiter:1.20.0' + // mysql 컨테이너 + testImplementation 'org.testcontainers:mysql:1.20.0' } tasks.named('test') { diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 00000000..e10c549a --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,17 @@ +services: + ddingdong-local-db: + image: mysql:8.0 + container_name: ddingdong_local_mysql + platform: linux/x86_64 + environment: # 환경 변수 설정 + MYSQL_ROOT_PASSWORD: 1234 + MYSQL_DATABASE: ddingdong_local_db + MYSQL_CHARSET: utf8mb4 + MYSQL_COLLATION: utf8mb4_unicode_ci + TZ: Asia/Seoul + ports: + - "3307:3306" + volumes: + - backup-store:/var/lib/mysql +volumes: + backup-store : \ No newline at end of file diff --git a/src/main/resources/application-local.yml b/src/main/resources/application-local.yml index 2eede133..580fd27e 100644 --- a/src/main/resources/application-local.yml +++ b/src/main/resources/application-local.yml @@ -4,24 +4,21 @@ spring: on-profile: local datasource: - url: jdbc:h2:tcp://localhost/~/projects/ddingdong/ddingdong - driver-class-name: org.h2.Driver - username: sa - password: + url: jdbc:mysql://localhost:3307/ddingdong_local_db + driver-class-name: com.mysql.cj.jdbc.Driver + username: root + password: 1234 jpa: hibernate: ddl-auto: create - show-sql: true properties: hibernate: format_sql: true + dialect: org.hibernate.dialect.MySQL8InnoDBDialect + show-sql: true defer-datasource-initialization: true sql: init: mode: always - - h2: - console: - enabled: true diff --git a/src/main/resources/application-test.yml b/src/main/resources/application-test.yml index 246955cb..b2efa1b0 100644 --- a/src/main/resources/application-test.yml +++ b/src/main/resources/application-test.yml @@ -3,20 +3,15 @@ spring: activate: on-profile: test - datasource: - url: jdbc:h2:mem:ddingdongdb; - driver-class-name: org.h2.Driver - username: sa - password: - jpa: hibernate: ddl-auto: create - show-sql: true properties: hibernate: + show-sql: true format_sql: true auto_quote_keyword: true + dialect: org.hibernate.dialect.MySQL8InnoDBDialect sql: init: diff --git a/src/test/java/ddingdong/ddingdongBE/common/config/TestConfig.java b/src/test/java/ddingdong/ddingdongBE/common/config/TestConfig.java new file mode 100644 index 00000000..85380072 --- /dev/null +++ b/src/test/java/ddingdong/ddingdongBE/common/config/TestConfig.java @@ -0,0 +1,10 @@ +package ddingdong.ddingdongBE.common.config; + +import ddingdong.ddingdongBE.common.support.DataInitializer; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.Import; + +@TestConfiguration +@Import(DataInitializer.class) +public class TestConfig { +} diff --git a/src/test/java/ddingdong/ddingdongBE/common/support/DataInitializer.java b/src/test/java/ddingdong/ddingdongBE/common/support/DataInitializer.java new file mode 100644 index 00000000..2ecc1fcd --- /dev/null +++ b/src/test/java/ddingdong/ddingdongBE/common/support/DataInitializer.java @@ -0,0 +1,49 @@ +package ddingdong.ddingdongBE.common.support; + +import javax.persistence.PersistenceContext; +import javax.persistence.Query; +import java.util.ArrayList; +import java.util.List; +import javax.persistence.EntityManager; +import lombok.AccessLevel; +import lombok.NoArgsConstructor; +import org.springframework.context.annotation.Profile; +import org.springframework.stereotype.Component; +import org.springframework.transaction.annotation.Propagation; +import org.springframework.transaction.annotation.Transactional; + +@Profile("test") +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@Component +public class DataInitializer { + + private static final String OFF_FOREIGN_CONSTRAINTS = "SET foreign_key_checks = false"; + private static final String ON_FOREIGN_CONSTRAINTS = "SET foreign_key_checks = true"; + private static final String TRUNCATE_SQL_FORMAT = "TRUNCATE %s"; + + private static final List truncationDMLs = new ArrayList<>(); + + @PersistenceContext + private EntityManager em; + + @Transactional(propagation = Propagation.REQUIRES_NEW) + public void deleteAll() { + if (truncationDMLs.isEmpty()) { + init(); + } + + em.createNativeQuery(OFF_FOREIGN_CONSTRAINTS).executeUpdate(); + truncationDMLs.stream() + .map(em::createNativeQuery) + .forEach(Query::executeUpdate); + em.createNativeQuery(ON_FOREIGN_CONSTRAINTS).executeUpdate(); + } + + private void init() { + final List tableNames = em.createNativeQuery("SHOW TABLES ").getResultList(); + + tableNames.stream() + .map(tableName -> String.format(TRUNCATE_SQL_FORMAT, tableName)) + .forEach(truncationDMLs::add); + } +} diff --git a/src/test/java/ddingdong/ddingdongBE/common/support/DataJpaTestSupport.java b/src/test/java/ddingdong/ddingdongBE/common/support/DataJpaTestSupport.java new file mode 100644 index 00000000..a32f1f22 --- /dev/null +++ b/src/test/java/ddingdong/ddingdongBE/common/support/DataJpaTestSupport.java @@ -0,0 +1,13 @@ +package ddingdong.ddingdongBE.common.support; + +import ddingdong.ddingdongBE.common.config.TestConfig; +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.test.context.ActiveProfiles; +import org.springframework.test.context.TestPropertySource; + +@DataJpaTest +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +public abstract class DataJpaTestSupport extends TestContainerSupport { +} diff --git a/src/test/java/ddingdong/ddingdongBE/common/support/TestContainerSupport.java b/src/test/java/ddingdong/ddingdongBE/common/support/TestContainerSupport.java new file mode 100644 index 00000000..d9fbe8b6 --- /dev/null +++ b/src/test/java/ddingdong/ddingdongBE/common/support/TestContainerSupport.java @@ -0,0 +1,51 @@ +package ddingdong.ddingdongBE.common.support; + + +import static lombok.AccessLevel.PROTECTED; + +import ddingdong.ddingdongBE.common.config.TestConfig; +import lombok.NoArgsConstructor; +import org.junit.jupiter.api.BeforeEach; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.context.annotation.Import; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.DynamicPropertyRegistry; +import org.springframework.test.context.DynamicPropertySource; +import org.testcontainers.containers.JdbcDatabaseContainer; +import org.testcontainers.containers.MySQLContainer; + +@NoArgsConstructor(access = PROTECTED) +@ActiveProfiles("test") +@Import(TestConfig.class) +public abstract class TestContainerSupport { + + private static final String MYSQL_IMAGE = "mysql:8"; + private static final int MYSQL_PORT = 3306; + private static final JdbcDatabaseContainer MYSQL; + + @Autowired + private DataInitializer dataInitializer; + + // 싱글톤 + static { + MYSQL = new MySQLContainer<>(MYSQL_IMAGE) + .withExposedPorts(MYSQL_PORT) + .withReuse(true); + + MYSQL.start(); + } + + // 동적으로 DB 속성 할당 + @DynamicPropertySource + public static void setUp(DynamicPropertyRegistry registry) { + registry.add("spring.datasource.driver-class-name", MYSQL::getDriverClassName); + registry.add("spring.datasource.url", MYSQL::getJdbcUrl); + registry.add("spring.datasource.username", MYSQL::getUsername); + registry.add("spring.datasource.password", MYSQL::getPassword); + } + + @BeforeEach + void delete() { + dataInitializer.deleteAll(); + } +} diff --git a/src/test/java/ddingdong/ddingdongBE/common/support/WebApiIntegrationTestSupport.java b/src/test/java/ddingdong/ddingdongBE/common/support/WebApiIntegrationTestSupport.java new file mode 100644 index 00000000..372cd292 --- /dev/null +++ b/src/test/java/ddingdong/ddingdongBE/common/support/WebApiIntegrationTestSupport.java @@ -0,0 +1,24 @@ +package ddingdong.ddingdongBE.common.support; + +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.web.servlet.MockMvc; + +@SpringBootTest +@AutoConfigureMockMvc +public abstract class WebApiIntegrationTestSupport extends TestContainerSupport { + + @Autowired + protected MockMvc mockMvc; + + @Autowired + protected ObjectMapper objectMapper; + + protected String toJson(Object object) throws JsonProcessingException { + return objectMapper.writeValueAsString(object); + } + +} diff --git a/src/test/java/ddingdong/ddingdongBE/support/WebApiTestSupport.java b/src/test/java/ddingdong/ddingdongBE/common/support/WebApiUnitTestSupport.java similarity index 56% rename from src/test/java/ddingdong/ddingdongBE/support/WebApiTestSupport.java rename to src/test/java/ddingdong/ddingdongBE/common/support/WebApiUnitTestSupport.java index 5dd00fa3..00c70708 100644 --- a/src/test/java/ddingdong/ddingdongBE/support/WebApiTestSupport.java +++ b/src/test/java/ddingdong/ddingdongBE/common/support/WebApiUnitTestSupport.java @@ -1,7 +1,9 @@ -package ddingdong.ddingdongBE.support; +package ddingdong.ddingdongBE.common.support; import static org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.springSecurity; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import ddingdong.ddingdongBE.domain.club.service.ClubService; import ddingdong.ddingdongBE.domain.documents.controller.AdminDocumentController; import ddingdong.ddingdongBE.domain.documents.controller.DocumentController; @@ -25,37 +27,44 @@ @ActiveProfiles("test") @WebMvcTest(controllers = { - AdminDocumentController.class, - DocumentController.class, - AdminQuestionController.class, - QuestionController.class, - AdminScoreHistoryController.class, - ClubScoreHistoryController.class + AdminDocumentController.class, + DocumentController.class, + AdminQuestionController.class, + QuestionController.class, + AdminScoreHistoryController.class, + ClubScoreHistoryController.class }) -public abstract class WebApiTestSupport { - - @Autowired - private WebApplicationContext context; - @Autowired - protected MockMvc mockMvc; - @MockBean - protected DocumentService documentService; - @MockBean - protected FileService fileService; - @MockBean - protected FileInformationService fileInformationService; - @MockBean - protected QuestionService questionService; - @MockBean - protected ClubService clubService; - @MockBean - protected ScoreHistoryService scoreHistoryService; - - @BeforeEach - void setUp() { - mockMvc = MockMvcBuilders.webAppContextSetup(context) - .apply(springSecurity()) - .build(); - } +public abstract class WebApiUnitTestSupport { + + @Autowired + private WebApplicationContext context; + @Autowired + protected MockMvc mockMvc; + @MockBean + protected DocumentService documentService; + @MockBean + protected FileService fileService; + @MockBean + protected FileInformationService fileInformationService; + @MockBean + protected QuestionService questionService; + @MockBean + protected ClubService clubService; + @MockBean + protected ScoreHistoryService scoreHistoryService; + + @Autowired + protected ObjectMapper objectMapper; + + protected String toJson(Object object) throws JsonProcessingException { + return objectMapper.writeValueAsString(object); + } + + @BeforeEach + void setUp() { + mockMvc = MockMvcBuilders.webAppContextSetup(context) + .apply(springSecurity()) + .build(); + } } diff --git a/src/test/java/ddingdong/ddingdongBE/support/WithMockAuthenticatedUser.java b/src/test/java/ddingdong/ddingdongBE/common/support/WithMockAuthenticatedUser.java similarity index 93% rename from src/test/java/ddingdong/ddingdongBE/support/WithMockAuthenticatedUser.java rename to src/test/java/ddingdong/ddingdongBE/common/support/WithMockAuthenticatedUser.java index 908eddfb..244ac6d4 100644 --- a/src/test/java/ddingdong/ddingdongBE/support/WithMockAuthenticatedUser.java +++ b/src/test/java/ddingdong/ddingdongBE/common/support/WithMockAuthenticatedUser.java @@ -1,4 +1,4 @@ -package ddingdong.ddingdongBE.support; +package ddingdong.ddingdongBE.common.support; import java.lang.annotation.Documented; import java.lang.annotation.ElementType; diff --git a/src/test/java/ddingdong/ddingdongBE/support/WithMockAuthenticatedUserSecurityContextFactory.java b/src/test/java/ddingdong/ddingdongBE/common/support/WithMockAuthenticatedUserSecurityContextFactory.java similarity index 96% rename from src/test/java/ddingdong/ddingdongBE/support/WithMockAuthenticatedUserSecurityContextFactory.java rename to src/test/java/ddingdong/ddingdongBE/common/support/WithMockAuthenticatedUserSecurityContextFactory.java index 95bc10d3..2fb64836 100644 --- a/src/test/java/ddingdong/ddingdongBE/support/WithMockAuthenticatedUserSecurityContextFactory.java +++ b/src/test/java/ddingdong/ddingdongBE/common/support/WithMockAuthenticatedUserSecurityContextFactory.java @@ -1,4 +1,4 @@ -package ddingdong.ddingdongBE.support; +package ddingdong.ddingdongBE.common.support; import ddingdong.ddingdongBE.auth.PrincipalDetails; import ddingdong.ddingdongBE.domain.user.entity.Role; diff --git a/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/AdminDocumentControllerTest.java b/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/AdminDocumentControllerUnitTest.java similarity index 96% rename from src/test/java/ddingdong/ddingdongBE/domain/documents/controller/AdminDocumentControllerTest.java rename to src/test/java/ddingdong/ddingdongBE/domain/documents/controller/AdminDocumentControllerUnitTest.java index 5e30000c..0b230bc8 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/AdminDocumentControllerTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/AdminDocumentControllerUnitTest.java @@ -18,8 +18,8 @@ import ddingdong.ddingdongBE.domain.documents.controller.dto.request.ModifyDocumentRequest; import ddingdong.ddingdongBE.domain.documents.entity.Document; import ddingdong.ddingdongBE.file.dto.FileResponse; -import ddingdong.ddingdongBE.support.WebApiTestSupport; -import ddingdong.ddingdongBE.support.WithMockAuthenticatedUser; +import ddingdong.ddingdongBE.common.support.WebApiUnitTestSupport; +import ddingdong.ddingdongBE.common.support.WithMockAuthenticatedUser; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -27,7 +27,7 @@ import org.springframework.http.MediaType; import org.springframework.mock.web.MockMultipartFile; -public class AdminDocumentControllerTest extends WebApiTestSupport { +public class AdminDocumentControllerUnitTest extends WebApiUnitTestSupport { @WithMockAuthenticatedUser(role = "ADMIN") @DisplayName("document 자료 생성 요청을 수행한다.") diff --git a/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/DocumentControllerTest.java b/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/DocumentControllerUnitTest.java similarity index 93% rename from src/test/java/ddingdong/ddingdongBE/domain/documents/controller/DocumentControllerTest.java rename to src/test/java/ddingdong/ddingdongBE/domain/documents/controller/DocumentControllerUnitTest.java index f4c346d6..acb9df82 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/DocumentControllerTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/documents/controller/DocumentControllerUnitTest.java @@ -11,14 +11,14 @@ import ddingdong.ddingdongBE.domain.documents.entity.Document; import ddingdong.ddingdongBE.file.dto.FileResponse; -import ddingdong.ddingdongBE.support.WebApiTestSupport; -import ddingdong.ddingdongBE.support.WithMockAuthenticatedUser; +import ddingdong.ddingdongBE.common.support.WebApiUnitTestSupport; +import ddingdong.ddingdongBE.common.support.WithMockAuthenticatedUser; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -class DocumentControllerTest extends WebApiTestSupport { +class DocumentControllerUnitTest extends WebApiUnitTestSupport { @WithMockAuthenticatedUser diff --git a/src/test/java/ddingdong/ddingdongBE/domain/question/controller/AdminQuestionControllerTest.java b/src/test/java/ddingdong/ddingdongBE/domain/question/controller/AdminQuestionControllerUnitTest.java similarity index 96% rename from src/test/java/ddingdong/ddingdongBE/domain/question/controller/AdminQuestionControllerTest.java rename to src/test/java/ddingdong/ddingdongBE/domain/question/controller/AdminQuestionControllerUnitTest.java index 07c0b6dd..3dfa611b 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/question/controller/AdminQuestionControllerTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/question/controller/AdminQuestionControllerUnitTest.java @@ -17,15 +17,15 @@ import ddingdong.ddingdongBE.domain.question.controller.dto.request.GenerateQuestionRequest; import ddingdong.ddingdongBE.domain.question.controller.dto.request.ModifyQuestionRequest; import ddingdong.ddingdongBE.domain.question.entity.Question; -import ddingdong.ddingdongBE.support.WebApiTestSupport; -import ddingdong.ddingdongBE.support.WithMockAuthenticatedUser; +import ddingdong.ddingdongBE.common.support.WebApiUnitTestSupport; +import ddingdong.ddingdongBE.common.support.WithMockAuthenticatedUser; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.springframework.http.MediaType; -class AdminQuestionControllerTest extends WebApiTestSupport { +class AdminQuestionControllerUnitTest extends WebApiUnitTestSupport { @WithMockAuthenticatedUser(role = "ADMIN") @DisplayName("question 생성 요청을 수행한다.") diff --git a/src/test/java/ddingdong/ddingdongBE/domain/question/controller/QuestionControllerTest.java b/src/test/java/ddingdong/ddingdongBE/domain/question/controller/QuestionControllerUnitTest.java similarity index 90% rename from src/test/java/ddingdong/ddingdongBE/domain/question/controller/QuestionControllerTest.java rename to src/test/java/ddingdong/ddingdongBE/domain/question/controller/QuestionControllerUnitTest.java index 37da2c47..12fd38b7 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/question/controller/QuestionControllerTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/question/controller/QuestionControllerUnitTest.java @@ -9,14 +9,14 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import ddingdong.ddingdongBE.domain.question.entity.Question; -import ddingdong.ddingdongBE.support.WebApiTestSupport; -import ddingdong.ddingdongBE.support.WithMockAuthenticatedUser; +import ddingdong.ddingdongBE.common.support.WebApiUnitTestSupport; +import ddingdong.ddingdongBE.common.support.WithMockAuthenticatedUser; import java.time.LocalDateTime; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -class QuestionControllerTest extends WebApiTestSupport { +class QuestionControllerUnitTest extends WebApiUnitTestSupport { @WithMockAuthenticatedUser @DisplayName("questions 조회 요청을 수행한다.") diff --git a/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/AdminScoreHistoryControllerTest.java b/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/AdminScoreHistoryControllerUnitTest.java similarity index 92% rename from src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/AdminScoreHistoryControllerTest.java rename to src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/AdminScoreHistoryControllerUnitTest.java index d451a7dc..45e2fd1f 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/AdminScoreHistoryControllerTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/AdminScoreHistoryControllerUnitTest.java @@ -14,13 +14,13 @@ import ddingdong.ddingdongBE.domain.club.entity.Club; import ddingdong.ddingdongBE.domain.scorehistory.entity.Score; import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory; -import ddingdong.ddingdongBE.support.WebApiTestSupport; -import ddingdong.ddingdongBE.support.WithMockAuthenticatedUser; +import ddingdong.ddingdongBE.common.support.WebApiUnitTestSupport; +import ddingdong.ddingdongBE.common.support.WithMockAuthenticatedUser; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -class AdminScoreHistoryControllerTest extends WebApiTestSupport { +class AdminScoreHistoryControllerUnitTest extends WebApiUnitTestSupport { @WithMockAuthenticatedUser(role = "ADMIN") @DisplayName("동아리 점수 내역 조회 요청을 수행한다.") diff --git a/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/ClubScoreHistoryControllerTest.java b/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/ClubScoreHistoryControllerUnitTest.java similarity index 92% rename from src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/ClubScoreHistoryControllerTest.java rename to src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/ClubScoreHistoryControllerUnitTest.java index 17f02116..e1c11e26 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/ClubScoreHistoryControllerTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/scorehistory/controller/ClubScoreHistoryControllerUnitTest.java @@ -14,13 +14,13 @@ import ddingdong.ddingdongBE.domain.club.entity.Club; import ddingdong.ddingdongBE.domain.scorehistory.entity.Score; import ddingdong.ddingdongBE.domain.scorehistory.entity.ScoreHistory; -import ddingdong.ddingdongBE.support.WebApiTestSupport; -import ddingdong.ddingdongBE.support.WithMockAuthenticatedUser; +import ddingdong.ddingdongBE.common.support.WebApiUnitTestSupport; +import ddingdong.ddingdongBE.common.support.WithMockAuthenticatedUser; import java.util.List; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -class ClubScoreHistoryControllerTest extends WebApiTestSupport { +class ClubScoreHistoryControllerUnitTest extends WebApiUnitTestSupport { @WithMockAuthenticatedUser(role = "CLUB") @DisplayName("동아리- 내 점수 내역 조회 요청을 수행한다.") diff --git a/src/test/java/ddingdong/ddingdongBE/domain/user/repository/UserRepositoryTest.java b/src/test/java/ddingdong/ddingdongBE/domain/user/repository/UserRepositoryTest.java index 97c6b4bd..19ed64eb 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/user/repository/UserRepositoryTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/user/repository/UserRepositoryTest.java @@ -3,6 +3,7 @@ import static ddingdong.ddingdongBE.domain.user.entity.Role.*; import static org.assertj.core.api.Assertions.*; +import ddingdong.ddingdongBE.common.support.DataJpaTestSupport; import ddingdong.ddingdongBE.domain.user.entity.User; import java.util.List; import org.junit.jupiter.api.DisplayName; @@ -11,9 +12,7 @@ import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; import org.springframework.test.context.ActiveProfiles; -@ActiveProfiles("test") -@DataJpaTest -class UserRepositoryTest { +class UserRepositoryTest extends DataJpaTestSupport { @Autowired private UserRepository userRepository;