Class BaseBuilder<C extends io.dropwizard.core.Configuration,T extends BaseBuilder<C,T>>
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.builder.BaseBuilder<C,T>
-
- Type Parameters:
C
- configuration typeT
- 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 Summary
Fields Modifier and Type Field Description protected java.lang.Class<? extends io.dropwizard.core.Application<C>>
app
protected C
configObject
protected java.util.Map<java.lang.String,java.util.function.Supplier<java.lang.String>>
configOverrides
protected java.lang.String
configPath
protected io.dropwizard.configuration.ConfigurationSourceProvider
configSourceProvider
protected java.lang.String
propertyPrefix
-
Constructor Summary
Constructors Constructor Description BaseBuilder(java.lang.Class<? extends io.dropwizard.core.Application<C>> app)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description T
config(C config)
Use configuration instance instead of configuration parsing from yaml file.T
config(java.lang.String path)
Must not be used ifconfig(io.dropwizard.core.Configuration)
used.T
configOverride(java.lang.String override)
Must not be used ifconfig(io.dropwizard.core.Configuration)
used.T
configOverride(java.lang.String key, java.lang.String value)
Must not be used ifconfig(io.dropwizard.core.Configuration)
used.T
configOverride(java.lang.String key, java.util.function.Supplier<java.lang.String> value)
Must not be used ifconfig(io.dropwizard.core.Configuration)
used.T
configOverrides(java.lang.String... overrides)
Must not be used ifconfig(io.dropwizard.core.Configuration)
used.T
configSourceProvider(io.dropwizard.configuration.ConfigurationSourceProvider provider)
Must not be used ifconfig(io.dropwizard.core.Configuration)
used.T
hooks(java.lang.Class<? extends GuiceyConfigurationHook>... hooks)
Shortcut for hooks registration (method simply immediately registers provided hooks).T
hooks(GuiceyConfigurationHook... hooks)
Shortcut for hooks registration (method simply immediately registers provided hooks).protected io.dropwizard.testing.ConfigOverride[]
prepareOverrides(java.lang.String prefix)
T
propertyPrefix(java.lang.String prefix)
Dropwizard stored all provided configuration overriding values as system properties with provided prefix (or "dw." by default).T
restMapping(java.lang.String restMapping)
Specifies rest mapping path.
-
-
-
Field Detail
-
app
protected final java.lang.Class<? extends io.dropwizard.core.Application<C extends io.dropwizard.core.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.core.Configuration configObject
-
propertyPrefix
protected java.lang.String propertyPrefix
-
-
Constructor Detail
-
BaseBuilder
public BaseBuilder(java.lang.Class<? extends io.dropwizard.core.Application<C>> app)
-
-
Method Detail
-
config
public T config(@Nullable java.lang.String path)
Must not be used ifconfig(io.dropwizard.core.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 ifconfig(io.dropwizard.core.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 ifconfig(io.dropwizard.core.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 ifconfig(io.dropwizard.core.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 ifconfig(io.dropwizard.core.Configuration)
used.- Parameters:
key
- configuration pathvalue
- 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 ifconfig(io.dropwizard.core.Configuration)
used.- Parameters:
key
- configuration pathvalue
- 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 specifyrestMapping = "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
-
-