Class 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 and DropwizardClientExtension.
    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:

    
        @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:

    • 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 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 class org.junit.rules.ExternalResource
        Throws:
        Throwable
      • after

        protected void after()
        Deprecated.
        Overrides:
        after in class org.junit.rules.ExternalResource