Package io.dropwizard.testing
Class DropwizardTestSupport<C extends io.dropwizard.core.Configuration>
java.lang.Object
io.dropwizard.testing.DropwizardTestSupport<C>
- Type Parameters:
C- the configuration type
A test support class for starting and stopping your application at the start and end of a test class.
By default, the Application will be constructed using reflection to invoke the nullary
constructor. If your application does not provide a public nullary constructor, you will need to
override the newApplication() method to provide your application instance(s).
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classDropwizardTestSupport.ServiceListener<T extends io.dropwizard.core.Configuration> -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable io.dropwizard.core.Application<C>protected final Set<ConfigOverride>protected final @Nullable Stringprotected final @Nullable io.dropwizard.configuration.ConfigurationSourceProviderprotected @Nullable Cprotected final @Nullable Stringprotected @Nullable io.dropwizard.core.setup.Environmentprotected final booleanFlag that indicates whether instance was constructed with an explicit Configuration object or not; handling of the two cases differ.protected @Nullable org.eclipse.jetty.server.Serverprotected List<DropwizardTestSupport.ServiceListener<C>> -
Constructor Summary
ConstructorsConstructorDescriptionDropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable C configuration, Function<io.dropwizard.core.Application<C>, io.dropwizard.core.cli.Command> commandInstantiator) Alternate constructor that allows specifying the command the Dropwizard application is started with.DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, Function<io.dropwizard.core.Application<C>, io.dropwizard.core.cli.Command> commandInstantiator, ConfigOverride... configOverrides) DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, ConfigOverride... configOverrides) DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, Function<io.dropwizard.core.Application<C>, io.dropwizard.core.cli.Command> commandInstantiator, ConfigOverride... configOverrides) DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides) DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, C configuration) Alternative constructor that may be used to directly provide Configuration to use, instead of specifying resource path for locating data to create Configuration. -
Method Summary
Modifier and TypeMethodDescriptionaddListener(DropwizardTestSupport.ServiceListener<C> listener) voidafter()voidbefore()int<A extends io.dropwizard.core.Application<C>>
Aio.dropwizard.core.setup.Environmentintcom.fasterxml.jackson.databind.ObjectMapperintgetPort(int connectorIndex) manage(io.dropwizard.lifecycle.Managed managed) io.dropwizard.core.Application<C>
-
Field Details
-
applicationClass
-
configPath
-
configSourceProvider
protected final @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider -
configOverrides
-
customPropertyPrefix
-
commandInstantiator
-
explicitConfig
protected final boolean explicitConfigFlag that indicates whether instance was constructed with an explicit Configuration object or not; handling of the two cases differ. Needed because state ofconfigurationchanges during lifecycle. -
configuration
-
application
protected @Nullable io.dropwizard.core.Application<C extends io.dropwizard.core.Configuration> application -
environment
protected @Nullable io.dropwizard.core.setup.Environment environment -
jettyServer
protected @Nullable org.eclipse.jetty.server.Server jettyServer -
listeners
protected List<DropwizardTestSupport.ServiceListener<C extends io.dropwizard.core.Configuration>> listeners
-
-
Constructor Details
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides) -
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, Function<io.dropwizard.core.Application<C>, io.dropwizard.core.cli.Command> commandInstantiator, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, Function<io.dropwizard.core.Application<C>, io.dropwizard.core.cli.Command> commandInstantiator, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, C configuration) Alternative constructor that may be used to directly provide Configuration to use, instead of specifying resource path for locating data to create Configuration.- Parameters:
applicationClass- Type of Application to createconfiguration- Pre-constructed configuration object caller provides; will not be manipulated in any way, no overriding- Since:
- 0.9
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable C configuration, Function<io.dropwizard.core.Application<C>, io.dropwizard.core.cli.Command> commandInstantiator) Alternate constructor that allows specifying the command the Dropwizard application is started with.- Parameters:
applicationClass- Type of Application to createconfiguration- Pre-constructed configuration object caller provides; will not be manipulated in any way, no overridingcommandInstantiator- TheFunctionused to instantiate theCommandused to start the Application- Since:
- 1.1.0
-
-
Method Details
-
addListener
-
manage
-
before
- Throws:
Exception
-
after
public void after() -
getConfiguration
-
getLocalPort
public int getLocalPort() -
getAdminPort
public int getAdminPort() -
getPort
public int getPort(int connectorIndex) -
newApplication
-
getApplication
-
getEnvironment
public io.dropwizard.core.setup.Environment getEnvironment() -
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-