Package io.dropwizard.testing.junit5
Class DropwizardClientExtension
java.lang.Object
io.dropwizard.testing.junit5.DropwizardClientExtension
- All Implemented Interfaces:
DropwizardExtension
Test your HTTP client code by writing a JAX-RS test double class and let this extension start and stop a
Dropwizard application containing your doubles.
Example:
@Path("/ping")
public static class PingResource {
@GET
public String ping() {
return "pong";
}
}
public static DropwizardClientExtension dropwizard = new DropwizardClientExtension(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 DropwizardClientExtension
takes 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 Details
-
DropwizardClientExtension
-
-
Method Details
-
baseUri
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper() -
getEnvironment
-
before
Description copied from interface:DropwizardExtension
Executed before test method or class.- Specified by:
before
in interfaceDropwizardExtension
- Throws:
Throwable
-
after
public void after()Description copied from interface:DropwizardExtension
Executed after test method or class.- Specified by:
after
in interfaceDropwizardExtension
-