diff --git a/eventstore/src/main/java/net/slipp/ddd/events/DefaultEventStore.java b/eventstore/src/main/java/net/slipp/ddd/events/DefaultEventStore.java index ca0ce67..24c3ae0 100644 --- a/eventstore/src/main/java/net/slipp/ddd/events/DefaultEventStore.java +++ b/eventstore/src/main/java/net/slipp/ddd/events/DefaultEventStore.java @@ -13,16 +13,6 @@ public DefaultEventStore(StoredEventRepository storedEventRepository) { this.storedEventRepository = storedEventRepository; } - @Override - public List allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId) { - return storedEventRepository.allStoredEventsBetween(aLowStoredEventId, aHighStoredEventId); - } - - @Override - public List allStoredEventsSince(long aStoredEventId) { - return storedEventRepository.allStoredEventsSince(aStoredEventId); - } - @Override public StoredEvent append(DomainEvent aDomainEvent) { return storedEventRepository.save(null); @@ -33,8 +23,4 @@ public void close() { // DO NOTHING } - @Override - public long countStoredEvents() { - return storedEventRepository.countStoredEvents(); - } } diff --git a/eventstore/src/main/java/net/slipp/ddd/events/EventStore.java b/eventstore/src/main/java/net/slipp/ddd/events/EventStore.java index 59fcbbc..5e00eeb 100644 --- a/eventstore/src/main/java/net/slipp/ddd/events/EventStore.java +++ b/eventstore/src/main/java/net/slipp/ddd/events/EventStore.java @@ -6,13 +6,7 @@ public interface EventStore { - List allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId); - - List allStoredEventsSince(long aStoredEventId); - StoredEvent append(DomainEvent aDomainEvent); void close(); - - long countStoredEvents(); } diff --git a/eventstore/src/main/java/net/slipp/ddd/events/StoredEvent.java b/eventstore/src/main/java/net/slipp/ddd/events/StoredEvent.java index e8529a4..be4b394 100644 --- a/eventstore/src/main/java/net/slipp/ddd/events/StoredEvent.java +++ b/eventstore/src/main/java/net/slipp/ddd/events/StoredEvent.java @@ -6,30 +6,17 @@ public class StoredEvent { - private Long eventId; - private String eventBody; - private LocalDateTime occurredOn; - private String typeName; - - public StoredEvent(String aTypeName, LocalDateTime anOccurredOn, String anEventBody) { - this(); - - this.setEventBody(anEventBody); - this.setOccurredOn(anOccurredOn); - this.setTypeName(aTypeName); - } - - public StoredEvent(String aTypeName, LocalDateTime anOccurredOn, String anEventBody, Long anEventId) { - this(aTypeName, anOccurredOn, anEventBody); - - this.setEventId(anEventId); - } + private Long id; + private final String eventId; + private final String eventBody; + private final LocalDateTime occurredOn; + private final String typeName; public String eventBody() { return this.eventBody; } - public Long eventId() { + public String eventId() { return this.eventId; } @@ -59,31 +46,20 @@ public String eventTypeName() { } - public StoredEvent() { - super(); - this.setEventId(-1); + public StoredEvent(Long id, String eventId, String eventBody, LocalDateTime occurredOn, String typeName) { + this.id = id; + this.eventId = eventId; + this.eventBody = eventBody; + this.occurredOn = occurredOn; + this.typeName = typeName; } - protected void setEventBody(String anEventBody) { - //TODO this.assertArgumentNotEmpty(anEventBody, "The event body is required."); - //this.assertArgumentLength(anEventBody, 1, 65000, "The event body must be 65000 characters or less."); - - this.eventBody = anEventBody; - } - - protected void setEventId(long anEventId) { - this.eventId = anEventId; - } - - protected void setOccurredOn(LocalDateTime anOccurredOn) { - //LocalDateTime.of() - this.occurredOn = anOccurredOn; + public StoredEvent(String eventId, String eventBody, LocalDateTime occurredOn, String typeName) { + super(); + this.eventId = eventId; + this.eventBody = eventBody; + this.occurredOn = occurredOn; + this.typeName = typeName; } - protected void setTypeName(String aTypeName) { - //TODO this.assertArgumentNotEmpty(aTypeName, "The event type name is required."); - //this.assertArgumentLength(aTypeName, 1, 100, "The event type name must be 100 characters or less."); - - this.typeName = aTypeName; - } } diff --git a/eventstore/src/main/java/net/slipp/ddd/events/StoredEventRepository.java b/eventstore/src/main/java/net/slipp/ddd/events/StoredEventRepository.java index e4891cd..95694a2 100644 --- a/eventstore/src/main/java/net/slipp/ddd/events/StoredEventRepository.java +++ b/eventstore/src/main/java/net/slipp/ddd/events/StoredEventRepository.java @@ -1,17 +1,7 @@ package net.slipp.ddd.events; -import java.util.List; -import java.util.Optional; - public interface StoredEventRepository { StoredEvent save(StoredEvent anEvent); - List allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId); - - List allStoredEventsSince(long aStoredEventId); - - long countStoredEvents(); - - Optional findByEventId(Long eventId); } diff --git a/recruit/build.gradle b/recruit/build.gradle index 7125278..2e78d12 100644 --- a/recruit/build.gradle +++ b/recruit/build.gradle @@ -19,14 +19,22 @@ repositories { jcenter() } +dependencyManagement { + dependencies { + dependency group: 'org.bgee.log4jdbc-log4j2', name: 'log4jdbc-log4j2-jdbc4.1', version: '1.16' + dependency group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: '2.1.1' + } +} + dependencies { implementation project(':assertions') implementation project(':eventstore') - implementation 'org.springframework.boot:spring-boot-starter-aop' - + implementation group: 'org.mariadb.jdbc', name: 'mariadb-java-client' + implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter' + implementation 'org.springframework.boot:spring-boot-starter-aop' implementation 'org.springframework.boot:spring-boot-starter-web' implementation 'org.projectlombok:lombok' implementation group: 'org.apache.commons', name: 'commons-lang3', version: '3.10' @@ -37,7 +45,7 @@ dependencies { implementation 'org.springframework.boot:spring-boot-starter-data-jpa' runtimeOnly 'mysql:mysql-connector-java' - implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1:1.16' + implementation 'org.bgee.log4jdbc-log4j2:log4jdbc-log4j2-jdbc4.1' implementation "org.liquibase:liquibase-core" liquibaseRuntime "org.liquibase:liquibase-core" liquibaseRuntime "mysql:mysql-connector-java" diff --git a/recruit/src/main/docker/mysql.yml b/recruit/src/main/docker/mysql.yml index ee37672..070ca23 100644 --- a/recruit/src/main/docker/mysql.yml +++ b/recruit/src/main/docker/mysql.yml @@ -3,9 +3,10 @@ services: slipping-mysql: image: mysql:8.0.20 environment: - - MYSQL_USER=root - - MYSQL_ALLOW_EMPTY_PASSWORD=yes + - MYSQL_ROOT_PASSWORD=root + - MYSQL_USER=slipp + - MYSQL_PASSWORD=slipppw - MYSQL_DATABASE=slipping ports: - 3377:3306 - command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp + command: mysqld --lower_case_table_names=1 --skip-ssl --character_set_server=utf8mb4 --explicit_defaults_for_timestamp --default-authentication-plugin=mysql_native_password diff --git a/recruit/src/main/java/net/slipp/moim/App.java b/recruit/src/main/java/net/slipp/moim/App.java index 84c559f..bdc44a9 100644 --- a/recruit/src/main/java/net/slipp/moim/App.java +++ b/recruit/src/main/java/net/slipp/moim/App.java @@ -3,8 +3,8 @@ import net.slipp.ddd.events.DefaultEventStore; import net.slipp.ddd.events.EventStore; -import net.slipp.ddd.events.StoredEvent; import net.slipp.ddd.events.StoredEventRepository; +import net.slipp.moim.port.repository.MybatisStoredEventRepository; import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; @@ -13,9 +13,6 @@ import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.EnableAspectJAutoProxy; -import java.util.List; -import java.util.Optional; - @SpringBootApplication @EnableConfigurationProperties({ LiquibaseProperties.class }) public class App { @@ -24,7 +21,6 @@ public static void main(String[] args) { SpringApplication.run(App.class, args); } - @EnableAspectJAutoProxy @Configuration static class AopConfiguration { @@ -32,34 +28,16 @@ static class AopConfiguration { @Configuration static class DomainEventConfiguration { - @Bean - public StoredEventRepository storedEventRepository() { - return new StoredEventRepository() { - @Override - public StoredEvent save(StoredEvent anEvent) { - return null; - } - @Override - public List allStoredEventsBetween(long aLowStoredEventId, long aHighStoredEventId) { - throw new UnsupportedOperationException(); - } + private final MybatisStoredEventRepository mybatisStoredEventRepository; - @Override - public List allStoredEventsSince(long aStoredEventId) { - throw new UnsupportedOperationException(); - } - - @Override - public long countStoredEvents() { - throw new UnsupportedOperationException(); - } + DomainEventConfiguration(MybatisStoredEventRepository mybatisStoredEventRepository) { + this.mybatisStoredEventRepository = mybatisStoredEventRepository; + } - @Override - public Optional findByEventId(Long eventId) { - throw new UnsupportedOperationException(); - } - }; + @Bean + public StoredEventRepository storedEventRepository() { + return mybatisStoredEventRepository; } @Bean diff --git a/recruit/src/main/java/net/slipp/moim/domain/model/sample/Sample.java b/recruit/src/main/java/net/slipp/moim/domain/model/sample/Sample.java new file mode 100644 index 0000000..26804ee --- /dev/null +++ b/recruit/src/main/java/net/slipp/moim/domain/model/sample/Sample.java @@ -0,0 +1,18 @@ +package net.slipp.moim.domain.model.sample; + +import lombok.*; + +@Getter +@Setter +@NoArgsConstructor +@AllArgsConstructor +@ToString +@EqualsAndHashCode +@Builder +public class Sample { + + private Long id; + private String name; + private String address; + +} diff --git a/recruit/src/main/java/net/slipp/moim/domain/model/sample/SampleMapper.java b/recruit/src/main/java/net/slipp/moim/domain/model/sample/SampleMapper.java new file mode 100644 index 0000000..46aa03d --- /dev/null +++ b/recruit/src/main/java/net/slipp/moim/domain/model/sample/SampleMapper.java @@ -0,0 +1,11 @@ +package net.slipp.moim.domain.model.sample; + +import org.apache.ibatis.annotations.Mapper; + +import java.util.List; + +@Mapper +public interface SampleMapper { + + List findAll(); +} diff --git a/recruit/src/main/java/net/slipp/moim/domain/model/sample/SampleService.java b/recruit/src/main/java/net/slipp/moim/domain/model/sample/SampleService.java new file mode 100644 index 0000000..69e7be7 --- /dev/null +++ b/recruit/src/main/java/net/slipp/moim/domain/model/sample/SampleService.java @@ -0,0 +1,19 @@ +package net.slipp.moim.domain.model.sample; + +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +public class SampleService { + + private final SampleMapper sampleMapper; + + public SampleService(SampleMapper sampleMapper) { + this.sampleMapper = sampleMapper; + } + + public List findAll() { + return sampleMapper.findAll(); + } +} diff --git a/recruit/src/main/java/net/slipp/moim/port/repository/MybatisStoredEventRepository.java b/recruit/src/main/java/net/slipp/moim/port/repository/MybatisStoredEventRepository.java new file mode 100644 index 0000000..0c3ab43 --- /dev/null +++ b/recruit/src/main/java/net/slipp/moim/port/repository/MybatisStoredEventRepository.java @@ -0,0 +1,24 @@ +package net.slipp.moim.port.repository; + +import net.slipp.ddd.events.StoredEvent; +import net.slipp.ddd.events.StoredEventRepository; +import org.apache.ibatis.annotations.Insert; +import org.apache.ibatis.annotations.Mapper; +import org.apache.ibatis.annotations.Select; + +@Mapper +public interface MybatisStoredEventRepository extends StoredEventRepository { + + @Override + default StoredEvent save(StoredEvent anEvent) { + + this.insert(anEvent); + return this.findStoredEventByEventId(anEvent.eventId()); + }; + + @Insert("insert into stored_event(event_id, event_body, occurred_on, type_name) values (#{eventId}, #{eventBody}, #{occurredOn}, #{typeName})") + void insert(StoredEvent anEvent); + + @Select("select * from stored_event where event_id = #{eventId}") + StoredEvent findStoredEventByEventId(String eventId); +} diff --git a/recruit/src/main/java/net/slipp/moim/support/config/db/DatasourceConfig.java b/recruit/src/main/java/net/slipp/moim/support/config/db/DatasourceConfig.java new file mode 100644 index 0000000..bcf1767 --- /dev/null +++ b/recruit/src/main/java/net/slipp/moim/support/config/db/DatasourceConfig.java @@ -0,0 +1,72 @@ +package net.slipp.moim.support.config.db; + +import com.zaxxer.hikari.HikariConfig; +import com.zaxxer.hikari.HikariDataSource; +import lombok.extern.slf4j.Slf4j; +import org.apache.ibatis.session.SqlSessionFactory; +import org.mybatis.spring.SqlSessionFactoryBean; +import org.mybatis.spring.SqlSessionTemplate; +import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.ApplicationContext; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Primary; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.jdbc.datasource.DataSourceTransactionManager; + +import javax.sql.DataSource; + +import static net.slipp.moim.support.config.db.MybatisConfig.CONFIG_LOCATION_PATH; +import static net.slipp.moim.support.config.db.MybatisConfig.SQL_LOCATION_PATH; + +@Slf4j +@Configuration +public class DatasourceConfig { + + private final ApplicationContext applicationContext; + + public DatasourceConfig(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + @Primary + @Bean + public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception { + PathMatchingResourcePatternResolver pathResolver = new PathMatchingResourcePatternResolver(); + + SqlSessionFactoryBean sqlSessionFactoryBean = new SqlSessionFactoryBean(); + sqlSessionFactoryBean.setDataSource(dataSource); + sqlSessionFactoryBean.setMapperLocations(applicationContext.getResources(SQL_LOCATION_PATH)); + sqlSessionFactoryBean.setConfigLocation(pathResolver.getResource(CONFIG_LOCATION_PATH)); + + return sqlSessionFactoryBean.getObject(); + } + + @Primary + @Bean + public SqlSessionTemplate sqlSessionTemplate(SqlSessionFactory sqlSessionFactory) { + return new SqlSessionTemplate(sqlSessionFactory); + } + + @Primary + @Bean + @ConfigurationProperties(prefix = "spring.datasource.hikari") + public HikariConfig hikariConfig() { + return new HikariConfig(); + } + + @Primary + @Bean + public DataSource dataSource() { + DataSource dataSource = new HikariDataSource(hikariConfig()); + log.info("datasource : {}", dataSource); + return dataSource; + } + + @Bean + public DataSourceTransactionManager transactionManager() { + return new DataSourceTransactionManager(dataSource()); + } + +} + diff --git a/recruit/src/main/java/net/slipp/moim/support/config/db/MybatisConfig.java b/recruit/src/main/java/net/slipp/moim/support/config/db/MybatisConfig.java new file mode 100644 index 0000000..7712b88 --- /dev/null +++ b/recruit/src/main/java/net/slipp/moim/support/config/db/MybatisConfig.java @@ -0,0 +1,13 @@ +package net.slipp.moim.support.config.db; + +import org.mybatis.spring.annotation.MapperScan; +import org.springframework.context.annotation.Configuration; + +@Configuration +@MapperScan(basePackages = {MybatisConfig.BASE_PACKAGE, MybatisConfig.PORT_REPOSITORY_PACKAGE}) +public class MybatisConfig { + public static final String BASE_PACKAGE = "net.slipp.moim.domain"; + public static final String PORT_REPOSITORY_PACKAGE = "net.slipp.moim.port.repository"; + public static final String CONFIG_LOCATION_PATH = "classpath:mybatis/mybatis-config.xml"; + public static final String SQL_LOCATION_PATH = "classpath:/mapper/**/*.xml"; +} diff --git a/recruit/src/main/resources/application.yml b/recruit/src/main/resources/application.yml index 6e4a551..ce3322e 100644 --- a/recruit/src/main/resources/application.yml +++ b/recruit/src/main/resources/application.yml @@ -5,11 +5,11 @@ spring: datasource: type: com.zaxxer.hikari.HikariDataSource - driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy - url: jdbc:log4jdbc:mysql://localhost:3377/slipping?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true - username: root - password: hikari: + driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy + jdbc-url: jdbc:log4jdbc:mysql://localhost:3377/slipping?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true + username: slipp + password: slipppw poolName: Hikari maximum-pool-size: 3 minimum-idle: 3 @@ -21,3 +21,16 @@ spring: prepStmtCacheSize: 250 prepStmtCacheSqlLimit: 2048 useServerPrepStmts: true + +mybatis: + # type-aliases-package: com.example.domain.model + # type-handlers-package: com.example.typehandler + configuration: + map-underscore-to-camel-case: true + default-fetch-size: 100 + default-statement-timeout: 30 + +logging: + level: + net.slipp: DEBUG + org.mybatis: info diff --git a/recruit/src/main/resources/config/liquibase/changelog/20200614182000_add_column_in_sample.xml b/recruit/src/main/resources/config/liquibase/changelog/20200614182000_add_column_in_sample.xml index 03fc6d3..a5dcd3e 100644 --- a/recruit/src/main/resources/config/liquibase/changelog/20200614182000_add_column_in_sample.xml +++ b/recruit/src/main/resources/config/liquibase/changelog/20200614182000_add_column_in_sample.xml @@ -9,6 +9,9 @@ + + UPDATE slipping.sample SET address='테스트 지역'; + diff --git a/recruit/src/main/resources/config/liquibase/changelog/20200727000000_create_table_store_event.xml b/recruit/src/main/resources/config/liquibase/changelog/20200727000000_create_table_store_event.xml new file mode 100644 index 0000000..8348f6b --- /dev/null +++ b/recruit/src/main/resources/config/liquibase/changelog/20200727000000_create_table_store_event.xml @@ -0,0 +1,20 @@ + + + + + create table stored_event ( + id bigint primary key AUTO_INCREMENT, + event_id varchar(36), + event_body varchar(1000), + occurred_on datetime default current_timestamp, + type_name varchar(100) + ); + + + + diff --git a/recruit/src/main/resources/config/liquibase/data/sample_data.csv b/recruit/src/main/resources/config/liquibase/data/sample_data.csv index c86e130..6f66d0b 100644 --- a/recruit/src/main/resources/config/liquibase/data/sample_data.csv +++ b/recruit/src/main/resources/config/liquibase/data/sample_data.csv @@ -1,3 +1,3 @@ id;name 1;sample1 -2;sampel2 +2;sample2 diff --git a/recruit/src/main/resources/config/liquibase/master.xml b/recruit/src/main/resources/config/liquibase/master.xml index 614714c..18ca840 100644 --- a/recruit/src/main/resources/config/liquibase/master.xml +++ b/recruit/src/main/resources/config/liquibase/master.xml @@ -12,5 +12,6 @@ + diff --git a/recruit/src/main/resources/log4jdbc.log4j2.properties b/recruit/src/main/resources/log4jdbc.log4j2.properties new file mode 100644 index 0000000..8f18407 --- /dev/null +++ b/recruit/src/main/resources/log4jdbc.log4j2.properties @@ -0,0 +1,2 @@ +log4jdbc.spylogdelegator.name=net.sf.log4jdbc.log.slf4j.Slf4jSpyLogDelegator +log4jdbc.dump.sql.maxlinelength=0 diff --git a/recruit/src/main/resources/mapper/paging.xml b/recruit/src/main/resources/mapper/paging.xml new file mode 100644 index 0000000..ceacb1a --- /dev/null +++ b/recruit/src/main/resources/mapper/paging.xml @@ -0,0 +1,23 @@ + + + + + + + SELECT PAGING.* FROM( + + + + ) PAGING + LIMIT #{param.pageable.pageSize} OFFSET #{param.pageable.offset} + + + + SELECT count(*) FROM ( + + + + ) TOTAL + + + diff --git a/recruit/src/main/resources/mapper/sample.xml b/recruit/src/main/resources/mapper/sample.xml new file mode 100644 index 0000000..576e5cc --- /dev/null +++ b/recruit/src/main/resources/mapper/sample.xml @@ -0,0 +1,9 @@ + + + + + + + diff --git a/recruit/src/main/resources/mybatis/mybatis-config.xml b/recruit/src/main/resources/mybatis/mybatis-config.xml new file mode 100644 index 0000000..442a6be --- /dev/null +++ b/recruit/src/main/resources/mybatis/mybatis-config.xml @@ -0,0 +1,13 @@ + + + + + + + + + + + + + diff --git a/recruit/src/test/java/net/slipp/TestApp.java b/recruit/src/test/java/net/slipp/TestApp.java new file mode 100644 index 0000000..9d0f677 --- /dev/null +++ b/recruit/src/test/java/net/slipp/TestApp.java @@ -0,0 +1,53 @@ +package net.slipp; + + +import net.slipp.ddd.events.DefaultEventStore; +import net.slipp.ddd.events.EventStore; +import net.slipp.ddd.events.StoredEvent; +import net.slipp.ddd.events.StoredEventRepository; +import net.slipp.moim.port.repository.MybatisStoredEventRepository; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.boot.autoconfigure.liquibase.LiquibaseProperties; +import org.springframework.boot.context.properties.EnableConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.EnableAspectJAutoProxy; + +import java.util.List; +import java.util.Optional; + +@SpringBootApplication +@EnableConfigurationProperties({ LiquibaseProperties.class }) +public class TestApp { + + public static void main(String[] args) { + SpringApplication.run(TestApp.class, args); + } + + + @EnableAspectJAutoProxy + @Configuration + static class AopConfiguration { + } + + @Configuration + static class DomainEventConfiguration { + + private final MybatisStoredEventRepository mybatisStoredEventRepository; + + DomainEventConfiguration(MybatisStoredEventRepository mybatisStoredEventRepository) { + this.mybatisStoredEventRepository = mybatisStoredEventRepository; + } + + @Bean + public StoredEventRepository storedEventRepository() { + return mybatisStoredEventRepository; + } + + @Bean + public EventStore eventStore(StoredEventRepository storedEventRepository) { + return new DefaultEventStore(storedEventRepository); + } + } +} diff --git a/recruit/src/test/java/net/slipp/moim/domain/model/sample/SampleMapperTest.java b/recruit/src/test/java/net/slipp/moim/domain/model/sample/SampleMapperTest.java new file mode 100644 index 0000000..da43e06 --- /dev/null +++ b/recruit/src/test/java/net/slipp/moim/domain/model/sample/SampleMapperTest.java @@ -0,0 +1,25 @@ +package net.slipp.moim.domain.model.sample; + +import net.slipp.support.BaseRepositoryTest; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +class SampleMapperTest extends BaseRepositoryTest { + + @Autowired + private SampleMapper sampleMapper; + + @Test + void name() { + List result = sampleMapper.findAll(); + + assertThat(result.get(0).getName()).isEqualTo("sample1"); + assertThat(result.get(0).getAddress()).isEqualTo("테스트 지역"); + assertThat(result.get(1).getName()).isEqualTo("sample2"); + assertThat(result.get(1).getAddress()).isEqualTo("테스트 지역"); + } +} diff --git a/recruit/src/test/java/net/slipp/moim/domain/model/sample/SampleServiceTest.java b/recruit/src/test/java/net/slipp/moim/domain/model/sample/SampleServiceTest.java new file mode 100644 index 0000000..e927fe9 --- /dev/null +++ b/recruit/src/test/java/net/slipp/moim/domain/model/sample/SampleServiceTest.java @@ -0,0 +1,7 @@ +package net.slipp.moim.domain.model.sample; + +import static org.junit.jupiter.api.Assertions.*; + +class SampleServiceTest { + +} diff --git a/recruit/src/test/java/net/slipp/moim/port/repository/MybatisStoredEventRepositoryTest.java b/recruit/src/test/java/net/slipp/moim/port/repository/MybatisStoredEventRepositoryTest.java new file mode 100644 index 0000000..f534f3c --- /dev/null +++ b/recruit/src/test/java/net/slipp/moim/port/repository/MybatisStoredEventRepositoryTest.java @@ -0,0 +1,36 @@ +package net.slipp.moim.port.repository; + +import net.slipp.ddd.events.StoredEvent; +import net.slipp.support.BaseRepositoryTest; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; + +import java.time.LocalDateTime; +import java.util.UUID; + +import static org.assertj.core.api.Assertions.assertThat; + +class MybatisStoredEventRepositoryTest extends BaseRepositoryTest { + + @Autowired + private MybatisStoredEventRepository mybatisStoredEventRepository; + + private StoredEvent storedEvent; + private String eventId; + + @BeforeEach + void beforeEach() { + + eventId = UUID.randomUUID().toString(); + storedEvent = new StoredEvent(eventId, "typeName", LocalDateTime.now(), "eventBody"); + } + + @Test + void save() { + + StoredEvent saved = mybatisStoredEventRepository.save(storedEvent); + assertThat(saved.eventId()).isEqualTo(eventId); + } + +} diff --git a/recruit/src/test/java/net/slipp/support/BaseRepositoryTest.java b/recruit/src/test/java/net/slipp/support/BaseRepositoryTest.java new file mode 100644 index 0000000..4101c7c --- /dev/null +++ b/recruit/src/test/java/net/slipp/support/BaseRepositoryTest.java @@ -0,0 +1,17 @@ +package net.slipp.support; + +import net.slipp.moim.support.config.db.DatasourceConfig; +import net.slipp.moim.support.config.db.MybatisConfig; +import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.transaction.annotation.Transactional; + +@ActiveProfiles("test") +@ContextConfiguration(classes = {MybatisConfig.class, DatasourceConfig.class}) +@AutoConfigureTestDatabase(replace = AutoConfigureTestDatabase.Replace.NONE) +@SpringBootTest +@Transactional +public class BaseRepositoryTest { +} diff --git a/recruit/src/test/resources/application-test.yml b/recruit/src/test/resources/application-test.yml new file mode 100644 index 0000000..6c9b52a --- /dev/null +++ b/recruit/src/test/resources/application-test.yml @@ -0,0 +1,35 @@ +spring: + liquibase: + enabled: false + change-log: classpath:config/liquibase/master.xml + + datasource: + type: com.zaxxer.hikari.HikariDataSource + hikari: + driver-class-name: net.sf.log4jdbc.sql.jdbcapi.DriverSpy + jdbc-url: jdbc:log4jdbc:mysql://localhost:3377/slipping?useUnicode=true&characterEncoding=utf8&useSSL=false&useLegacyDatetimeCode=false&serverTimezone=UTC&createDatabaseIfNotExist=true + username: slipp + password: slipppw + poolName: Hikari + maximum-pool-size: 3 + minimum-idle: 3 + max-lifetime: 57600 + connection-timeout: 57600 + idle-timeout: 30000 + data-source-properties: + cachePrepStmts: true + prepStmtCacheSize: 250 + prepStmtCacheSqlLimit: 2048 + useServerPrepStmts: true +mybatis: + # type-aliases-package: com.example.domain.model + # type-handlers-package: com.example.typehandler + configuration: + map-underscore-to-camel-case: true + default-fetch-size: 100 + default-statement-timeout: 30 + +logging: + level: + net.slipp: DEBUG + org.mybatis: info