Package io.dropwizard.testing
Class DropwizardTestSupport<C extends 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 class
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected @Nullable Application<C>
protected final Class<? extends Application<C>>
protected final Function<Application<C>,
Command> protected final Set<ConfigOverride>
protected final @Nullable String
protected final @Nullable ConfigurationSourceProvider
protected @Nullable C
protected final @Nullable String
protected @Nullable Environment
protected final boolean
Flag 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.Server
protected List<DropwizardTestSupport.ServiceListener<C>>
-
Constructor Summary
ConstructorsConstructorDescriptionDropwizardTestSupport
(Class<? extends Application<C>> applicationClass, @Nullable C configuration, Function<Application<C>, Command> commandInstantiator) Alternate constructor that allows specifying the command the Dropwizard application is started with.DropwizardTestSupport
(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) DropwizardTestSupport
(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, Function<Application<C>, Command> commandInstantiator, ConfigOverride... configOverrides) DropwizardTestSupport
(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable ConfigurationSourceProvider configSourceProvider, ConfigOverride... configOverrides) DropwizardTestSupport
(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) DropwizardTestSupport
(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, Function<Application<C>, Command> commandInstantiator, ConfigOverride... configOverrides) DropwizardTestSupport
(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides) DropwizardTestSupport
(Class<? extends 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) void
after()
void
before()
int
<A extends Application<C>>
Aint
com.fasterxml.jackson.databind.ObjectMapper
int
getPort
(int connectorIndex)
-
Field Details
-
applicationClass
-
configPath
-
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 ofconfiguration
changes during lifecycle. -
configuration
-
application
-
environment
-
jettyServer
protected @Nullable org.eclipse.jetty.server.Server jettyServer -
listeners
-
-
Constructor Details
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides) -
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable ConfigurationSourceProvider configSourceProvider, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, Function<Application<C>, Command> commandInstantiator, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
public DropwizardTestSupport(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, Function<Application<C>, Command> commandInstantiator, ConfigOverride... configOverrides) - Since:
- 2.0
-
DropwizardTestSupport
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 Application<C>> applicationClass, @Nullable C configuration, Function<Application<C>, Command> commandInstantiator) Alternate constructor that allows specifying the command the Dropwizard application is started with.
-
-
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
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-