Class TestExtension
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.jupiter.ext.conf.ExtensionBuilder<io.dropwizard.core.Configuration,TestExtension,ExtensionConfig>
-
- ru.vyarus.dropwizard.guice.test.jupiter.env.TestExtension
-
public class TestExtension extends ExtensionBuilder<io.dropwizard.core.Configuration,TestExtension,ExtensionConfig>
Configuration object forTestEnvironmentSetupobjects.- Since:
- 15.05.2022
-
-
Field Summary
-
Fields inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.conf.ExtensionBuilder
cfg
-
-
Constructor Summary
Constructors Constructor Description TestExtension(ExtensionConfig cfg, org.junit.jupiter.api.extension.ExtensionContext context, ListenersSupport listeners)Create extension.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <A extends java.lang.annotation.Annotation,T>
java.util.List<AnnotatedField<A,T>>findAnnotatedFields(java.lang.Class<A> annotation, java.lang.Class<T> requiredFieldType)Search for annotated fields with validation (a field type must be assignable to provided type).org.junit.jupiter.api.extension.ExtensionContextgetJunitContext()This might be class or method context ("before all" or "before each"), depending on how guicey extension would be registered: in case of registration with a non-static field "before all" not called.booleanisApplicationStartedForClass()Shortcut to simplify detection on what phase extension was created: beforeAll or beforeEach.booleanisDebug()Useful to bind debug options on the extension debug (no need for additional keys).TestExtensionlisten(TestExecutionListener listener)Listen for test lifecycle.TestExtensiononAfterAll(LambdaTestListener listener)TestExtensiononAfterEach(LambdaTestListener listener)TestExtensiononApplicationStart(LambdaTestListener listener)TestExtensiononApplicationStarting(LambdaTestListener listener)TestExtensiononApplicationStop(LambdaTestListener listener)TestExtensiononApplicationStopping(LambdaTestListener listener)TestExtensiononBeforeAll(LambdaTestListener listener)TestExtensiononBeforeEach(LambdaTestListener listener)-
Methods inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.conf.ExtensionBuilder
clientFactory, config, configModifiers, configModifiers, configOverride, configOverride, configOverrideByExtension, configOverrideByExtension, configOverrides, configOverrides, debug, disableDefaultExtensions, hooks, hooks, injectOnce, reuseApplication, with
-
-
-
-
Constructor Detail
-
TestExtension
public TestExtension(ExtensionConfig cfg, org.junit.jupiter.api.extension.ExtensionContext context, ListenersSupport listeners)
Create extension.- Parameters:
cfg- configcontext- junit contextlisteners- listeners support
-
-
Method Detail
-
isDebug
public boolean isDebug()
Useful to bind debug options on the extension debug (no need for additional keys).- Returns:
- true if debug is enabled on guicey extension
-
isApplicationStartedForClass
public boolean isApplicationStartedForClass()
Shortcut to simplify detection on what phase extension was created: beforeAll or beforeEach.- Returns:
- true if application started once per test class, false if application started for each test method
-
getJunitContext
public org.junit.jupiter.api.extension.ExtensionContext getJunitContext()
This might be class or method context ("before all" or "before each"), depending on how guicey extension would be registered: in case of registration with a non-static field "before all" not called.Note that guicey provide static method for accessing objects, stored in context, like:
GuiceyExtensionsSupport.lookupSupport( org.junit.jupiter.api.extension.ExtensionContext)orGuiceyExtensionsSupport.lookupInjector( org.junit.jupiter.api.extension.ExtensionContext).- Returns:
- test extension context
-
listen
public TestExtension listen(TestExecutionListener listener)
Listen for test lifecycle. Useful when not only resource close is required (achievable by returning a closable object from setup), but writing a separate junit extension is not desirable. Moreover, this listener is synchronized with guicey extension lifecycle.Listener could also be registered with lambdas using on* methods like
onApplicationStart(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.lambda.LambdaTestListener). Lambda version might be more convenient in case when setup object is a lambda itself.- Parameters:
listener- listener object- Returns:
- builder instance for chained calls
-
onApplicationStarting
public TestExtension onApplicationStarting(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.starting( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called before application start (could be beforeAll (default) or beforeEach phase)- Returns:
- builder instance for chained calls
-
onApplicationStart
public TestExtension onApplicationStart(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.started( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called after application start (could be beforeAll (default) or beforeEach phase)- Returns:
- builder instance for chained calls
-
onBeforeAll
public TestExtension onBeforeAll(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.beforeAll( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called (might not be called!) before all test methods- Returns:
- builder instance for chained calls
-
onBeforeEach
public TestExtension onBeforeEach(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.beforeEach( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called before each test method- Returns:
- builder instance for chained calls
-
onAfterEach
public TestExtension onAfterEach(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.afterEach( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called after each test method- Returns:
- builder instance for chained calls
-
onAfterAll
public TestExtension onAfterAll(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.afterAll( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called (might not be called!) after all test methods- Returns:
- builder instance for chained calls
-
onApplicationStopping
public TestExtension onApplicationStopping(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.stopping( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called before application stop (could be afterAll (default) or afterEach phase)- Returns:
- builder instance for chained calls
-
onApplicationStop
public TestExtension onApplicationStop(LambdaTestListener listener)
Lambda version oflisten(ru.vyarus.dropwizard.guice.test.jupiter.env.listen.TestExecutionListener)forTestExecutionListener.stopped( ru.vyarus.dropwizard.guice.test.jupiter.env.listen.EventContext). Lambda listener version is more useful in case when setup object is declared as a lambda itself.Might be called multiple times.
- Parameters:
listener- listener called after application stop (could be afterAll (default) or afterEach phase)- Returns:
- builder instance for chained calls
-
findAnnotatedFields
public <A extends java.lang.annotation.Annotation,T> java.util.List<AnnotatedField<A,T>> findAnnotatedFields(java.lang.Class<A> annotation, java.lang.Class<T> requiredFieldType)
Search for annotated fields with validation (a field type must be assignable to provided type).- Type Parameters:
A- annotation typeT- required filed minimal type- Parameters:
annotation- annotation to searchrequiredFieldType- required field type- Returns:
- annotated test fields (including fields from base test class).
-
-