Class ReusableAppUtils

java.lang.Object
ru.vyarus.dropwizard.guice.test.util.ReusableAppUtils

public final class ReusableAppUtils extends Object
Reusable application support for tests. Reusable application must be declared in base test class (preferably abstract) to guarantee that all derived tests would use THE SAME extension declaration.

Reusable application stored in root context under spacial key: base test class name. DW_SUPPORT key can't be used because root storage is visible by all tests, but only some of them could extend base class and so should actually use global application. Moreover, there might be multiple reusable applications used (when multiple base classes used with reusable application declaration).

Global application would be started by the first test and shut down after all tests execution (automatically on storage close).

There is an additional api for extensions to be able to close reusable application: GuiceyExtensionsSupport.closeReusableApp(org.junit.jupiter.api.extension.ExtensionContext).

Since:
19.12.2022
  • Method Details

    • findDeclarationClass

      public static Class<?> findDeclarationClass(Class<?> test, Annotation ann)
      Search for exact class in test class clas hierarchy where annotation was declared.
      Parameters:
      test - test class
      ann - annotation to find
      Returns:
      found annotation
      Throws:
      NullPointerException - if annotation not found
      IllegalStateException - if declaration is not correct
    • findExtensionField

      public static Field findExtensionField(Class<?> test, GuiceyExtensionsSupport ext)
      Search for field in test class hierarchy where extension was declared.

      Field would not be found if extension declared in non-static field.

      Parameters:
      test - test class
      ext - extension instance
      Returns:
      field declared extension
      Throws:
      NullPointerException - if field not found
      IllegalStateException - if declaration is not correct
    • registerField

      public static void registerField(Class<?> test, GuiceyExtensionsSupport ext, ExtensionConfig config)
      Register reusable app declaration source.
      Parameters:
      test - test class
      ext - extension instance
      config - extension config
    • registerAnnotation

      public static void registerAnnotation(Class<?> test, Annotation ann, ExtensionConfig config)
      Register reusable app declaration source.
      Parameters:
      test - test class
      ann - extension annotation
      config - extension config
    • getGlobalStore

      public static org.junit.jupiter.api.extension.ExtensionContext.Store getGlobalStore(org.junit.jupiter.api.extension.ExtensionContext context)
      Parameters:
      context - any context
      Returns:
      global store where reusable application must be stored
    • getGlobalApp

      public static StoredReusableApp getGlobalApp(org.junit.jupiter.api.extension.ExtensionContext context, Class<?> declarationClass)
      Parameters:
      context - any context
      declarationClass - base test class where reusable app was declared
      Returns:
      reusable app holder or null
    • registerGlobalApp

      public static void registerGlobalApp(org.junit.jupiter.api.extension.ExtensionContext context, StoredReusableApp app)
      Stores new application in global context.
      Parameters:
      context - any context
      app - application holder to store
    • closeGlobalApp

      public static boolean closeGlobalApp(org.junit.jupiter.api.extension.ExtensionContext context, Class<?> declarationClass)
      Do nothing if reusable application not found for provided base class.
      Parameters:
      context - any context
      declarationClass - base test class where reusable app was declared
      Returns:
      true if app was closed, false otherwise