Class DropwizardAppExtension<C extends Configuration>

  • Type Parameters:
    C - the configuration type
    All Implemented Interfaces:
    DropwizardExtension

    public class DropwizardAppExtension<C extends Configuration>
    extends Object
    implements DropwizardExtension
    An extension for starting and stopping your application at the start and end of a test class.

    By default, the Application will be constructed using reflection to invoke the nullary constructor. If your application does not provide a public nullary constructor, you will need to override the newApplication() method to provide your application instance(s).

    Using DropwizardAppExtension at the suite level can speed up test runs, as the application is only started and stopped once for the entire suite:

     public class MySuite {
       public static final DropwizardAppExtension<MyConfig> DROPWIZARD = new DropwizardAppExtension<>(...);
     }
     

    If the same instance of DropwizardAppExtension is reused at the suite- and class-level, then the application will be started and stopped once, regardless of whether the entire suite or a single test is executed.

     @ExtendWith(DropwizardExtensionsSupport.class)
     public class FooTest {
       public static final DropwizardAppExtension<MyConfig> DROPWIZARD = MySuite.DROPWIZARD;
    
       public void testFoo() { ... }
     }
    
     @ExtendWith(DropwizardExtensionsSupport.class)
     public class BarTest {
       public static final DropwizardAppExtension<MyConfig> DROPWIZARD = MySuite.DROPWIZARD;
    
       public void testBar() { ... }
     }
     

    • Constructor Detail

      • DropwizardAppExtension

        public DropwizardAppExtension​(Class<? extends Application<C>> applicationClass)
      • DropwizardAppExtension

        public DropwizardAppExtension​(Class<? extends Application<C>> applicationClass,
                                      C configuration)
        Alternate constructor that allows specifying exact Configuration object to use, instead of reading a resource and binding it as Configuration object.
        Since:
        0.9
      • DropwizardAppExtension

        public DropwizardAppExtension​(Class<? extends Application<C>> applicationClass,
                                      C configuration,
                                      Function<Application<C>,​Command> commandInstantiator)
        Alternate constructor that allows specifying the command the Dropwizard application is started with.
        Since:
        1.1.0
    • Method Detail

      • getConfiguration

        public C getConfiguration()
      • getLocalPort

        public int getLocalPort()
      • getPort

        public int getPort​(int connectorIndex)
      • getAdminPort

        public int getAdminPort()
      • getApplication

        public <A extends Application<C>> A getApplication()
      • getObjectMapper

        public com.fasterxml.jackson.databind.ObjectMapper getObjectMapper()
      • client

        public javax.ws.rs.client.Client client()
        Returns a new HTTP Jersey Client for performing HTTP requests against the tested Dropwizard server. The client can be reused across different tests and automatically closed along with the server. The client can be augmented by overriding the clientBuilder() method.
        Returns:
        a new Client managed by the extension.
      • clientBuilder

        protected org.glassfish.jersey.client.JerseyClientBuilder clientBuilder()