Package io.dropwizard.testing.junit
Class DropwizardClientRule
- java.lang.Object
-
- org.junit.rules.ExternalResource
-
- io.dropwizard.testing.junit.DropwizardClientRule
-
- All Implemented Interfaces:
org.junit.rules.TestRule
public class DropwizardClientRule extends org.junit.rules.ExternalResourceTest your HTTP client code by writing a JAX-RS test double class and let this rule start and stop a Dropwizard application containing your doubles.Example:
Of course, you'd use your http client, not@Path("/ping") public static class PingResource { @GET public String ping() { return "pong"; } } @ClassRule public static DropwizardClientRule dropwizard = new DropwizardClientRule(new PingResource()); @Test public void shouldPing() throws IOException { URL url = new URL(dropwizard.baseUri() + "/ping"); String response = new BufferedReader(new InputStreamReader(url.openStream())).readLine(); assertEquals("pong", response); }URL.openStream().The
DropwizardClientRuletakes care of:- Creating a simple default configuration.
- Creating a simplistic application.
- Adding a dummy health check to the application to suppress the startup warning.
- Adding your resources to the application.
- Choosing a free random port number.
- Starting the application.
- Stopping the application.
-
-
Constructor Summary
Constructors Constructor Description DropwizardClientRule(Object... resources)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidafter()URIbaseUri()protected voidbefore()io.dropwizard.core.setup.EnvironmentgetEnvironment()com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()
-
-
-
Constructor Detail
-
DropwizardClientRule
public DropwizardClientRule(Object... resources)
-
-
Method Detail
-
baseUri
public URI baseUri()
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
getEnvironment
public io.dropwizard.core.setup.Environment getEnvironment()
-
before
protected void before() throws Throwable- Overrides:
beforein classorg.junit.rules.ExternalResource- Throws:
Throwable
-
after
protected void after()
- Overrides:
afterin classorg.junit.rules.ExternalResource
-
-