-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCareCodeMariaDbIntegrationTest.java
More file actions
87 lines (74 loc) · 3.38 KB
/
Copy pathCareCodeMariaDbIntegrationTest.java
File metadata and controls
87 lines (74 loc) · 3.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
package com.carecode.integration;
import com.carecode.CareCodeApplication;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.test.context.DynamicPropertyRegistry;
import org.springframework.test.context.DynamicPropertySource;
import org.testcontainers.containers.MariaDBContainer;
import org.testcontainers.junit.jupiter.Container;
import org.testcontainers.junit.jupiter.Testcontainers;
import javax.sql.DataSource;
import java.sql.Connection;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(
classes = CareCodeApplication.class,
properties = {
"spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.data.redis.RedisAutoConfiguration,"
+ "org.springframework.boot.autoconfigure.data.redis.RedisRepositoriesAutoConfiguration,"
+ "org.springframework.boot.autoconfigure.mail.MailSenderAutoConfiguration",
"spring.cache.type=none",
"jwt.secret=testJwtSecretKeyForIntegrationTestsMustBe256BitsLong012345678901234567890",
"spring.flyway.enabled=false",
"spring.jpa.hibernate.ddl-auto=create-drop",
"springdoc.api-docs.enabled=false",
"springdoc.swagger-ui.enabled=false",
"public.data.api.key=dummy",
"GOOGLE_CLIENT_ID=dummy-google-client",
"GOOGLE_CLIENT_SECRET=dummy-google-secret",
"KAKAO_CLIENT_ID=dummy-kakao-client",
"KAKAO_CLIENT_SECRET=dummy-kakao-secret",
"MAIL_USERNAME=dummy",
"MAIL_PASSWORD=dummy"
}
)
@Testcontainers(disabledWithoutDocker = true)
class CareCodeMariaDbIntegrationTest {
@Container
static final MariaDBContainer<?> MARIA_DB = new MariaDBContainer<>("mariadb:10.11")
.withDatabaseName("carecode_it")
.withUsername("test")
.withPassword("test");
@DynamicPropertySource
static void configureDataSource(DynamicPropertyRegistry registry) {
registry.add("spring.datasource.url", MARIA_DB::getJdbcUrl);
registry.add("spring.datasource.username", MARIA_DB::getUsername);
registry.add("spring.datasource.password", MARIA_DB::getPassword);
}
@MockBean
private RedisConnectionFactory redisConnectionFactory;
@MockBean
private StringRedisTemplate stringRedisTemplate;
// 메일 자동설정을 제외했으므로 대체 빈을 넣어준다 (실제 SMTP 연결은 하지 않는다).
@MockBean
private JavaMailSender javaMailSender;
@Autowired
DataSource dataSource;
@Autowired
ApplicationContext applicationContext;
@Test
void spring_context_loads() {
assertThat(applicationContext).isNotNull();
}
@Test
void datasource_is_reachable_withMariaDb() throws Exception {
try (Connection connection = dataSource.getConnection()) {
assertThat(connection.isValid(5)).isTrue();
}
}
}