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

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

      • DropwizardClientExtension

        public DropwizardClientExtension​(Object... resources)