Package fr.ght1pc9kc.testy.redis
Class WithEmbeddedRedis
java.lang.Object
fr.ght1pc9kc.testy.redis.WithEmbeddedRedis
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver,org.junit.jupiter.api.extension.TestInstantiationAwareExtension
public class WithEmbeddedRedis
extends Object
implements org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback, org.junit.jupiter.api.extension.ParameterResolver
Allow to launch en Embedded Redis DB
With
With
Use embedded-redis from codemonstur which seem to be the most maintained fork of the original kstyrc version
From this database, an async RedisServer is created and shared in the context.
This extension allow to injection of :
@RedisPort int redisPort: The redis listening portRedisClient client: The redis lettuce client connected to the embedded serverRedisServer server: The redis server itself
Usage :
With @ExtendWith
@ExtendWith(WithEmbeddedRedis.class)
class WithEmbeddedRedisTest {
@Test
void should_use_embedded_redis(RedisClient client) {
try (StatefulRedisConnection<String, String> conn = client.connect()) {
RedisCommands<String, String> redisCommands = conn.sync();
String actual = redisCommands.set("key", "Hello, Redis!");
}
}
}
With @RegisterExtension
@RegisterExtension
public static WithEmbeddedRedis mockRedis = WithEmbeddedRedis.builder().build();
@Test
void should_use_embedded_redis(RedisClient client) {
try (StatefulRedisConnection<String, String> conn = client.connect()) {
RedisCommands<String, String> redisCommands = conn.sync();
String actual = redisCommands.set("key", "Hello, Redis!");
}
}
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidafterAll(org.junit.jupiter.api.extension.ExtensionContext context) voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) booleansupportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
WithEmbeddedRedis
public WithEmbeddedRedis()
-
-
Method Details
-
beforeAll
- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
Exception
-
afterAll
- Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback- Throws:
Exception
-
supportsParameter
public boolean supportsParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
supportsParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-
resolveParameter
public Object resolveParameter(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws org.junit.jupiter.api.extension.ParameterResolutionException - Specified by:
resolveParameterin interfaceorg.junit.jupiter.api.extension.ParameterResolver- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-