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
@Deprecated public class DropwizardClientRule extends org.junit.rules.ExternalResource
Deprecated.Deprecated since Dropwizard 2.0.0. Please migrate to JUnit 5 andDropwizardClientExtension
.Test 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
DropwizardClientRule
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 DropwizardClientRule(Object... resources)
Deprecated.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected void
after()
Deprecated.URI
baseUri()
Deprecated.protected void
before()
Deprecated.Environment
getEnvironment()
Deprecated.com.fasterxml.jackson.databind.ObjectMapper
getObjectMapper()
Deprecated.
-
-
-
Constructor Detail
-
DropwizardClientRule
public DropwizardClientRule(Object... resources)
Deprecated.
-
-
Method Detail
-
baseUri
public URI baseUri()
Deprecated.
-
getObjectMapper
public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
Deprecated.
-
getEnvironment
public Environment getEnvironment()
Deprecated.
-
before
protected void before() throws Throwable
Deprecated.- Overrides:
before
in classorg.junit.rules.ExternalResource
- Throws:
Throwable
-
after
protected void after()
Deprecated.- Overrides:
after
in classorg.junit.rules.ExternalResource
-
-