public abstract class GuiceyExtensionsSupport extends TestParametersSupport implements org.junit.jupiter.api.extension.TestInstancePostProcessor, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
DropwizardTestSupport object
for actual execution (only configuration differs).
Extensions assumed to be used only on class level: extension will start dropwizard app before all tests and shut down it after all tests. If nested tests used - they also affected. Execution per test is not allowed because these tests are integration tests and they must minimize environment preparation time. Group tests not affecting application state into one class and use different test classes (or nested classes) for tests modifying state.
Test instance is not managed by guice! Only Injector.injectMembers(Object) applied
for it to process test fields injection. Guice AOP can't be used on test methods. Technically, creating test
instances with guice is possible, but in this case nested tests could not work at all, which is unacceptable.
Extension detects static fields of GuiceyConfigurationHook type, annotated with EnableHook
and initialize these hooks automatically. It was done like this to simplify customizations, when main extension
could be declared as annotation and hook as field. Also, it was impossible to implement hooks support
with junit extension. Hook field could be declared even in base test class.
For external integrations (other extensions), there is a special "hack" allowing to access
DropwizardTestSupport object (and so get access to injector): lookupSupport(ExtensionContext).
And shortcuts lookupInjector(ExtensionContext) and lookupClient(ExtensionContext).
for supported test parameters| Constructor and Description |
|---|
GuiceyExtensionsSupport() |
| Modifier and Type | Method and Description |
|---|---|
void |
afterAll(org.junit.jupiter.api.extension.ExtensionContext context) |
void |
beforeAll(org.junit.jupiter.api.extension.ExtensionContext context) |
protected ClientSupport |
getClient(org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
protected static org.junit.jupiter.api.extension.ExtensionContext.Store |
getExtensionStore(org.junit.jupiter.api.extension.ExtensionContext context) |
protected java.util.Optional<com.google.inject.Injector> |
getInjector(org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
protected io.dropwizard.testing.DropwizardTestSupport<?> |
getSupport(org.junit.jupiter.api.extension.ExtensionContext extensionContext) |
static java.util.Optional<ClientSupport> |
lookupClient(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Shortcut for
ClientSupport object lookup by other extensions. |
static java.util.Optional<com.google.inject.Injector> |
lookupInjector(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Shortcut for application injector resolution be used by other extensions.
|
static java.util.Optional<io.dropwizard.testing.DropwizardTestSupport<?>> |
lookupSupport(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Static "hack" for other extensions extending base guicey extensions abilities.
|
protected void |
onShutdown(org.junit.jupiter.api.extension.ExtensionContext context)
Hook to perform additional work after server shutdown.
|
void |
postProcessTestInstance(java.lang.Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context) |
protected abstract io.dropwizard.testing.DropwizardTestSupport<?> |
prepareTestSupport(org.junit.jupiter.api.extension.ExtensionContext context)
The only role of actual extension class is to configure
DropwizardTestSupport object
according to annotated configuration. |
resolveParameter, supportsParameterpublic void postProcessTestInstance(java.lang.Object testInstance,
org.junit.jupiter.api.extension.ExtensionContext context)
throws java.lang.Exception
postProcessTestInstance in interface org.junit.jupiter.api.extension.TestInstancePostProcessorjava.lang.Exceptionpublic void beforeAll(org.junit.jupiter.api.extension.ExtensionContext context)
throws java.lang.Exception
beforeAll in interface org.junit.jupiter.api.extension.BeforeAllCallbackjava.lang.Exceptionpublic void afterAll(org.junit.jupiter.api.extension.ExtensionContext context)
throws java.lang.Exception
afterAll in interface org.junit.jupiter.api.extension.AfterAllCallbackjava.lang.Exceptionpublic static java.util.Optional<io.dropwizard.testing.DropwizardTestSupport<?>> lookupSupport(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
The only thin moment here is extensions order! Junit preserve declaration order so in most cases it should not be a problem.
extensionContext - extension contextpublic static java.util.Optional<com.google.inject.Injector> lookupInjector(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
Custom extension must be activated after main guicey extension!
extensionContext - extension contextpublic static java.util.Optional<ClientSupport> lookupClient(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
ClientSupport object lookup by other extensions.
Custom extension must be activated after main guicey extension!
extensionContext - extension contextprotected abstract io.dropwizard.testing.DropwizardTestSupport<?> prepareTestSupport(org.junit.jupiter.api.extension.ExtensionContext context)
DropwizardTestSupport object
according to annotated configuration.context - extension contextprotected void onShutdown(org.junit.jupiter.api.extension.ExtensionContext context)
context - test contextprotected io.dropwizard.testing.DropwizardTestSupport<?> getSupport(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
getSupport in class TestParametersSupportextensionContext - junit extension contextprotected ClientSupport getClient(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
getClient in class TestParametersSupportextensionContext - junit extension contextprotected java.util.Optional<com.google.inject.Injector> getInjector(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
getInjector in class TestParametersSupportextensionContext - junit extension contextprotected static org.junit.jupiter.api.extension.ExtensionContext.Store getExtensionStore(org.junit.jupiter.api.extension.ExtensionContext context)