Class BaseBuilder<C extends io.dropwizard.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.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.Application<C extends io.dropwizard.Configuration>> app
      • configPath

        protected java.lang.String configPath
      • configSourceProvider

        protected io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider
      • configOverrides

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

        protected C extends io.dropwizard.Configuration configObject
      • propertyPrefix

        protected java.lang.String propertyPrefix
    • Constructor Detail

      • BaseBuilder

        public BaseBuilder​(java.lang.Class<? extends io.dropwizard.Application<C>> app)
    • Method Detail

      • config

        public T config​(@Nullable
                        java.lang.String path)
        Must not be used if config(io.dropwizard.Configuration) used.
        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)
        Must not be used if config(io.dropwizard.Configuration) used.
        Parameters:
        provider - configuration source provider
        Returns:
        builder instance for chained calls
      • configOverrides

        public T configOverrides​(java.lang.String... overrides)
        Must not be used if config(io.dropwizard.Configuration) used.
        Parameters:
        overrides - config override values (in format "path: value")
        Returns:
        builder instance for chained calls
      • configOverride

        public T configOverride​(@Nullable
                                java.lang.String override)
        Must not be used if config(io.dropwizard.Configuration) used.
        Parameters:
        override - config override value (in format "path: value")
        Returns:
        builder instance for chained calls
      • configOverride

        public T configOverride​(java.lang.String key,
                                java.lang.String value)
        Must not be used if config(io.dropwizard.Configuration) used.
        Parameters:
        key - configuration path
        value - overriding value
        Returns:
        builder instance for chained calls
      • configOverride

        public T configOverride​(java.lang.String key,
                                java.util.function.Supplier<java.lang.String> value)
        Must not be used if config(io.dropwizard.Configuration) used.
        Parameters:
        key - configuration path
        value - overriding value provider
        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)
      • 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.

        Returns:
        builder instance for chained calls