Annotation Type UseDropwizardApp


  • @Retention(RUNTIME)
    @Target(TYPE)
    public @interface UseDropwizardApp
    Dropwizard spock extension. Starts dropwizard application before all tests in class and shutdown after them.

    Gucie injections will work on test class (just annotate required fields with Inject. Shared may be used to define common injection points for all tests in class.

    Note: setupSpec() fixture is called after application start and cleanupSpec() before application tear down.

    Extension would also recognize the following test fields (including super classes):

    • static GuiceyConfigurationHook annotated with EnableHook - hook from field will be registered
    • ClientSupport annotated with InjectClient field will be injected with client instance.

    Internally based on DropwizardTestSupport.

    Since:
    03.01.2015
    See Also:
    InjectClient
    • Required Element Summary

      Required Elements 
      Modifier and Type Required Element Description
      java.lang.Class<? extends io.dropwizard.core.Application> value  
    • Optional Element Summary

      Optional Elements 
      Modifier and Type Optional Element Description
      java.lang.String config  
      ConfigOverride[] configOverride  
      java.lang.Class<? extends ru.vyarus.dropwizard.guice.hook.GuiceyConfigurationHook>[] hooks
      Hooks provide access to guice builder allowing complete customization of application context in tests.
      boolean randomPorts
      Enables random ports usage.
      java.lang.String restMapping
      Specifies rest mapping path.
    • Element Detail

      • value

        java.lang.Class<? extends io.dropwizard.core.Application> value
        Returns:
        application class
      • config

        java.lang.String config
        Returns:
        path to configuration file (optional)
        Default:
        ""
      • configOverride

        ConfigOverride[] configOverride
        Returns:
        list of overridden configuration values (may be used even without real configuration)
        Default:
        {}
      • hooks

        java.lang.Class<? extends ru.vyarus.dropwizard.guice.hook.GuiceyConfigurationHook>[] hooks
        Hooks provide access to guice builder allowing complete customization of application context in tests.

        Additional hooks could be declared in static test fields: @EnableHook static GuiceyConfigurationHook HOOK = { it.disableExtensions(Something.class)}.

        Returns:
        list of hooks to use
        See Also:
        for more info, EnableHook
        Default:
        {}
      • randomPorts

        boolean randomPorts
        Enables random ports usage. Supports both simple and default dropwizard servers. Random ports would be set even if you specify exact configuration file with configured ports (option overrides configuration).

        To get port numbers in test use ClientSupport static field:

        @InjectClient ClientSupport client
        
         static setupSpec() {
             String baseUrl = "http://localhost:" + client.getPort();
             String baseAdminUrl = "http://localhost:" + client.getAdminPort();
         }
         
        Or use client target methods directly.
        Returns:
        true to use random ports
        Default:
        false
      • restMapping

        java.lang.String restMapping
        Specifies rest mapping path. This is the same as specifying configOverride() "server.rootMapping=/something/*". Specified value would be prefixed with "/" and, if required "/*" applied at the end. So it would be correct to specify restMapping = "api" (actually set value would be "/api/*").

        This option is only intended to simplify cases when custom configuration file is not yet used in tests (usually early PoC phase). It allows you to map servlet into application root in test (because rest is no more resides in root). When used with existing configuration file, this parameter will override file definition.

        Returns:
        rest mapping (empty string - do nothing)
        Default:
        ""