Class TestDropwizardAppExtension
- All Implemented Interfaces:
org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.AfterEachCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.BeforeEachCallback,org.junit.jupiter.api.extension.Extension,org.junit.jupiter.api.extension.ParameterResolver,org.junit.jupiter.api.extension.TestInstantiationAwareExtension
TestDropwizardApp junit 5 extension implementation. Normally, extension should be activated with annotation,
but in some cases manual registration may be used:
@RegisterExtension
static TestDropwizardAppExtension app = TestDropwizardAppExtension.forApp(MyApp.class).create()
Registration in static field is complete equivalent of annotation declaration! When registered in non-static field,
application would be started for each test method.
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
ConfigOverrideobjects (required for delayed evaluated values: e.g. when it is obtained from some other junit extension) - Per-method application startup (for non-static field)
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 or TestSupport utility).
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 ClassesModifier and TypeClassDescriptionstatic classTestDropwizardAppExtension.Builder<C extends io.dropwizard.core.Configuration>Builder used for manual extension registration (forApp(Class)).Nested classes/interfaces inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
org.junit.jupiter.api.extension.TestInstantiationAwareExtension.ExtensionContextScope -
Field Summary
Fields inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.GuiceyExtensionsSupport
listeners, tracker -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <C extends io.dropwizard.core.Configuration>
TestDropwizardAppExtension.Builder<C>Builder for manual extension registration withRegisterExtension.protected ExtensionConfiggetConfig(org.junit.jupiter.api.extension.ExtensionContext context) Returns existing config or parse it from annotation.protected io.dropwizard.testing.DropwizardTestSupport<?>prepareTestSupport(String configPrefix, org.junit.jupiter.api.extension.ExtensionContext context, List<TestEnvironmentSetup> setups) The only role of actual extension class is to configureDropwizardTestSupportobject according to annotation.Methods inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.GuiceyExtensionsSupport
afterAll, afterEach, beforeAll, beforeEach, closeReusableApp, getClient, getExtensionStore, getInjector, getSupport, isReusableAppUsed, lookupClient, lookupInjector, lookupSupportMethods inherited from class ru.vyarus.dropwizard.guice.test.jupiter.ext.TestParametersSupport
resolveParameter, supportsParameterMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.junit.jupiter.api.extension.TestInstantiationAwareExtension
getTestInstantiationExtensionContextScope
-
Constructor Details
-
TestDropwizardAppExtension
public TestDropwizardAppExtension()Create extension.
-
-
Method Details
-
forApp
public static <C extends io.dropwizard.core.Configuration> TestDropwizardAppExtension.Builder<C> forApp(Class<? extends io.dropwizard.core.Application<C>> app) Builder for manual extension registration withRegisterExtension. Provides the same configuration options asTestDropwizardAppannotation (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
DropwizardTestSupportprovides an ability to register customManagedor listenerDropwizardTestSupport.addListener(DropwizardTestSupport.ServiceListener). If you need these then useExtensionBuilder.hooks(GuiceyConfigurationHook...)to register additional managed object or additional dropwizard or guicey bundle (which will be the same as listener above).- Type Parameters:
C- configuration type- Parameters:
app- application class- Returns:
- builder for extension configuration.
-
getConfig
Description copied from class:GuiceyExtensionsSupportReturns existing config or parse it from annotation.Separate configuration creation is important for application re-use logic when additional actions from
GuiceyExtensionsSupport.prepareTestSupport(String, org.junit.jupiter.api.extension.ExtensionContext, java.util.List)should be omitted in case if context already created.- Specified by:
getConfigin classGuiceyExtensionsSupport- Parameters:
context- extension context- Returns:
- extension configuration
-
prepareTestSupport
protected io.dropwizard.testing.DropwizardTestSupport<?> prepareTestSupport(String configPrefix, org.junit.jupiter.api.extension.ExtensionContext context, List<TestEnvironmentSetup> setups) Description copied from class:GuiceyExtensionsSupportThe only role of actual extension class is to configureDropwizardTestSupportobject according to annotation.- Specified by:
prepareTestSupportin classGuiceyExtensionsSupport- Parameters:
configPrefix- configuration properties prefixcontext- extension contextsetups- setup extensions resolved from fields (or empty list)- Returns:
- configured dropwizard test support object
-