Class ReusableAppUtils
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.util.ReusableAppUtils
-
public final class ReusableAppUtils extends java.lang.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 Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static boolean
closeGlobalApp(org.junit.jupiter.api.extension.ExtensionContext context, java.lang.Class<?> declarationClass)
Do nothing if reusable application not found for provided base class.static java.lang.Class<?>
findDeclarationClass(java.lang.Class<?> test, java.lang.annotation.Annotation ann)
Search for exact class in test class clas hierarchy where annotation was declared.static java.lang.reflect.Field
findExtensionField(java.lang.Class<?> test, GuiceyExtensionsSupport ext)
Search for field in test class hierarchy where extension was declared.static StoredReusableApp
getGlobalApp(org.junit.jupiter.api.extension.ExtensionContext context, java.lang.Class<?> declarationClass)
static org.junit.jupiter.api.extension.ExtensionContext.Store
getGlobalStore(org.junit.jupiter.api.extension.ExtensionContext context)
static void
registerAnnotation(java.lang.Class<?> test, java.lang.annotation.Annotation ann, ExtensionConfig config)
Register reusable app declaration source.static void
registerField(java.lang.Class<?> test, GuiceyExtensionsSupport ext, ExtensionConfig config)
Register reusable app declaration source.static void
registerGlobalApp(org.junit.jupiter.api.extension.ExtensionContext context, StoredReusableApp app)
Stores new application in global context.
-
-
-
Method Detail
-
findDeclarationClass
public static java.lang.Class<?> findDeclarationClass(java.lang.Class<?> test, java.lang.annotation.Annotation ann)
Search for exact class in test class clas hierarchy where annotation was declared.- Parameters:
test
- test classann
- annotation to find- Returns:
- found annotation
- Throws:
java.lang.NullPointerException
- if annotation not foundjava.lang.IllegalStateException
- if declaration is not correct
-
findExtensionField
public static java.lang.reflect.Field findExtensionField(java.lang.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 classext
- extension instance- Returns:
- field declared extension
- Throws:
java.lang.NullPointerException
- if field not foundjava.lang.IllegalStateException
- if declaration is not correct
-
registerField
public static void registerField(java.lang.Class<?> test, GuiceyExtensionsSupport ext, ExtensionConfig config)
Register reusable app declaration source.- Parameters:
test
- test classext
- extension instanceconfig
- extension config
-
registerAnnotation
public static void registerAnnotation(java.lang.Class<?> test, java.lang.annotation.Annotation ann, ExtensionConfig config)
Register reusable app declaration source.- Parameters:
test
- test classann
- extension annotationconfig
- 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, java.lang.Class<?> declarationClass)
- Parameters:
context
- any contextdeclarationClass
- 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 contextapp
- application holder to store
-
closeGlobalApp
public static boolean closeGlobalApp(org.junit.jupiter.api.extension.ExtensionContext context, java.lang.Class<?> declarationClass)
Do nothing if reusable application not found for provided base class.- Parameters:
context
- any contextdeclarationClass
- base test class where reusable app was declared- Returns:
- true if app was closed, false otherwise
-
-