-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApplicationContextLoadTest.java
More file actions
80 lines (69 loc) · 3.45 KB
/
Copy pathApplicationContextLoadTest.java
File metadata and controls
80 lines (69 loc) · 3.45 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
package com.carecode.integration;
import com.carecode.CareCodeApplication;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationContext;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.security.web.FilterChainProxy;
import static org.assertj.core.api.Assertions.assertThat;
/** Docker 없이도 도는 컨텍스트 로딩 테스트. 보안 필터 체인, 인터셉터, 캐시 설정 등 빈 구성이 깨지면 여기서 바로 잡힌다 */
@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",
"spring.datasource.url=jdbc:h2:mem:carecode;MODE=MySQL;DB_CLOSE_DELAY=-1",
"spring.datasource.driver-class-name=org.h2.Driver",
"spring.datasource.username=sa",
"spring.datasource.password=",
"spring.jpa.database-platform=org.hibernate.dialect.H2Dialect",
"spring.jpa.hibernate.ddl-auto=create-drop",
"spring.flyway.enabled=false",
"jwt.secret=testJwtSecretKeyForContextLoadTestMustBe256BitsLong0123456789",
"springdoc.api-docs.enabled=false",
"springdoc.swagger-ui.enabled=false",
"public.data.api.key=dummy",
"KAKAO_CLIENT_ID=dummy-kakao-client",
"KAKAO_CLIENT_SECRET=dummy-kakao-secret",
"MAIL_USERNAME=dummy",
"MAIL_PASSWORD=dummy"
}
)
@DisplayName("애플리케이션 컨텍스트 로딩")
class ApplicationContextLoadTest {
@MockBean
private RedisConnectionFactory redisConnectionFactory;
@MockBean
private StringRedisTemplate stringRedisTemplate;
// 메일 자동설정을 제외했으므로 대체 빈을 넣어준다 (실제 SMTP 연결은 하지 않는다).
@MockBean
private JavaMailSender javaMailSender;
@Autowired
private ApplicationContext applicationContext;
@Test
@DisplayName("컨텍스트가 정상적으로 기동된다")
void contextLoads() {
assertThat(applicationContext).isNotNull();
}
@Test
@DisplayName("보안 필터 체인이 등록되어 있다")
void securityFilterChainIsRegistered() {
FilterChainProxy proxy = applicationContext.getBean(FilterChainProxy.class);
assertThat(proxy.getFilterChains()).isNotEmpty();
}
@Test
@DisplayName("Rate limit 인터셉터가 빈으로 등록되어 있다")
void rateLimitInterceptorIsRegistered() {
assertThat(applicationContext.getBeansOfType(com.carecode.core.RateLimitInterceptor.class))
.isNotEmpty();
assertThat(applicationContext.getBeansOfType(com.carecode.core.config.WebMvcConfig.class))
.isNotEmpty();
}
}