Package io.dropwizard.testing
Class DropwizardTestSupport<C extends Configuration>
- java.lang.Object
-
- io.dropwizard.testing.DropwizardTestSupport<C>
-
- Type Parameters:
C
- the configuration type
public class DropwizardTestSupport<C extends Configuration> extends Object
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 thenewApplication()
method to provide your application instance(s).
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
DropwizardTestSupport.ServiceListener<T extends Configuration>
-
Field Summary
Fields Modifier and Type Field Description protected @Nullable Application<C>
application
protected Class<? extends Application<C>>
applicationClass
protected Function<Application<C>,Command>
commandInstantiator
protected Set<ConfigOverride>
configOverrides
protected @Nullable String
configPath
protected @Nullable ConfigurationSourceProvider
configSourceProvider
protected @Nullable C
configuration
protected @Nullable String
customPropertyPrefix
protected @Nullable Environment
environment
protected boolean
explicitConfig
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
jettyServer
protected List<DropwizardTestSupport.ServiceListener<C>>
listeners
-
Constructor Summary
Constructors Constructor Description 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.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
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DropwizardTestSupport<C>
addListener(DropwizardTestSupport.ServiceListener<C> listener)
void
after()
void
before()
int
getAdminPort()
<A extends Application<C>>
AgetApplication()
C
getConfiguration()
Environment
getEnvironment()
int
getLocalPort()
com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
int
getPort(int connectorIndex)
DropwizardTestSupport<C>
manage(Managed managed)
Application<C>
newApplication()
-
-
-
Field Detail
-
applicationClass
protected final Class<? extends Application<C extends Configuration>> applicationClass
-
configPath
protected final @Nullable String configPath
-
configSourceProvider
protected final @Nullable ConfigurationSourceProvider configSourceProvider
-
configOverrides
protected final Set<ConfigOverride> configOverrides
-
customPropertyPrefix
protected final @Nullable String customPropertyPrefix
-
commandInstantiator
protected final Function<Application<C extends Configuration>,Command> commandInstantiator
-
explicitConfig
protected final boolean explicitConfig
Flag 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
protected @Nullable C extends Configuration configuration
-
application
protected @Nullable Application<C extends Configuration> application
-
environment
protected @Nullable Environment environment
-
jettyServer
protected @Nullable org.eclipse.jetty.server.Server jettyServer
-
listeners
protected List<DropwizardTestSupport.ServiceListener<C extends Configuration>> listeners
-
-
Constructor Detail
-
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
public 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.- 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 Detail
-
addListener
public DropwizardTestSupport<C> addListener(DropwizardTestSupport.ServiceListener<C> listener)
-
manage
public DropwizardTestSupport<C> manage(Managed managed)
-
after
public void after()
-
getConfiguration
public C getConfiguration()
-
getLocalPort
public int getLocalPort()
-
getAdminPort
public int getAdminPort()
-
getPort
public int getPort(int connectorIndex)
-
newApplication
public Application<C> newApplication()
-
getApplication
public <A extends Application<C>> A getApplication()
-
getEnvironment
public Environment getEnvironment()
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
-