From 8df4ccf9b1a8aedc6db7c3493f34f2fd9ef5c944 Mon Sep 17 00:00:00 2001 From: haeyonghahn Date: Sat, 27 Jan 2024 19:40:46 +0900 Subject: [PATCH 1/2] =?UTF-8?q?Text:=20=EB=A9=A4=EB=B2=84=20=ED=85=8C?= =?UTF-8?q?=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit member 조회, member 생성 테스트 추가 및 mockito 라이브러리 추가 --- build.gradle | 5 +-- .../gooding/oauth/command/domain/OAuthId.java | 4 ++ .../application/CreateMemberService.java | 4 +- .../gooding/user/command/domain/Member.java | 12 ++++- .../gooding/user/query/dto/MemberData.java | 3 ++ .../application/CreateMemberServiceTest.java | 36 +++++++++++++++ .../user/fixture/MemberDataFixture.java | 13 ++++++ .../gooding/user/fixture/MemberFixture.java | 20 +++++++++ .../application/MemberQueryServiceTest.java | 45 +++++++++++++++++++ .../query/dao}/MemberDataDaoTest.java | 4 +- 10 files changed, 137 insertions(+), 9 deletions(-) create mode 100644 src/test/java/com/dnd/gooding/user/command/application/CreateMemberServiceTest.java create mode 100644 src/test/java/com/dnd/gooding/user/fixture/MemberDataFixture.java create mode 100644 src/test/java/com/dnd/gooding/user/fixture/MemberFixture.java create mode 100644 src/test/java/com/dnd/gooding/user/query/application/MemberQueryServiceTest.java rename src/test/java/com/dnd/gooding/{member/query => user/query/dao}/MemberDataDaoTest.java (89%) diff --git a/build.gradle b/build.gradle index 5c3c341..86abdc0 100644 --- a/build.gradle +++ b/build.gradle @@ -57,9 +57,8 @@ dependencies { implementation 'io.jsonwebtoken:jjwt-impl:0.11.5' implementation 'io.jsonwebtoken:jjwt-jackson:0.11.5' // Test - testImplementation('org.springframework.boot:spring-boot-starter-test') { - exclude group: 'org.junit.vintage', module: 'junit-vintage-engine' - } + testImplementation 'org.springframework.boot:spring-boot-starter-test' + testImplementation 'org.mockito:mockito-core:3.+' testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' } diff --git a/src/main/java/com/dnd/gooding/oauth/command/domain/OAuthId.java b/src/main/java/com/dnd/gooding/oauth/command/domain/OAuthId.java index f5d153a..29c0103 100644 --- a/src/main/java/com/dnd/gooding/oauth/command/domain/OAuthId.java +++ b/src/main/java/com/dnd/gooding/oauth/command/domain/OAuthId.java @@ -23,6 +23,10 @@ public String getId() { return id; } + public static OAuthId of(String id) { + return new OAuthId(id); + } + @Override public boolean equals(Object o) { if (this == o) diff --git a/src/main/java/com/dnd/gooding/user/command/application/CreateMemberService.java b/src/main/java/com/dnd/gooding/user/command/application/CreateMemberService.java index 5bae6dc..27451b4 100644 --- a/src/main/java/com/dnd/gooding/user/command/application/CreateMemberService.java +++ b/src/main/java/com/dnd/gooding/user/command/application/CreateMemberService.java @@ -12,7 +12,7 @@ @Service public class CreateMemberService { - public MemberRepository memberRepository; + private MemberRepository memberRepository; public CreateMemberService(MemberRepository memberRepository) { this.memberRepository = memberRepository; @@ -21,7 +21,7 @@ public CreateMemberService(MemberRepository memberRepository) { public void createMember(String id, String oAuthId) { MemberId memberId = MemberId.of(id); Member member = new Member(memberId, null, null, null, - UserRole.ROLE_USER.name(), new OAuthId(oAuthId)); + UserRole.ROLE_USER.name(), new OAuthId(oAuthId)); save(member); } diff --git a/src/main/java/com/dnd/gooding/user/command/domain/Member.java b/src/main/java/com/dnd/gooding/user/command/domain/Member.java index 69953dd..6b43b79 100644 --- a/src/main/java/com/dnd/gooding/user/command/domain/Member.java +++ b/src/main/java/com/dnd/gooding/user/command/domain/Member.java @@ -3,7 +3,14 @@ import java.util.Random; import java.util.Set; -import javax.persistence.*; +import javax.persistence.Access; +import javax.persistence.AccessType; +import javax.persistence.Column; +import javax.persistence.Convert; +import javax.persistence.Embedded; +import javax.persistence.EmbeddedId; +import javax.persistence.Entity; +import javax.persistence.Table; import com.dnd.gooding.common.jpa.EmailSetConverter; import com.dnd.gooding.common.jpa.InterestConverter; @@ -13,6 +20,8 @@ import com.dnd.gooding.common.model.InterestSet; import com.dnd.gooding.oauth.command.domain.OAuthId; +import lombok.Builder; + @Entity @Table(name = "member") @Access(AccessType.FIELD) @@ -35,6 +44,7 @@ public class Member { protected Member() { } + @Builder public Member(MemberId id, String name, EmailSet emails, InterestSet interests, String userRole, OAuthId oAuthId) { this.id = id; diff --git a/src/main/java/com/dnd/gooding/user/query/dto/MemberData.java b/src/main/java/com/dnd/gooding/user/query/dto/MemberData.java index 85e85d2..c16686d 100644 --- a/src/main/java/com/dnd/gooding/user/query/dto/MemberData.java +++ b/src/main/java/com/dnd/gooding/user/query/dto/MemberData.java @@ -22,6 +22,8 @@ import com.dnd.gooding.common.model.InterestSet; import com.fasterxml.jackson.annotation.JsonIgnore; +import lombok.Builder; + @Entity @Immutable @Table(name = "member") @@ -67,6 +69,7 @@ public class MemberData { protected MemberData() { } + @Builder public MemberData(String id, String name) { this.id = id; this.name = name; diff --git a/src/test/java/com/dnd/gooding/user/command/application/CreateMemberServiceTest.java b/src/test/java/com/dnd/gooding/user/command/application/CreateMemberServiceTest.java new file mode 100644 index 0000000..2710cd3 --- /dev/null +++ b/src/test/java/com/dnd/gooding/user/command/application/CreateMemberServiceTest.java @@ -0,0 +1,36 @@ +package com.dnd.gooding.user.command.application; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import com.dnd.gooding.user.command.domain.MemberRepository; + +public class CreateMemberServiceTest { + + private MemberRepository memberRepository; + private CreateMemberService createMemberService; + + @BeforeEach + public void beforeEach() { + memberRepository = Mockito.mock(MemberRepository.class); + createMemberService = new CreateMemberService(memberRepository); + } + + @DisplayName("멤버를 생성한다.") + @Test + public void createMember() { + // given + String id = "youg1322@naver.com"; + String oAuthId = "12356"; + + // when + createMemberService.createMember(id, oAuthId); + + // then + Mockito.verify(memberRepository, Mockito.times(1)).findById(Mockito.any()); + Mockito.verify(memberRepository, Mockito.times(1)).save(Mockito.any()); + + } +} diff --git a/src/test/java/com/dnd/gooding/user/fixture/MemberDataFixture.java b/src/test/java/com/dnd/gooding/user/fixture/MemberDataFixture.java new file mode 100644 index 0000000..134f09c --- /dev/null +++ b/src/test/java/com/dnd/gooding/user/fixture/MemberDataFixture.java @@ -0,0 +1,13 @@ +package com.dnd.gooding.user.fixture; + +import com.dnd.gooding.user.query.dto.MemberData; + +public class MemberDataFixture { + + public static MemberData getMember() { + return MemberData.builder() + .id("youg1322@naver.com") + .name("haeyong") + .build(); + } +} diff --git a/src/test/java/com/dnd/gooding/user/fixture/MemberFixture.java b/src/test/java/com/dnd/gooding/user/fixture/MemberFixture.java new file mode 100644 index 0000000..7354163 --- /dev/null +++ b/src/test/java/com/dnd/gooding/user/fixture/MemberFixture.java @@ -0,0 +1,20 @@ +package com.dnd.gooding.user.fixture; + +import com.dnd.gooding.common.model.UserRole; +import com.dnd.gooding.oauth.command.domain.OAuthId; +import com.dnd.gooding.user.command.domain.Member; +import com.dnd.gooding.user.command.domain.MemberId; + +public class MemberFixture { + + public static Member create() { + return Member.builder() + .id(MemberId.of("youg1322@naver.com")) + .name(null) + .emails(null) + .interests(null) + .userRole(UserRole.ROLE_USER.name()) + .oAuthId(OAuthId.of("12356")) + .build(); + } +} diff --git a/src/test/java/com/dnd/gooding/user/query/application/MemberQueryServiceTest.java b/src/test/java/com/dnd/gooding/user/query/application/MemberQueryServiceTest.java new file mode 100644 index 0000000..4f78163 --- /dev/null +++ b/src/test/java/com/dnd/gooding/user/query/application/MemberQueryServiceTest.java @@ -0,0 +1,45 @@ +package com.dnd.gooding.user.query.application; + +import java.util.Optional; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; + +import com.dnd.gooding.user.fixture.MemberDataFixture; +import com.dnd.gooding.user.query.dao.MemberDataDao; +import com.dnd.gooding.user.query.dto.MemberData; + +public class MemberQueryServiceTest { + + private MemberDataDao memberDataDao; + private MemberQueryService memberQueryService; + + @BeforeEach + public void beforeEach() { + memberDataDao = Mockito.mock(MemberDataDao.class); + memberQueryService = new MemberQueryService(memberDataDao); + } + + @DisplayName("멤버 ID로 멤버 정보를 가져온다.") + @Test + public void getMember() { + // given + String id = "youg1322@naver.com"; + + MemberData expectMemberData = MemberDataFixture.getMember(); + + Mockito.when(memberDataDao.findById(id)).thenReturn( + Optional.of(expectMemberData) + ); + + // when + MemberData memberData = memberQueryService.getMember(id); + + // then + Assertions.assertEquals(expectMemberData.getId(), memberData.getId()); + Assertions.assertEquals(expectMemberData.getName(), memberData.getName()); + } +} diff --git a/src/test/java/com/dnd/gooding/member/query/MemberDataDaoTest.java b/src/test/java/com/dnd/gooding/user/query/dao/MemberDataDaoTest.java similarity index 89% rename from src/test/java/com/dnd/gooding/member/query/MemberDataDaoTest.java rename to src/test/java/com/dnd/gooding/user/query/dao/MemberDataDaoTest.java index 15cb641..391d6c4 100644 --- a/src/test/java/com/dnd/gooding/member/query/MemberDataDaoTest.java +++ b/src/test/java/com/dnd/gooding/user/query/dao/MemberDataDaoTest.java @@ -1,4 +1,4 @@ -package com.dnd.gooding.member.query; +package com.dnd.gooding.user.query.dao; import java.util.List; @@ -12,8 +12,6 @@ import org.springframework.test.context.jdbc.Sql; import com.dnd.gooding.user.command.application.NoMemberException; -import com.dnd.gooding.user.query.dao.MemberDataDao; -import com.dnd.gooding.user.query.dao.MemberDataSpecs; import com.dnd.gooding.user.query.dto.MemberData; @SpringBootTest From d9787f1d746a504f564d8069b1f5caa7b51743e2 Mon Sep 17 00:00:00 2001 From: haeyonghahn Date: Sun, 28 Jan 2024 22:28:39 +0900 Subject: [PATCH 2/2] =?UTF-8?q?Test:=20flyway=20=EB=B0=8F=20=ED=86=B5?= =?UTF-8?q?=ED=95=A9=20=ED=85=8C=EC=8A=A4=ED=8A=B8=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 5 +- build.gradle | 1 + db/flyway.conf | 9 +++ db/migration/V0__init.sql | 43 ++++++++++++++ infra/local/docker-compose.yml | 23 ++++++++ infra/test/docker-compose.yml | 21 +++++++ src/main/resources/application.yml | 2 +- src/main/sql/init.sql | 8 --- .../{user => }/fixture/MemberDataFixture.java | 2 +- .../{user => }/fixture/MemberFixture.java | 2 +- .../integration/GoodingApplicationTest.java | 10 ++++ .../gooding/integration/IntegrationTest.java | 59 +++++++++++++++++++ .../MemberQueryServiceIntegrationTest.java | 4 ++ .../record/query/RecordDataDaoTest.java | 33 ----------- .../unit/record/query/RecordDataDaoTest.java | 37 ++++++++++++ .../application/CreateMemberServiceTest.java | 3 +- .../application/MemberQueryServiceTest.java | 5 +- .../user/query/dao/MemberDataDaoTest.java | 4 +- 18 files changed, 222 insertions(+), 49 deletions(-) create mode 100644 db/flyway.conf create mode 100644 db/migration/V0__init.sql create mode 100644 infra/local/docker-compose.yml create mode 100644 infra/test/docker-compose.yml delete mode 100644 src/main/sql/init.sql rename src/test/java/com/dnd/gooding/{user => }/fixture/MemberDataFixture.java (85%) rename src/test/java/com/dnd/gooding/{user => }/fixture/MemberFixture.java (92%) create mode 100644 src/test/java/com/dnd/gooding/integration/GoodingApplicationTest.java create mode 100644 src/test/java/com/dnd/gooding/integration/IntegrationTest.java create mode 100644 src/test/java/com/dnd/gooding/integration/user/query/MemberQueryServiceIntegrationTest.java delete mode 100644 src/test/java/com/dnd/gooding/record/query/RecordDataDaoTest.java create mode 100644 src/test/java/com/dnd/gooding/unit/record/query/RecordDataDaoTest.java rename src/test/java/com/dnd/gooding/{ => unit}/user/command/application/CreateMemberServiceTest.java (87%) rename src/test/java/com/dnd/gooding/{ => unit}/user/query/application/MemberQueryServiceTest.java (87%) rename src/test/java/com/dnd/gooding/{ => unit}/user/query/dao/MemberDataDaoTest.java (88%) diff --git a/.gitignore b/.gitignore index e8c88ed..54ae706 100644 --- a/.gitignore +++ b/.gitignore @@ -35,4 +35,7 @@ out/ /.nb-gradle/ ### VS Code ### -.vscode/ \ No newline at end of file +.vscode/ + +### local environment ### +infra/local/dbdata \ No newline at end of file diff --git a/build.gradle b/build.gradle index 86abdc0..1609629 100644 --- a/build.gradle +++ b/build.gradle @@ -59,6 +59,7 @@ dependencies { // Test testImplementation 'org.springframework.boot:spring-boot-starter-test' testImplementation 'org.mockito:mockito-core:3.+' + testImplementation "org.testcontainers:testcontainers:1.19.0" testCompileOnly 'org.projectlombok:lombok' testAnnotationProcessor 'org.projectlombok:lombok' } diff --git a/db/flyway.conf b/db/flyway.conf new file mode 100644 index 0000000..786d179 --- /dev/null +++ b/db/flyway.conf @@ -0,0 +1,9 @@ +flyway.url=${FLYWAY_DB_URL} +flyway.user=${FLYWAY_DB_USER} +flyway.password=${FLYWAY_DB_PASSWORD} + +flyway.encoding=UTF-8 +flyway.outOfOrder=true +flyway.validateOnMigrate=true +flyway.connectRetries=60 +flyway.connectRetriesInterval=5 \ No newline at end of file diff --git a/db/migration/V0__init.sql b/db/migration/V0__init.sql new file mode 100644 index 0000000..76cd1c9 --- /dev/null +++ b/db/migration/V0__init.sql @@ -0,0 +1,43 @@ +CREATE TABLE IF NOT EXISTS `member` ( + `member_id` varchar(255) NOT NULL, + `emails` varchar(255) DEFAULT NULL, + `interests` varchar(255) DEFAULT NULL, + `name` varchar(255) DEFAULT NULL, + `oauth_id` varchar(255) DEFAULT NULL, + `password` varchar(255) DEFAULT NULL, + `user_role` varchar(255) DEFAULT NULL, + PRIMARY KEY (`member_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `oauth` ( + `oauth_id` varchar(255) NOT NULL, + `email` varchar(255) DEFAULT NULL, + `image_url` varchar(255) DEFAULT NULL, + `provider` varchar(255) DEFAULT NULL, + PRIMARY KEY (`oauth_id`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `record` ( + `record_number` varchar(255) NOT NULL, + `place_latitude` double DEFAULT NULL, + `place_longitude` double DEFAULT NULL, + `place_title` varchar(255) DEFAULT NULL, + `description` varchar(255) DEFAULT NULL, + `record_date` datetime(6) DEFAULT NULL, + `record_score` bigint(20) DEFAULT NULL, + `recorder_id` varchar(255) DEFAULT NULL, + `recorder_name` varchar(255) DEFAULT NULL, + `state` varchar(255) DEFAULT NULL, + `title` varchar(255) DEFAULT NULL, + PRIMARY KEY (`record_number`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; + +CREATE TABLE IF NOT EXISTS `image` ( + `image_id` bigint(20) NOT NULL AUTO_INCREMENT, + `image_path` varchar(255) DEFAULT NULL, + `upload_time` datetime(6) DEFAULT NULL, + `record_number` varchar(255) DEFAULT NULL, + `list_idx` int(11) DEFAULT NULL, + PRIMARY KEY (`image_id`), + FOREIGN KEY (`record_number`) REFERENCES `record` (`record_number`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; \ No newline at end of file diff --git a/infra/local/docker-compose.yml b/infra/local/docker-compose.yml new file mode 100644 index 0000000..beae317 --- /dev/null +++ b/infra/local/docker-compose.yml @@ -0,0 +1,23 @@ +version: "3.8" + +services: + local-db: + image: mysql:8.0 + environment: + MYSQL_DATABASE: gooding + MYSQL_ROOT_PASSWORD: test1357 + ports: + - 3306:3306 + volumes: + - ./dbdata:/var/lib/mysql + local-db-migrate: + image: flyway/flyway:7 + restart: always + environment: + - FLYWAY_DB_URL=jdbc:mysql://local-db/gooding + - FLYWAY_DB_USER=root + - FLYWAY_DB_PASSWORD=test1357 + command: migrate + volumes: + - ../../db/flyway.conf:/flyway/conf/flyway.conf + - ../../db/migration:/flyway/sql \ No newline at end of file diff --git a/infra/test/docker-compose.yml b/infra/test/docker-compose.yml new file mode 100644 index 0000000..f85521f --- /dev/null +++ b/infra/test/docker-compose.yml @@ -0,0 +1,21 @@ +version: "3.8" + +services: + local-db: + image: mysql:8.0 + environment: + MYSQL_DATABASE: gooding + MYSQL_ROOT_PASSWORD: test1357 + ports: + - 3306 + local-db-migrate: + image: flyway/flyway:7 + restart: always + environment: + - FLYWAY_DB_URL=jdbc:mysql://local-db/gooding + - FLYWAY_DB_USER=root + - FLYWAY_DB_PASSWORD=test1357 + command: migrate + volumes: + - ../../db/flyway.conf:/flyway/conf/flyway.conf + - ../../db/migration:/flyway/sql \ No newline at end of file diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml index b5c4514..73b8590 100644 --- a/src/main/resources/application.yml +++ b/src/main/resources/application.yml @@ -22,7 +22,7 @@ spring: database: mysql database-platform: org.hibernate.dialect.MySQL8Dialect hibernate: - ddl-auto: create + ddl-auto: none properties: hibernate: format_sql: true diff --git a/src/main/sql/init.sql b/src/main/sql/init.sql deleted file mode 100644 index 7da565b..0000000 --- a/src/main/sql/init.sql +++ /dev/null @@ -1,8 +0,0 @@ -truncate table member; - -insert into member (member_id, emails, interests, name, oauth_id, password, user_role) - values ('yonog7317', 'yong80211@gmail.com,youg1322@naver.com','1,2,3','hahn', '', '', 'ROLE_USER'); -insert into member (member_id, emails, interests, name, oauth_id, password, user_role) - values ('kim1322', 'yong80211@gmail.com','4,5,6','kim', '', '', 'ROLE_USER'); -insert into member (member_id, emails, interests, name, oauth_id, password, user_role) - values ('son7', 'yong80211@gmail.com','4,5,6','son', '', '', 'ROLE_USER'); \ No newline at end of file diff --git a/src/test/java/com/dnd/gooding/user/fixture/MemberDataFixture.java b/src/test/java/com/dnd/gooding/fixture/MemberDataFixture.java similarity index 85% rename from src/test/java/com/dnd/gooding/user/fixture/MemberDataFixture.java rename to src/test/java/com/dnd/gooding/fixture/MemberDataFixture.java index 134f09c..2c83769 100644 --- a/src/test/java/com/dnd/gooding/user/fixture/MemberDataFixture.java +++ b/src/test/java/com/dnd/gooding/fixture/MemberDataFixture.java @@ -1,4 +1,4 @@ -package com.dnd.gooding.user.fixture; +package com.dnd.gooding.fixture; import com.dnd.gooding.user.query.dto.MemberData; diff --git a/src/test/java/com/dnd/gooding/user/fixture/MemberFixture.java b/src/test/java/com/dnd/gooding/fixture/MemberFixture.java similarity index 92% rename from src/test/java/com/dnd/gooding/user/fixture/MemberFixture.java rename to src/test/java/com/dnd/gooding/fixture/MemberFixture.java index 7354163..ab6fac5 100644 --- a/src/test/java/com/dnd/gooding/user/fixture/MemberFixture.java +++ b/src/test/java/com/dnd/gooding/fixture/MemberFixture.java @@ -1,4 +1,4 @@ -package com.dnd.gooding.user.fixture; +package com.dnd.gooding.fixture; import com.dnd.gooding.common.model.UserRole; import com.dnd.gooding.oauth.command.domain.OAuthId; diff --git a/src/test/java/com/dnd/gooding/integration/GoodingApplicationTest.java b/src/test/java/com/dnd/gooding/integration/GoodingApplicationTest.java new file mode 100644 index 0000000..a136945 --- /dev/null +++ b/src/test/java/com/dnd/gooding/integration/GoodingApplicationTest.java @@ -0,0 +1,10 @@ +package com.dnd.gooding.integration; + +import org.junit.jupiter.api.Test; + +public class GoodingApplicationTest extends IntegrationTest { + + @Test + void contextLoads() { + } +} diff --git a/src/test/java/com/dnd/gooding/integration/IntegrationTest.java b/src/test/java/com/dnd/gooding/integration/IntegrationTest.java new file mode 100644 index 0000000..5c7f06f --- /dev/null +++ b/src/test/java/com/dnd/gooding/integration/IntegrationTest.java @@ -0,0 +1,59 @@ +package com.dnd.gooding.integration; + +import java.io.File; +import java.time.Duration; +import java.util.HashMap; +import java.util.Map; + +import org.junit.Ignore; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.util.TestPropertyValues; +import org.springframework.context.ApplicationContextInitializer; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.transaction.annotation.Transactional; +import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.wait.strategy.Wait; + +@Ignore +@Transactional +@SpringBootTest +@ContextConfiguration(initializers = IntegrationTest.IntegrationTestInitializer.class) +public class IntegrationTest { + + static DockerComposeContainer rdbms; + + static { + rdbms = new DockerComposeContainer(new File("infra/test/docker-compose.yml")) + .withExposedService( + "local-db", + 3306, + Wait.forLogMessage(".*ready for connections.*", 1) + .withStartupTimeout(Duration.ofSeconds(300)) + ) + .withExposedService( + "local-db-migrate", + 0, + Wait.forLogMessage("(.*Successfully applied.*)|(.*Successfully validated.*)", 1) + .withStartupTimeout(Duration.ofSeconds(300)) + ); + + rdbms.start(); + } + + static class IntegrationTestInitializer implements ApplicationContextInitializer { + + @Override + public void initialize(ConfigurableApplicationContext applicationContext) { + Map properties = new HashMap<>(); + String rdbmsHost = rdbms.getServiceHost("local-db", 3306); + Integer rdbmsPort = rdbms.getServicePort("local-db", 3306); + + properties.put("spring.datasource.url", + "jdbc:mysql://" + rdbmsHost + ":" + rdbmsPort + "+/gooding?serverTimezone=Asia/Seoul"); + + TestPropertyValues.of(properties) + .applyTo(applicationContext); + } + } +} diff --git a/src/test/java/com/dnd/gooding/integration/user/query/MemberQueryServiceIntegrationTest.java b/src/test/java/com/dnd/gooding/integration/user/query/MemberQueryServiceIntegrationTest.java new file mode 100644 index 0000000..4099941 --- /dev/null +++ b/src/test/java/com/dnd/gooding/integration/user/query/MemberQueryServiceIntegrationTest.java @@ -0,0 +1,4 @@ +package com.dnd.gooding.integration.user.query; + +public class MemberQueryServiceIntegrationTest { +} diff --git a/src/test/java/com/dnd/gooding/record/query/RecordDataDaoTest.java b/src/test/java/com/dnd/gooding/record/query/RecordDataDaoTest.java deleted file mode 100644 index f0a6001..0000000 --- a/src/test/java/com/dnd/gooding/record/query/RecordDataDaoTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.dnd.gooding.record.query; - -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.data.jpa.domain.Specification; -import org.springframework.test.context.jdbc.Sql; - -import java.util.List; - -@SpringBootTest -@Sql("classpath:init-test.sql") -public class RecordDataDaoTest { - - private Logger logger = LoggerFactory.getLogger(getClass()); - @Autowired - private RecordDataDao recordDataDao; - - @Test - void findById() { - RecordData result = recordDataDao.findById("record1"); - logger.info("spec result: {}, {}", result.getRecordNumber(), result.getRecorderId()); - } - - @Test - void findAll() { - Specification spec = RecordDataSpecs.equalsRecorderId("yong7317"); - List result = recordDataDao.findAll(spec); - logger.info("spec result: {}", result.size()); - } -} diff --git a/src/test/java/com/dnd/gooding/unit/record/query/RecordDataDaoTest.java b/src/test/java/com/dnd/gooding/unit/record/query/RecordDataDaoTest.java new file mode 100644 index 0000000..896771c --- /dev/null +++ b/src/test/java/com/dnd/gooding/unit/record/query/RecordDataDaoTest.java @@ -0,0 +1,37 @@ +package com.dnd.gooding.unit.record.query; + +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.data.jpa.domain.Specification; +import org.springframework.test.context.jdbc.Sql; + +import com.dnd.gooding.record.query.RecordData; +import com.dnd.gooding.record.query.RecordDataDao; +import com.dnd.gooding.record.query.RecordDataSpecs; + +@SpringBootTest +@Sql("classpath:init-test.sql") +public class RecordDataDaoTest { + + private Logger logger = LoggerFactory.getLogger(getClass()); + @Autowired + private RecordDataDao recordDataDao; + + @Test + void findById() { + RecordData result = recordDataDao.findById("record1"); + logger.info("spec result: {}, {}", result.getRecordNumber(), result.getRecorderId()); + } + + @Test + void findAll() { + Specification spec = RecordDataSpecs.equalsRecorderId("yong7317"); + List result = recordDataDao.findAll(spec); + logger.info("spec result: {}", result.size()); + } +} diff --git a/src/test/java/com/dnd/gooding/user/command/application/CreateMemberServiceTest.java b/src/test/java/com/dnd/gooding/unit/user/command/application/CreateMemberServiceTest.java similarity index 87% rename from src/test/java/com/dnd/gooding/user/command/application/CreateMemberServiceTest.java rename to src/test/java/com/dnd/gooding/unit/user/command/application/CreateMemberServiceTest.java index 2710cd3..34516c2 100644 --- a/src/test/java/com/dnd/gooding/user/command/application/CreateMemberServiceTest.java +++ b/src/test/java/com/dnd/gooding/unit/user/command/application/CreateMemberServiceTest.java @@ -1,10 +1,11 @@ -package com.dnd.gooding.user.command.application; +package com.dnd.gooding.unit.user.command.application; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.mockito.Mockito; +import com.dnd.gooding.user.command.application.CreateMemberService; import com.dnd.gooding.user.command.domain.MemberRepository; public class CreateMemberServiceTest { diff --git a/src/test/java/com/dnd/gooding/user/query/application/MemberQueryServiceTest.java b/src/test/java/com/dnd/gooding/unit/user/query/application/MemberQueryServiceTest.java similarity index 87% rename from src/test/java/com/dnd/gooding/user/query/application/MemberQueryServiceTest.java rename to src/test/java/com/dnd/gooding/unit/user/query/application/MemberQueryServiceTest.java index 4f78163..3eb4648 100644 --- a/src/test/java/com/dnd/gooding/user/query/application/MemberQueryServiceTest.java +++ b/src/test/java/com/dnd/gooding/unit/user/query/application/MemberQueryServiceTest.java @@ -1,4 +1,4 @@ -package com.dnd.gooding.user.query.application; +package com.dnd.gooding.unit.user.query.application; import java.util.Optional; @@ -8,7 +8,8 @@ import org.junit.jupiter.api.Test; import org.mockito.Mockito; -import com.dnd.gooding.user.fixture.MemberDataFixture; +import com.dnd.gooding.fixture.MemberDataFixture; +import com.dnd.gooding.user.query.application.MemberQueryService; import com.dnd.gooding.user.query.dao.MemberDataDao; import com.dnd.gooding.user.query.dto.MemberData; diff --git a/src/test/java/com/dnd/gooding/user/query/dao/MemberDataDaoTest.java b/src/test/java/com/dnd/gooding/unit/user/query/dao/MemberDataDaoTest.java similarity index 88% rename from src/test/java/com/dnd/gooding/user/query/dao/MemberDataDaoTest.java rename to src/test/java/com/dnd/gooding/unit/user/query/dao/MemberDataDaoTest.java index 391d6c4..2c7b4be 100644 --- a/src/test/java/com/dnd/gooding/user/query/dao/MemberDataDaoTest.java +++ b/src/test/java/com/dnd/gooding/unit/user/query/dao/MemberDataDaoTest.java @@ -1,4 +1,4 @@ -package com.dnd.gooding.user.query.dao; +package com.dnd.gooding.unit.user.query.dao; import java.util.List; @@ -12,6 +12,8 @@ import org.springframework.test.context.jdbc.Sql; import com.dnd.gooding.user.command.application.NoMemberException; +import com.dnd.gooding.user.query.dao.MemberDataDao; +import com.dnd.gooding.user.query.dao.MemberDataSpecs; import com.dnd.gooding.user.query.dto.MemberData; @SpringBootTest