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.ObjectBase 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>>appApplication class.protected CconfigObjectConfiguration instance (instead of file).protected java.util.Map<java.lang.String,java.util.function.Supplier<java.lang.String>>configOverridesConfiguration overrides.protected java.lang.StringconfigPathConfiguration file path.protected io.dropwizard.configuration.ConfigurationSourceProviderconfigSourceProviderConfiguration source provider.protected java.util.List<ConfigModifier<C>>modifiersConfiguration modifiers.protected java.lang.StringpropertyPrefixConfiguration overrides property prefix.protected java.lang.StringrestMappingRest context mapping.
-
Constructor Summary
Constructors Constructor Description BaseBuilder(java.lang.Class<? extends io.dropwizard.core.Application<C>> app)Create builder.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Tconfig(C config)Use configuration instance instead of configuration parsing from yaml file.Tconfig(java.lang.String path)Must not be used ifconfig(io.dropwizard.core.Configuration)used.TconfigModifiers(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).TconfigModifiers(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).TconfigOverride(java.lang.String override)Must not be used ifconfig(io.dropwizard.core.Configuration)used.TconfigOverride(java.lang.String key, java.lang.String value)Must not be used ifconfig(io.dropwizard.core.Configuration)used.TconfigOverride(java.lang.String key, java.util.function.Supplier<java.lang.String> value)Must not be used ifconfig(io.dropwizard.core.Configuration)used.TconfigOverrides(java.lang.String... overrides)Must not be used ifconfig(io.dropwizard.core.Configuration)used.TconfigSourceProvider(io.dropwizard.configuration.ConfigurationSourceProvider provider)Must not be used ifconfig(io.dropwizard.core.Configuration)used.Thooks(java.lang.Class<? extends GuiceyConfigurationHook>... hooks)Shortcut for hooks registration (method simply immediately registers provided hooks).Thooks(GuiceyConfigurationHook... hooks)Shortcut for hooks registration (method simply immediately registers provided hooks).protected io.dropwizard.testing.ConfigOverride[]prepareOverrides(java.lang.String prefix)Collect configuration overrides objects.TpropertyPrefix(java.lang.String prefix)Dropwizard stored all provided configuration overriding values as system properties with provided prefix (or "dw." by default).TrestMapping(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
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)
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
- See Also:
configModifiers(ru.vyarus.dropwizard.guice.test.util.ConfigModifier[])
-
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
- See Also:
configModifiers(ru.vyarus.dropwizard.guice.test.util.ConfigModifier[])
-
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
- See Also:
configModifiers(ru.vyarus.dropwizard.guice.test.util.ConfigModifier[])
-
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
-
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) useconfigModifiers(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 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.
- Parameters:
restMapping- rest mapping path- Returns:
- builder instance for chained calls
-
-