Separate Application Profiles Using Local MySQL DB.
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -38,3 +38,5 @@ out/
|
||||
|
||||
/logs
|
||||
/logs/*.log
|
||||
|
||||
/src/main/resources/application-prod.yml
|
||||
|
||||
@@ -42,7 +42,8 @@ dependencies {
|
||||
annotationProcessor 'org.projectlombok:lombok'
|
||||
|
||||
implementation 'org.mybatis.spring.boot:mybatis-spring-boot-starter:2.2.0'
|
||||
runtimeOnly 'com.h2database:h2'
|
||||
testImplementation 'com.h2database:h2'
|
||||
runtimeOnly 'mysql:mysql-connector-java'
|
||||
|
||||
implementation 'com.lmax:disruptor:3.4.4'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-log4j2'
|
||||
@@ -60,7 +61,7 @@ dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
|
||||
implementation 'org.springframework.session:spring-session-data-redis'
|
||||
|
||||
testImplementation 'io.github.javaunit:autoparams:0.2.12'
|
||||
testImplementation 'io.github.javaunit:autoparams:0.3.0'
|
||||
testImplementation 'com.tngtech.archunit:archunit-junit5:0.20.1'
|
||||
|
||||
testImplementation 'org.springframework.boot:spring-boot-starter-test'
|
||||
|
||||
@@ -21,7 +21,7 @@ import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
public class AccountModuleConfiguration {
|
||||
|
||||
@Bean
|
||||
@Profile("prod")
|
||||
@Profile(value = {"local", "prod"})
|
||||
public MailDispatcher mailDispatcher(JavaMailSender javaMailSender) {
|
||||
return new SmtpMailDispatcher(javaMailSender);
|
||||
}
|
||||
|
||||
@@ -6,22 +6,10 @@ import org.mybatis.spring.SqlSessionFactoryBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
|
||||
@Configuration
|
||||
public class DatabaseConfiguration {
|
||||
|
||||
@Bean
|
||||
public DataSource dataSource() {
|
||||
return new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2)
|
||||
.setName("testdb;mode=MySQL")
|
||||
.addScript("classpath:sql/ddl.sql")
|
||||
.addScript("classpath:sql/dml.sql")
|
||||
.build();
|
||||
}
|
||||
|
||||
@Bean
|
||||
public SqlSessionFactory sqlSessionFactory(DataSource dataSource) throws Exception {
|
||||
var factoryBean = new SqlSessionFactoryBean();
|
||||
|
||||
11
src/main/resources/application-local.yml
Normal file
11
src/main/resources/application-local.yml
Normal file
@@ -0,0 +1,11 @@
|
||||
spring:
|
||||
datasource:
|
||||
url: jdbc:mysql://localhost:3307/yam?useSSL=false&serverTimezone=UTC&useCursors=false&sendStringParametersAsUnicode=false&characterEncoding=UTF8
|
||||
username: root
|
||||
password: pass
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
|
||||
redis:
|
||||
host: localhost
|
||||
password:
|
||||
port: 6379
|
||||
@@ -12,10 +12,6 @@ spring:
|
||||
enable: true
|
||||
session:
|
||||
store-type: redis
|
||||
redis:
|
||||
host: localhost
|
||||
password:
|
||||
port: 6379
|
||||
|
||||
app:
|
||||
mail:
|
||||
|
||||
109
src/main/resources/schema-mysql.sql
Normal file
109
src/main/resources/schema-mysql.sql
Normal file
@@ -0,0 +1,109 @@
|
||||
create table account
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
email varchar(255) not null,
|
||||
email_check_token varchar(255),
|
||||
email_check_token_generated_at timestamp,
|
||||
email_verified boolean not null,
|
||||
joined_at timestamp,
|
||||
last_modified_at timestamp,
|
||||
role varchar(255) not null,
|
||||
password varchar(255) not null,
|
||||
withdraw boolean not null,
|
||||
withdrawal_at timestamp,
|
||||
member_id bigint,
|
||||
status varchar(255) not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table member
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
nickname varchar(255) not null,
|
||||
image varchar(255) not null,
|
||||
status varchar(255) not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table article
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
image varchar(255) not null,
|
||||
modified_at timestamp,
|
||||
status varchar(255) not null,
|
||||
title varchar(255) not null,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table article_likes
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table article_tag
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
article_id bigint not null,
|
||||
tag_id bigint not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table comment
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
content varchar(255) not null,
|
||||
created_at timestamp,
|
||||
modified_at timestamp,
|
||||
status varchar(255),
|
||||
article_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table comment_likes
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
comment_id bigint,
|
||||
member_id bigint,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
create table tag
|
||||
(
|
||||
id bigint not null auto_increment,
|
||||
name varchar(255) not null,
|
||||
primary key (id)
|
||||
) engine=InnoDB;
|
||||
|
||||
alter table account
|
||||
add constraint UK_q0uja26qgu1atulenwup9rxyr unique (email);
|
||||
alter table account
|
||||
add constraint FKr5j0huynd7nsv1s7e9vb8qvwo foreign key (member_id) references member;
|
||||
alter table tag
|
||||
add constraint UK_1wdpsed5kna2y38hnbgrnhi5b unique (name);
|
||||
alter table article
|
||||
add constraint UK_571gx7oqo5xpmgocegaidlcu9 unique (title);
|
||||
alter table article
|
||||
add constraint FK6l9vkfd5ixw8o8kph5rj1k7gu foreign key (member_id) references member;
|
||||
alter table article_likes
|
||||
add constraint FK1wt0ww82gfxkuxw3ghxmp55xy foreign key (article_id) references article;
|
||||
alter table article_likes
|
||||
add constraint FKkipxs7p8nrjd4537f3k8rexh5 foreign key (member_id) references member;
|
||||
alter table article_tag
|
||||
add constraint FKenqeees0y8hkm7x1p1ittuuye foreign key (article_id) references article;
|
||||
alter table article_tag
|
||||
add constraint FKesqp7s9jj2wumlnhssbme5ule foreign key (tag_id) references tag;
|
||||
alter table comment
|
||||
add constraint FK5yx0uphgjc6ik6hb82kkw501y foreign key (article_id) references article;
|
||||
alter table comment
|
||||
add constraint FKmrrrpi513ssu63i2783jyiv9m foreign key (member_id) references member;
|
||||
alter table comment_likes
|
||||
add constraint FKd0epu3dcjc57pwe7lt5jgfqsi foreign key (comment_id) references comment;
|
||||
alter table comment_likes
|
||||
add constraint FK7mxs5jtimpj71miv2r0fp6r8p foreign key (member_id) references member;
|
||||
@@ -27,11 +27,13 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
@DisplayName("Account Command HTTP API")
|
||||
@WebMvcTest(AccountCommandApi.class)
|
||||
@ActiveProfiles("test")
|
||||
final class AccountCommandApiTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -14,10 +14,12 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
@DisplayName("Account Query HTTP API")
|
||||
@WebMvcTest(AccountQueryApi.class)
|
||||
@ActiveProfiles("test")
|
||||
class AccountQueryApiTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -18,11 +18,13 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
@DisplayName("Article Command HTTP API")
|
||||
@WebMvcTest(ArticleCommandApi.class)
|
||||
@ActiveProfiles("test")
|
||||
final class ArticleCommandApiTests {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -25,10 +25,12 @@ import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.mock.web.MockHttpSession;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
@DisplayName("Comment Command HTTP API")
|
||||
@WebMvcTest(CommentCommandApi.class)
|
||||
@ActiveProfiles("test")
|
||||
final class CommentCommandApiTest {
|
||||
|
||||
@Autowired
|
||||
|
||||
@@ -3,10 +3,16 @@ package com.yam.app.integration;
|
||||
import static org.springframework.test.web.servlet.setup.SharedHttpSessionConfigurer.sharedHttpSession;
|
||||
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import javax.sql.DataSource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
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.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.Profile;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
|
||||
@@ -32,4 +38,19 @@ abstract class AbstractIntegrationTests {
|
||||
.apply(sharedHttpSession())
|
||||
.build();
|
||||
}
|
||||
|
||||
@Configuration
|
||||
public static class TestConfiguration {
|
||||
|
||||
@Bean
|
||||
@Profile("test")
|
||||
public DataSource dataSource() {
|
||||
return new EmbeddedDatabaseBuilder()
|
||||
.setType(EmbeddedDatabaseType.H2)
|
||||
.setName("testdb;mode=MySQL")
|
||||
.addScript("classpath:sql/ddl.sql")
|
||||
.addScript("classpath:sql/dml.sql")
|
||||
.build();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
5
src/test/resources/application-test.yml
Normal file
5
src/test/resources/application-test.yml
Normal file
@@ -0,0 +1,5 @@
|
||||
spring:
|
||||
redis:
|
||||
host: localhost
|
||||
password:
|
||||
port: 6379
|
||||
@@ -1,5 +1,4 @@
|
||||
create table account
|
||||
(
|
||||
create table account (
|
||||
id bigint generated by default as identity,
|
||||
email varchar(255) not null,
|
||||
email_check_token varchar(255),
|
||||
@@ -16,7 +15,7 @@ create table account
|
||||
primary key (id)
|
||||
);
|
||||
|
||||
create table member(
|
||||
create table member (
|
||||
id bigint generated by default as identity,
|
||||
nickname varchar(255) not null,
|
||||
image varchar(255) not null,
|
||||
@@ -1,6 +1,7 @@
|
||||
insert into member(nickname, image, status)
|
||||
values ('rebwon', 'temp.png', 'ALIVE'),
|
||||
('loginCheck', 'temp.png', 'ALIVE');
|
||||
('loginCheck', 'temp.png', 'ALIVE'),
|
||||
('comment', 'temp.png', 'ALIVE');
|
||||
|
||||
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||
joined_at, last_modified_at, password, withdraw, role, status)
|
||||
@@ -14,7 +15,10 @@ values ('rebwon@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||
false, 'DEFAULT', 1, 'ALIVE'),
|
||||
('loginCheck@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||
'$2a$10$EqbMbYB0vcZnuA5CClqa9uiLDnjA6pCjxn208ZchzA2q3ofqnkhcq',
|
||||
false, 'DEFAULT', 2, 'ALIVE');
|
||||
false, 'DEFAULT', 2, 'ALIVE'),
|
||||
('comment@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||
'$2a$10$EqbMbYB0vcZnuA5CClqa9uiLDnjA6pCjxn208ZchzA2q3ofqnkhcq',
|
||||
false, 'DEFAULT', 3, 'ALIVE');
|
||||
|
||||
insert into article(title, content, image, status, created_at, modified_at, member_id)
|
||||
values ('sample-title', 'sample-content', 'sample.png', 'ALIVE', now(), now(), 1);
|
||||
@@ -29,14 +33,5 @@ values (1, 1),
|
||||
(1, 2),
|
||||
(1, 3);
|
||||
|
||||
insert into member(nickname, image, status)
|
||||
values ('comment', 'temp.png', 'ALIVE');
|
||||
|
||||
insert into account(email, email_check_token, email_check_token_generated_at, email_verified,
|
||||
joined_at, last_modified_at, password, withdraw, role, member_id, status)
|
||||
values ('comment@gmail.com', 'emailchecktoken1', now(), true, now(), now(),
|
||||
'$2a$10$EqbMbYB0vcZnuA5CClqa9uiLDnjA6pCjxn208ZchzA2q3ofqnkhcq',
|
||||
false, 'DEFAULT', 3, 'ALIVE');
|
||||
|
||||
INSERT INTO comment(content, created_at, modified_at, status, article_id, member_id)
|
||||
VALUES ('sample content1', now(), now(), 'ALIVE', 1, 3);
|
||||
Reference in New Issue
Block a user