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
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:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
afterAll
(org.junit.jupiter.api.extension.ExtensionContext context) void
beforeAll
(org.junit.jupiter.api.extension.ExtensionContext context) resolveParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext) boolean
supportsParameter
(org.junit.jupiter.api.extension.ParameterContext parameterContext, org.junit.jupiter.api.extension.ExtensionContext extensionContext)
-
Constructor Details
-
WithEmbeddedRedis
public WithEmbeddedRedis()
-
-
Method Details
-
beforeAll
- Specified by:
beforeAll
in interfaceorg.junit.jupiter.api.extension.BeforeAllCallback
- Throws:
Exception
-
afterAll
- Specified by:
afterAll
in 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:
supportsParameter
in 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:
resolveParameter
in interfaceorg.junit.jupiter.api.extension.ParameterResolver
- Throws:
org.junit.jupiter.api.extension.ParameterResolutionException
-