Class TestDropwizardAppExtension
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.jupiter.ext.TestParametersSupport
-
- ru.vyarus.dropwizard.guice.test.jupiter.ext.GuiceyExtensionsSupport
-
- ru.vyarus.dropwizard.guice.test.jupiter.ext.TestDropwizardAppExtension
-
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback
,org.junit.jupiter.api.extension.BeforeAllCallback
,org.junit.jupiter.api.extension.BeforeEachCallback
,org.junit.jupiter.api.extension.Extension
,org.junit.jupiter.api.extension.ParameterResolver
public class TestDropwizardAppExtension extends GuiceyExtensionsSupport
TestDropwizardApp
junit 5 extension implementation. Normally, extension should be activated with annotation, but in some cases manual registration may be used:
This is complete equivalent of annotation declaration! Static modifier is important! There is no additional methods in extension (intentionally), so registration type changes nothing in usage.@RegisterExtension static TestDropwizardAppExtension app = TestDropwizardAppExtension.forApp(MyApp.class).create()
Reasons why it could be used instead of annotation:
- Incorrect execution order with some other extensions. Manually registered extension will execute after(!) all class level registrations (junit native behaviour). So moving guicey extension to manual registration may guarantee its execution after some other extension.
- Manual registration allows short hook declarations with lambdas:
.hooks(builder -> builder.modules(new DebugGuiceModule()))
- Config overrides registration as
ConfigOverride
objects (required for delayed evaluated values: e.g. when it is obtained from some other junit extension)
You can't use manual registration to configure multiple applications because junit allows only one extension instance (if you really need to use multiple applications in tests then register one with extension and for another use
DropwizardTestSupport
directly).If both declarations will be used at the same class (don't do that!) then annotation will win and manual registration will be ignored (junit default behaviour).
Other extensions requiring access to dropwizard application may use
GuiceyExtensionsSupport.lookupSupport(ExtensionContext)
.- Since:
- 28.04.2020
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
TestDropwizardAppExtension.Builder
Builder used for manual extension registration (forApp(Class)
).
-
Constructor Summary
Constructors Constructor Description TestDropwizardAppExtension()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static TestDropwizardAppExtension.Builder
forApp(java.lang.Class<? extends io.dropwizard.Application> app)
Builder for manual extension registration withRegisterExtension
.protected io.dropwizard.testing.DropwizardTestSupport<?>
prepareTestSupport(org.junit.jupiter.api.extension.ExtensionContext context)
The only role of actual extension class is to configureDropwizardTestSupport
object according to annotated configuration.-
Methods inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.GuiceyExtensionsSupport
afterAll, beforeAll, beforeEach, getClient, getExtensionStore, getInjector, getSupport, lookupClient, lookupInjector, lookupSupport, onShutdown
-
Methods inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.TestParametersSupport
resolveParameter, supportsParameter
-
-
-
-
Method Detail
-
forApp
public static TestDropwizardAppExtension.Builder forApp(java.lang.Class<? extends io.dropwizard.Application> app)
Builder for manual extension registration withRegisterExtension
. Provides the same configuration options asTestDropwizardApp
annotation (annotation considered as preferred usage way).IMPORTANT: extension must be used with static field only! You can't register multiple extensions!
This is just a different way of extension configuration! Resulted extension object does not provide any additional methods (and not intended to be used at all)!
Pure
DropwizardTestSupport
provides an ability to register customManaged
or listenerDropwizardTestSupport.addListener(DropwizardTestSupport.ServiceListener)
. If you need these then useTestDropwizardAppExtension.Builder.hooks(GuiceyConfigurationHook...)
to register additional managed object or additional dropwizard or guicey bundle (which will be the same as listener above).- Parameters:
app
- application class- Returns:
- builder for extension configuration.
-
prepareTestSupport
protected io.dropwizard.testing.DropwizardTestSupport<?> prepareTestSupport(org.junit.jupiter.api.extension.ExtensionContext context)
Description copied from class:GuiceyExtensionsSupport
The only role of actual extension class is to configureDropwizardTestSupport
object according to annotated configuration.- Specified by:
prepareTestSupport
in classGuiceyExtensionsSupport
- Parameters:
context
- extension context- Returns:
- configured dropwizard test support object
-
-