C
- the configuration typepublic class DropwizardAppRule<C extends Configuration>
extends org.junit.rules.ExternalResource
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).
Using DropwizardAppRule at the suite level can speed up test runs, as the application is only started and stopped once for the entire suite:
@RunWith(Suite.class) @SuiteClasses({FooTest.class, BarTest.class}) public class MySuite { @ClassRule public static final DropwizardAppRule<MyConfig> DROPWIZARD = new DropwizardAppRule<>(...); }
If the same instance of DropwizardAppRule is reused at the suite- and class-level, then the application will be started and stopped once, regardless of whether the entire suite or a single test is executed.
public class FooTest { @ClassRule public static final DropwizardAppRule<MyConfig> DROPWIZARD = MySuite.DROPWIZARD; public void testFoo() { ... } } public class BarTest { @ClassRule public static final DropwizardAppRule<MyConfig> DROPWIZARD = MySuite.DROPWIZARD; public void testBar() { ... } }
Modifier and Type | Class and Description |
---|---|
static class |
DropwizardAppRule.ServiceListener<T extends Configuration> |
Constructor and Description |
---|
DropwizardAppRule(Class<? extends Application<C>> applicationClass) |
DropwizardAppRule(Class<? extends Application<C>> applicationClass,
C configuration)
Alternate constructor that allows specifying exact Configuration object to
use, instead of reading a resource and binding it as Configuration object.
|
DropwizardAppRule(Class<? extends Application<C>> applicationClass,
C configuration,
Function<Application<C>,Command> commandInstantiator)
Alternate constructor that allows specifying the command the Dropwizard application is started with.
|
DropwizardAppRule(Class<? extends Application<C>> applicationClass,
String configPath,
ConfigOverride... configOverrides) |
DropwizardAppRule(Class<? extends Application<C>> applicationClass,
String configPath,
Optional<String> customPropertyPrefix,
ConfigOverride... configOverrides) |
DropwizardAppRule(Class<? extends Application<C>> applicationClass,
String configPath,
Optional<String> customPropertyPrefix,
Function<Application<C>,Command> commandInstantiator,
ConfigOverride... configOverrides) |
DropwizardAppRule(DropwizardTestSupport<C> testSupport) |
Modifier and Type | Method and Description |
---|---|
DropwizardAppRule<C> |
addListener(DropwizardAppRule.ServiceListener<C> listener) |
protected void |
after() |
protected void |
before() |
javax.ws.rs.client.Client |
client()
Returns a new HTTP Jersey
Client for performing HTTP requests against the tested
Dropwizard server. |
protected org.glassfish.jersey.client.JerseyClientBuilder |
clientBuilder() |
int |
getAdminPort() |
<A extends Application<C>> |
getApplication() |
C |
getConfiguration() |
Environment |
getEnvironment() |
int |
getLocalPort() |
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
int |
getPort(int connectorIndex) |
DropwizardTestSupport<C> |
getTestSupport() |
DropwizardAppRule<C> |
manage(io.dropwizard.lifecycle.Managed managed) |
Application<C> |
newApplication() |
public DropwizardAppRule(Class<? extends Application<C>> applicationClass)
public DropwizardAppRule(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides)
public DropwizardAppRule(Class<? extends Application<C>> applicationClass, String configPath, Optional<String> customPropertyPrefix, ConfigOverride... configOverrides)
public DropwizardAppRule(Class<? extends Application<C>> applicationClass, String configPath, Optional<String> customPropertyPrefix, Function<Application<C>,Command> commandInstantiator, ConfigOverride... configOverrides)
public DropwizardAppRule(Class<? extends Application<C>> applicationClass, C configuration)
public DropwizardAppRule(Class<? extends Application<C>> applicationClass, C configuration, Function<Application<C>,Command> commandInstantiator)
public DropwizardAppRule(DropwizardTestSupport<C> testSupport)
public DropwizardAppRule<C> addListener(DropwizardAppRule.ServiceListener<C> listener)
public DropwizardAppRule<C> manage(io.dropwizard.lifecycle.Managed managed)
protected void before()
before
in class org.junit.rules.ExternalResource
protected void after()
after
in class org.junit.rules.ExternalResource
public C getConfiguration()
public int getLocalPort()
public int getPort(int connectorIndex)
public int getAdminPort()
public Application<C> newApplication()
public <A extends Application<C>> A getApplication()
public Environment getEnvironment()
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
public DropwizardTestSupport<C> getTestSupport()
public javax.ws.rs.client.Client client()
Client
for performing HTTP requests against the tested
Dropwizard server. The client can be reused across different tests and automatically
closed along with the server. The client can be augmented by overriding the
clientBuilder()
method.Client
managed by the rule.protected org.glassfish.jersey.client.JerseyClientBuilder clientBuilder()
Copyright © 2017. All rights reserved.