public class DropwizardClientRule
extends org.junit.rules.ExternalResource
Example:
@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);
}
Of course, you'd use your http client, not URL.openStream().
The DropwizardClientRule takes care of:
| Constructor and Description |
|---|
DropwizardClientRule(Object... resources) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
after() |
URI |
baseUri() |
protected void |
before() |
Environment |
getEnvironment() |
com.fasterxml.jackson.databind.ObjectMapper |
getObjectMapper() |
public DropwizardClientRule(Object... resources)
public URI baseUri()
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
public Environment getEnvironment()
protected void before()
throws Throwable
before in class org.junit.rules.ExternalResourceThrowableprotected void after()
after in class org.junit.rules.ExternalResourceCopyright © 2016. All rights reserved.