-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[feat] 테스트를 위한 embedded redis 를 구동시키기 위한 extension 설정
- JUnit 테스트를 실행할 때 extension을 detect할 수 있도록 기능 추가
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
src/test/java/camp/woowak/lab/helper/EmbeddedRedisExtension.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package camp.woowak.lab.helper; | ||
|
||
import org.junit.jupiter.api.extension.BeforeAllCallback; | ||
import org.junit.jupiter.api.extension.ExtensionContext; | ||
import org.springframework.test.context.DynamicPropertyRegistry; | ||
import org.springframework.test.context.DynamicPropertySource; | ||
|
||
import redis.embedded.RedisServer; | ||
|
||
public class EmbeddedRedisExtension implements BeforeAllCallback { | ||
|
||
private static RedisServer redisServer; | ||
private static final ExtensionContext.Namespace NAMESPACE = ExtensionContext.Namespace.create( | ||
EmbeddedRedisExtension.class); | ||
|
||
@Override | ||
public void beforeAll(ExtensionContext context) throws Exception { | ||
if (redisServer == null) { | ||
redisServer = new RedisServer(6379); | ||
redisServer.start(); | ||
context.getRoot().getStore(NAMESPACE).put("redisServer", redisServer); | ||
} | ||
} | ||
|
||
@DynamicPropertySource | ||
static void redisProperties(DynamicPropertyRegistry registry) { | ||
registry.add("spring.data.redis.host", () -> "localhost"); | ||
registry.add("spring.data.redis.port", () -> "6379"); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
src/test/resources/META-INF/services/org.junit.jupiter.api.extension.Extension
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
camp.woowak.lab.helper.EmbeddedRedisExtension |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
junit.jupiter.extensions.autodetection.enabled=true | ||
junit.jupiter.extensions.autodetection.classpath.enabled=true |