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
DropwizardClientExtensiontakes 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 voidafter()Executed after test method or class.URIbaseUri()voidbefore()Executed before test method or class.EnvironmentgetEnvironment()com.fasterxml.jackson.databind.ObjectMappergetObjectMapper()
-
-
-
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 ThrowableDescription copied from interface:DropwizardExtensionExecuted before test method or class.- Specified by:
beforein interfaceDropwizardExtension- Throws:
Throwable
-
after
public void after()
Description copied from interface:DropwizardExtensionExecuted after test method or class.- Specified by:
afterin interfaceDropwizardExtension
-
-