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

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 port
  • RedisClient client: The redis lettuce client connected to the embedded server
  • RedisServer server: The redis server itself

Usage : Link icon

With @ExtendWith Link icon


  @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 Link icon


 @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 Link icon

    Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension Link icon

    org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope
  • Constructor Summary Link icon

    Constructors
    Constructor
    Description
     
  • Method Summary Link icon

    Modifier and Type
    Method
    Description
    void
    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)
     

    Methods inherited from class java.lang.Object Link icon

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension Link icon

    getTestInstantiationExtensionContextScope
  • Constructor Details Link icon

    • WithEmbeddedRedis Link icon

      public WithEmbeddedRedis()
  • Method Details Link icon

    • beforeAll Link icon

      public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallback
      Throws:
      Exception
    • afterAll Link icon

      public void afterAll(org.junit.jupiter.api.extension.ExtensionContext context) throws Exception
      Specified by:
      afterAll in interface org.junit.jupiter.api.extension.AfterAllCallback
      Throws:
      Exception
    • supportsParameter Link icon

      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 interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException
    • resolveParameter Link icon

      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 interface org.junit.jupiter.api.extension.ParameterResolver
      Throws:
      org.junit.jupiter.api.extension.ParameterResolutionException