Package io.dropwizard.testing.junit5
Class DropwizardClientExtension
- java.lang.Object
-
- io.dropwizard.testing.junit5.DropwizardClientExtension
-
- All Implemented Interfaces:
DropwizardExtension
public class DropwizardClientExtension extends Object implements 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:
Of course, you'd use your http client, not@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); }
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 Summary
Constructors Constructor Description DropwizardClientExtension(Object... resources)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
after()
Executed after test method or class.URI
baseUri()
void
before()
Executed before test method or class.Environment
getEnvironment()
com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
-
-
-
Constructor Detail
-
DropwizardClientExtension
public DropwizardClientExtension(Object... resources)
-
-
Method Detail
-
baseUri
public URI baseUri()
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
-
getEnvironment
public Environment getEnvironment()
-
before
public void before() throws Throwable
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
-
-