Class DropwizardTestSupport<C extends io.dropwizard.core.Configuration>

java.lang.Object
io.dropwizard.testing.DropwizardTestSupport<C>
Type Parameters:
C - the configuration type

public class DropwizardTestSupport<C extends io.dropwizard.core.Configuration> extends Object
A test support class 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).

  • Field Details

    • applicationClass

      protected final Class<? extends io.dropwizard.core.Application<C extends io.dropwizard.core.Configuration>> applicationClass
    • configPath

      protected final @Nullable String configPath
    • configSourceProvider

      protected final @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider
    • configOverrides

      protected final Set<ConfigOverride> configOverrides
    • customPropertyPrefix

      protected final @Nullable String customPropertyPrefix
    • commandInstantiator

      protected final Function<io.dropwizard.core.Application<C extends io.dropwizard.core.Configuration>,io.dropwizard.core.cli.Command> commandInstantiator
    • explicitConfig

      protected final boolean explicitConfig
      Flag that indicates whether instance was constructed with an explicit Configuration object or not; handling of the two cases differ. Needed because state of configuration changes during lifecycle.
    • configuration

      protected @Nullable C extends io.dropwizard.core.Configuration configuration
    • application

      protected @Nullable io.dropwizard.core.Application<C extends io.dropwizard.core.Configuration> application
    • environment

      protected @Nullable io.dropwizard.core.setup.Environment environment
    • jettyServer

      protected @Nullable org.eclipse.jetty.server.Server jettyServer
    • listeners

      protected List<DropwizardTestSupport.ServiceListener<C extends io.dropwizard.core.Configuration>> listeners
  • Constructor Details

    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, ConfigOverride... configOverrides)
    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, ConfigOverride... configOverrides)
      Since:
      2.0
    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides)
      Since:
      2.0
    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, ConfigOverride... configOverrides)
      Since:
      2.0
    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, Function<io.dropwizard.core.Application<C>,io.dropwizard.core.cli.Command> commandInstantiator, ConfigOverride... configOverrides)
      Since:
      2.0
    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, Function<io.dropwizard.core.Application<C>,io.dropwizard.core.cli.Command> commandInstantiator, ConfigOverride... configOverrides)
      Since:
      2.0
    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, C configuration)
      Alternative constructor that may be used to directly provide Configuration to use, instead of specifying resource path for locating data to create Configuration.
      Parameters:
      applicationClass - Type of Application to create
      configuration - Pre-constructed configuration object caller provides; will not be manipulated in any way, no overriding
      Since:
      0.9
    • DropwizardTestSupport

      public DropwizardTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable C configuration, Function<io.dropwizard.core.Application<C>,io.dropwizard.core.cli.Command> commandInstantiator)
      Alternate constructor that allows specifying the command the Dropwizard application is started with.
      Parameters:
      applicationClass - Type of Application to create
      configuration - Pre-constructed configuration object caller provides; will not be manipulated in any way, no overriding
      commandInstantiator - The Function used to instantiate the Command used to start the Application
      Since:
      1.1.0
  • Method Details

    • addListener

    • manage

      public DropwizardTestSupport<C> manage(io.dropwizard.lifecycle.Managed managed)
    • before

      public void before() throws Exception
      Throws:
      Exception
    • after

      public void after()
    • getConfiguration

      public C getConfiguration()
    • getLocalPort

      public int getLocalPort()
    • getAdminPort

      public int getAdminPort()
    • getPort

      public int getPort(int connectorIndex)
    • newApplication

      public io.dropwizard.core.Application<C> newApplication()
    • getApplication

      public <A extends io.dropwizard.core.Application<C>> A getApplication()
    • getEnvironment

      public io.dropwizard.core.setup.Environment getEnvironment()
    • getObjectMapper

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