From 421d0968395120f6ccb3bc8d49af42fe07890a19 Mon Sep 17 00:00:00 2001 From: Nikita Koksharov Date: Mon, 18 Mar 2024 08:06:07 +0300 Subject: [PATCH] refactoring --- redisson-spring-boot-starter/pom.xml | 6 ++++++ .../starter/RedissonAutoConfiguration2Test.java | 10 ++++++++++ .../starter/RedissonAutoConfigurationTest.java | 9 +++++++++ .../RedissonCacheManagerAutoConfigurationTest.java | 9 +++++++++ .../RedissonSessionManagerAutoConfigurationTest.java | 12 +++++++++++- 5 files changed, 45 insertions(+), 1 deletion(-) diff --git a/redisson-spring-boot-starter/pom.xml b/redisson-spring-boot-starter/pom.xml index 7a8acad32..33e9d57fa 100644 --- a/redisson-spring-boot-starter/pom.xml +++ b/redisson-spring-boot-starter/pom.xml @@ -152,6 +152,12 @@ test + + org.testcontainers + junit-jupiter + test + + ch.qos.logback logback-classic diff --git a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfiguration2Test.java b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfiguration2Test.java index a3b23f645..6a8f40ea7 100644 --- a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfiguration2Test.java +++ b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfiguration2Test.java @@ -13,14 +13,24 @@ import org.springframework.context.annotation.Import; import org.springframework.data.redis.core.BoundHashOperations; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.testcontainers.containers.FixedHostPortGenericContainer; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import static org.assertj.core.api.Assertions.assertThat; @SpringJUnitConfig @SpringBootTest(classes = RedissonApplication.class) @Import(RedissonAutoConfiguration2Test.RedissonConnectionDetailsConfig.class) +@Testcontainers public class RedissonAutoConfiguration2Test { + @Container + public static final GenericContainer REDIS = new FixedHostPortGenericContainer("redis:latest") + .withFixedExposedPort(6379, 6379); + + @TestConfiguration static class RedissonConnectionDetailsConfig { diff --git a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfigurationTest.java b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfigurationTest.java index ca1d02725..e3880606e 100644 --- a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfigurationTest.java +++ b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonAutoConfigurationTest.java @@ -9,6 +9,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.data.redis.core.BoundHashOperations; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.testcontainers.containers.FixedHostPortGenericContainer; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import static org.assertj.core.api.Assertions.assertThat; @@ -19,8 +23,13 @@ import static org.assertj.core.api.Assertions.assertThat; "spring.redis.redisson.file=classpath:redisson.yaml", "spring.redis.timeout=10000" }) +@Testcontainers public class RedissonAutoConfigurationTest { + @Container + public static final GenericContainer REDIS = new FixedHostPortGenericContainer("redis:latest") + .withFixedExposedPort(6379, 6379); + @Autowired private RedissonClient redisson; diff --git a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonCacheManagerAutoConfigurationTest.java b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonCacheManagerAutoConfigurationTest.java index 17d8d1b07..07602bb9b 100644 --- a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonCacheManagerAutoConfigurationTest.java +++ b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonCacheManagerAutoConfigurationTest.java @@ -7,6 +7,10 @@ import org.springframework.boot.test.context.SpringBootTest; import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.testcontainers.containers.FixedHostPortGenericContainer; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; @SpringJUnitConfig @SpringBootTest( @@ -16,8 +20,13 @@ import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; "spring.redis.timeout=10000", "spring.cache.type=redis", }) +@Testcontainers public class RedissonCacheManagerAutoConfigurationTest { + @Container + public static final GenericContainer REDIS = new FixedHostPortGenericContainer("redis:latest") + .withFixedExposedPort(6379, 6379); + @Autowired private CacheManager cacheManager; diff --git a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonSessionManagerAutoConfigurationTest.java b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonSessionManagerAutoConfigurationTest.java index c827cfa13..57a8efb02 100644 --- a/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonSessionManagerAutoConfigurationTest.java +++ b/redisson-spring-boot-starter/src/test/java/org/redisson/spring/starter/RedissonSessionManagerAutoConfigurationTest.java @@ -11,6 +11,10 @@ import org.springframework.http.HttpHeaders; import org.springframework.http.HttpMethod; import org.springframework.http.ResponseEntity; import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; +import org.testcontainers.containers.FixedHostPortGenericContainer; +import org.testcontainers.containers.GenericContainer; +import org.testcontainers.junit.jupiter.Container; +import org.testcontainers.junit.jupiter.Testcontainers; import java.util.List; @@ -23,9 +27,15 @@ import java.util.List; "spring.session.store-type=redis", // "spring.session.timeout.seconds=900", }) +@Testcontainers public class RedissonSessionManagerAutoConfigurationTest { - @LocalServerPort + @Container + public static final GenericContainer REDIS = new FixedHostPortGenericContainer("redis:latest") + .withFixedExposedPort(6379, 6379); + + + @LocalServerPort private int port; @Autowired