Package io.dropwizard.testing.junit5
Class DropwizardAppExtension<C extends Configuration>
- java.lang.Object
-
- io.dropwizard.testing.junit5.DropwizardAppExtension<C>
-
- Type Parameters:
C- the configuration type
- All Implemented Interfaces:
DropwizardExtension,org.junit.jupiter.api.extension.AfterAllCallback,org.junit.jupiter.api.extension.BeforeAllCallback,org.junit.jupiter.api.extension.Extension
public class DropwizardAppExtension<C extends Configuration> extends Object implements DropwizardExtension, org.junit.jupiter.api.extension.BeforeAllCallback, org.junit.jupiter.api.extension.AfterAllCallback
An extension for starting and stopping your application at the start and end of a test class.By default, the
Applicationwill 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 classDropwizardAppExtension.ServiceListener<T extends Configuration>
-
Constructor Summary
Constructors Constructor Description DropwizardAppExtension(DropwizardTestSupport<C> testSupport)DropwizardAppExtension(Class<? extends Application<C>> applicationClass)DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides)DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, Function<Application<C>,Command> commandInstantiator, ConfigOverride... configOverrides)DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides)DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, Function<Application<C>,Command> commandInstantiator, ConfigOverride... configOverrides)DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigurationSourceProvider configSourceProvider, ConfigOverride... configOverrides)DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides)DropwizardAppExtension(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.DropwizardAppExtension(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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description DropwizardAppExtension<C>addListener(DropwizardAppExtension.ServiceListener<C> listener)voidafter()Executed after test method or class.voidafterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)voidbefore()Executed before test method or class.voidbeforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)javax.ws.rs.client.Clientclient()Returns a new HTTP JerseyClientfor performing HTTP requests against the tested Dropwizard server.protected org.glassfish.jersey.client.JerseyClientBuilderclientBuilder()intgetAdminPort()<A extends Application<C>>
AgetApplication()CgetConfiguration()EnvironmentgetEnvironment()intgetLocalPort()com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()intgetPort(int connectorIndex)DropwizardTestSupport<C>getTestSupport()DropwizardAppExtension<C>manage(Managed managed)Application<C>newApplication()
-
-
-
Constructor Detail
-
DropwizardAppExtension
public DropwizardAppExtension(Class<? extends Application<C>> applicationClass)
-
DropwizardAppExtension
public DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides)
-
DropwizardAppExtension
public DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigurationSourceProvider configSourceProvider, ConfigOverride... configOverrides)
- Since:
- 2.0
-
DropwizardAppExtension
public DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides)
- Since:
- 2.0
-
DropwizardAppExtension
public DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides)
- Since:
- 2.0
-
DropwizardAppExtension
public DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, Function<Application<C>,Command> commandInstantiator, ConfigOverride... configOverrides)
-
DropwizardAppExtension
public DropwizardAppExtension(Class<? extends Application<C>> applicationClass, @Nullable String configPath, ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, Function<Application<C>,Command> commandInstantiator, ConfigOverride... configOverrides)
-
DropwizardAppExtension
public DropwizardAppExtension(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.- Since:
- 0.9
-
DropwizardAppExtension
public DropwizardAppExtension(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.- Since:
- 1.1.0
-
DropwizardAppExtension
public DropwizardAppExtension(DropwizardTestSupport<C> testSupport)
-
-
Method Detail
-
addListener
public DropwizardAppExtension<C> addListener(DropwizardAppExtension.ServiceListener<C> listener)
-
manage
public DropwizardAppExtension<C> manage(Managed managed)
-
beforeAll
public void beforeAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext) throws Exception- Specified by:
beforeAllin interfaceorg.junit.jupiter.api.extension.BeforeAllCallback- Throws:
Exception
-
afterAll
public void afterAll(org.junit.jupiter.api.extension.ExtensionContext extensionContext)
- Specified by:
afterAllin interfaceorg.junit.jupiter.api.extension.AfterAllCallback
-
before
public void before() throws ExceptionDescription copied from interface:DropwizardExtensionExecuted before test method or class.- Specified by:
beforein interfaceDropwizardExtension- Throws:
Exception
-
after
public void after()
Description copied from interface:DropwizardExtensionExecuted after test method or class.- Specified by:
afterin interfaceDropwizardExtension
-
getConfiguration
public C getConfiguration()
-
getLocalPort
public int getLocalPort()
-
getPort
public int getPort(int connectorIndex)
-
getAdminPort
public int getAdminPort()
-
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()
-
getTestSupport
public DropwizardTestSupport<C> getTestSupport()
-
client
public javax.ws.rs.client.Client client()
Returns a new HTTP JerseyClientfor 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 theclientBuilder()method.- Returns:
- a new
Clientmanaged by the extension.
-
clientBuilder
protected org.glassfish.jersey.client.JerseyClientBuilder clientBuilder()
-
-