From b595f712d87b58e0a233837755a22a65840679a1 Mon Sep 17 00:00:00 2001 From: Hong Jeong Hyeon Date: Sun, 2 May 2021 12:48:14 +0900 Subject: [PATCH] [FIX] EmbeddedRedisConfig --- .../user_backend_v2/config/EmbeddedRedisConfig.java | 10 +++++++--- .../main/user_backend_v2/EmailControllerTest.java | 7 +++++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/main/java/com/dsmpear/main/user_backend_v2/config/EmbeddedRedisConfig.java b/src/main/java/com/dsmpear/main/user_backend_v2/config/EmbeddedRedisConfig.java index 4a89cae..7689e59 100644 --- a/src/main/java/com/dsmpear/main/user_backend_v2/config/EmbeddedRedisConfig.java +++ b/src/main/java/com/dsmpear/main/user_backend_v2/config/EmbeddedRedisConfig.java @@ -9,12 +9,15 @@ import javax.annotation.PreDestroy; @Configuration -@Profile("local") +@Profile("test") public class EmbeddedRedisConfig { private final RedisServer redisServer; - public EmbeddedRedisConfig(@Value("${spring.redis.port}") int redisPort) { + @Value("${spring.redis.port}") + int redisPort; + + public EmbeddedRedisConfig() { this.redisServer = RedisServer.builder() .setting("maxheap 128M") .build(); @@ -27,7 +30,8 @@ public void runRedis() { @PreDestroy public void stopRedis() { - redisServer.stop(); + if(redisServer != null) + redisServer.stop(); } } \ No newline at end of file diff --git a/src/test/java/com/dsmpear/main/user_backend_v2/EmailControllerTest.java b/src/test/java/com/dsmpear/main/user_backend_v2/EmailControllerTest.java index 5d63225..2ccb9be 100644 --- a/src/test/java/com/dsmpear/main/user_backend_v2/EmailControllerTest.java +++ b/src/test/java/com/dsmpear/main/user_backend_v2/EmailControllerTest.java @@ -1,5 +1,7 @@ package com.dsmpear.main.user_backend_v2; +import com.dsmpear.main.user_backend_v2.config.EmbeddedRedisConfig; +import com.dsmpear.main.user_backend_v2.entity.user.UserRepository; import com.dsmpear.main.user_backend_v2.entity.verifynumber.VerifyNumber; import com.dsmpear.main.user_backend_v2.entity.verifynumber.VerifyNumberRepository; import com.dsmpear.main.user_backend_v2.payload.request.EmailVerifyRequest; @@ -10,7 +12,11 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.test.context.TestConfiguration; +import org.springframework.context.annotation.DependsOn; +import org.springframework.context.annotation.Import; import org.springframework.http.MediaType; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.context.junit.jupiter.SpringExtension; @@ -23,6 +29,7 @@ @ExtendWith(SpringExtension.class) @SpringBootTest @ActiveProfiles("test") +@EnableAutoConfiguration public class EmailControllerTest { private MockMvc mvc;