Class BaseBuilder<C extends io.dropwizard.core.Configuration,​T extends BaseBuilder<C,​T>>

  • Type Parameters:
    C - configuration type
    T - builder type
    Direct Known Subclasses:
    CommandRunBuilder, TestSupportBuilder

    public abstract class BaseBuilder<C extends io.dropwizard.core.Configuration,​T extends BaseBuilder<C,​T>>
    extends java.lang.Object
    Base class for test support objects builders.
    Since:
    20.11.2023
    • Field Detail

      • app

        protected final java.lang.Class<? extends io.dropwizard.core.Application<C extends io.dropwizard.core.Configuration>> app
        Application class.
      • configPath

        protected java.lang.String configPath
        Configuration file path.
      • configSourceProvider

        protected io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider
        Configuration source provider.
      • configOverrides

        protected final java.util.Map<java.lang.String,​java.util.function.Supplier<java.lang.String>> configOverrides
        Configuration overrides.
      • modifiers

        protected final java.util.List<ConfigModifier<C extends io.dropwizard.core.Configuration>> modifiers
        Configuration modifiers.
      • configObject

        protected C extends io.dropwizard.core.Configuration configObject
        Configuration instance (instead of file).
      • propertyPrefix

        protected java.lang.String propertyPrefix
        Configuration overrides property prefix.
      • restMapping

        protected java.lang.String restMapping
        Rest context mapping.
    • Constructor Detail

      • BaseBuilder

        public BaseBuilder​(java.lang.Class<? extends io.dropwizard.core.Application<C>> app)
        Create builder.
        Parameters:
        app - application class
    • Method Detail

      • config

        public T config​(@Nullable
                        java.lang.String path)
        Parameters:
        path - configuration file path
        Returns:
        builder instance for chained calls
      • config

        public T config​(@Nullable
                        C config)
        Use configuration instance instead of configuration parsing from yaml file. When this is used, other configuration options must not be used (they can't be used, and an error would be thrown indicating incorrect usage).
        Parameters:
        config - pre-initialized configuration object
        Returns:
        builder instance for chained calls
      • configSourceProvider

        public T configSourceProvider​(@Nullable
                                      io.dropwizard.configuration.ConfigurationSourceProvider provider)
        Parameters:
        provider - configuration source provider
        Returns:
        builder instance for chained calls
      • configOverride

        public T configOverride​(java.lang.String key,
                                java.util.function.Supplier<java.lang.String> value)
        Parameters:
        key - configuration path
        value - overriding value provider
        Returns:
        builder instance for chained calls
      • configModifiers

        @SafeVarargs
        public final T configModifiers​(ConfigModifier<C>... modifiers)
        Configuration modifier is an alternative for configuration override, which is limited for simple property types (for example, a collection could not be overridden).

        Modifier is called before application run phase. Only logger configuration is applied at this moment (and so you can't change it). Modifier would work with both yaml (config(String)) and instance (config(io.dropwizard.core.Configuration)) based configurations.

        Method supposed to be used with lambdas and so limited for application configuration class. For generic configurations (based on configuration subclass or raw Configuration) use configModifiers(Class[]).

        Parameters:
        modifiers - configuration modifiers
        Returns:
        builder instance for chained calls
      • configModifiers

        @SafeVarargs
        public final T configModifiers​(java.lang.Class<? extends ConfigModifier<? extends io.dropwizard.core.Configuration>>... modifiers)
        Configuration modifier is an alternative for configuration override, which is limited for simple property types (for example, a collection could not be overridden).

        Modifier is called before application run phase. Only logger configuration is applied at this moment (and so you can't change it). Modifier would work with both yaml (config(String)) and instance (config(io.dropwizard.core.Configuration)) based configurations.

        Method is useful for generic modifiers (based on configuration subclass or raw Configuration).

        Parameters:
        modifiers - configuration modifiers
        Returns:
        builder instance for chained calls
      • propertyPrefix

        public T propertyPrefix​(@Nullable
                                java.lang.String prefix)
        Dropwizard stored all provided configuration overriding values as system properties with provided prefix (or "dw." by default). If multiple tests run concurrently, they would collide on using the same system properties. It is preferred to specify test-unique prefix.
        Parameters:
        prefix - configuration override properties prefix
        Returns:
        builder instance for chained calls
      • hooks

        @SafeVarargs
        public final T hooks​(java.lang.Class<? extends GuiceyConfigurationHook>... hooks)
        Shortcut for hooks registration (method simply immediately registers provided hooks).
        Parameters:
        hooks - hook classes to install (nulls not allowed)
        Returns:
        builder instance for chained calls
      • hooks

        public T hooks​(GuiceyConfigurationHook... hooks)
        Shortcut for hooks registration (method simply immediately registers provided hooks).
        Parameters:
        hooks - hooks to install (nulls allowed)
        Returns:
        builder instance for chained calls
      • prepareOverrides

        protected io.dropwizard.testing.ConfigOverride[] prepareOverrides​(java.lang.String prefix)
        Collect configuration overrides objects.
        Parameters:
        prefix - custom configuration overrides prefix
        Returns:
        configuration overrides
      • restMapping

        public T restMapping​(java.lang.String restMapping)
        Specifies rest mapping path. This is the same as specifying direct config override "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 resided in root). When used with existing configuration file, this parameter will override file definition.

        Parameters:
        restMapping - rest mapping path
        Returns:
        builder instance for chained calls