Package ru.vyarus.dropwizard.guice.test
Class GuiceyTestSupport<C extends io.dropwizard.core.Configuration>
java.lang.Object
io.dropwizard.testing.DropwizardTestSupport<C>
ru.vyarus.dropwizard.guice.test.GuiceyTestSupport<C>
- Type Parameters:
C- configuration type
public class GuiceyTestSupport<C extends io.dropwizard.core.Configuration>
extends io.dropwizard.testing.DropwizardTestSupport<C>
An alternative to
DropwizardTestSupport which does not run jetty (web part) allowing to test only guice
context. Internally, TestCommand used instead of ServerCommand.
Supposed to be used in cases when application startup fail must be tested:
new GuiceyTestSupport(MyApp.class, (String) null).before().
- Since:
- 03.02.2022
-
Nested Class Summary
Nested classes/interfaces inherited from class io.dropwizard.testing.DropwizardTestSupport
io.dropwizard.testing.DropwizardTestSupport.ServiceListener<T extends io.dropwizard.core.Configuration> -
Field Summary
Fields inherited from class io.dropwizard.testing.DropwizardTestSupport
application, applicationClass, commandInstantiator, configOverrides, configPath, configSourceProvider, configuration, customPropertyPrefix, environment, explicitConfig, jettyServer, listeners -
Constructor Summary
ConstructorsConstructorDescriptionGuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, C configuration) Create test support.GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, String configPath, io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support.GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, String configPath, io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support.GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, String configPath, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support.GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, String configPath, String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support. -
Method Summary
Modifier and TypeMethodDescriptionvoidafter()configModifiers(List<ConfigModifier<C>> modifiers) Register configuration modifiers.final GuiceyTestSupport<C>configModifiers(ConfigModifier<C>... modifiers) Register configuration modifiers.By default, guicey simulates jetty lifecycle to support forManagedandLifeCycleobjects.<T> TgetBean(com.google.inject.Key<T> key) Shortcut for accessing guice beans.<T> TShortcut for accessing guice beans.run()Normally,DropwizardTestSupport.before()andafter()methods are called separately.<T> Trun(TestSupport.RunCallback<T> callback) Normally,DropwizardTestSupport.before()andafter()methods are called separately.Methods inherited from class io.dropwizard.testing.DropwizardTestSupport
addListener, before, getAdminPort, getApplication, getConfiguration, getEnvironment, getLocalPort, getObjectMapper, getPort, manage, newApplication
-
Constructor Details
-
GuiceyTestSupport
public GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support.- Parameters:
applicationClass- application classconfigPath- configuration file pathconfigOverrides- configuration overrides
-
GuiceyTestSupport
public GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support.- Parameters:
applicationClass- application classconfigPath- configuration file pathconfigSourceProvider- configuration source provider (optional)configOverrides- configuration overrides
-
GuiceyTestSupport
public GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable io.dropwizard.configuration.ConfigurationSourceProvider configSourceProvider, @Nullable String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support.- Parameters:
applicationClass- application classconfigPath- configuration file pathconfigSourceProvider- configuration source providercustomPropertyPrefix- configuration overrides prefixconfigOverrides- configuration overrides
-
GuiceyTestSupport
public GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, @Nullable String configPath, @Nullable String customPropertyPrefix, io.dropwizard.testing.ConfigOverride... configOverrides) Create test support.- Parameters:
applicationClass- application classconfigPath- configuration file pathcustomPropertyPrefix- configuration overrides prefixconfigOverrides- configuration overrides
-
GuiceyTestSupport
public GuiceyTestSupport(Class<? extends io.dropwizard.core.Application<C>> applicationClass, C configuration) Create test support.- Parameters:
applicationClass- application classconfiguration- manual configuration instance
-
-
Method Details
-
disableManagedLifecycle
By default, guicey simulates jetty lifecycle to support forManagedandLifeCycleobjects.It might be required in test to avoid starting managed objects (especially all managed in application) because important (for test) services replaced with mocks (and no need to wait for the rest of the application).
- Returns:
- test support instance for chained calls
-
configModifiers
Register configuration modifiers.- Parameters:
modifiers- configuration modifiers- Returns:
- support object instance for chained calls
-
configModifiers
Register configuration modifiers.- Parameters:
modifiers- configuration modifiers- Returns:
- support object instance for chained calls
-
run
Normally,DropwizardTestSupport.before()andafter()methods are called separately. This method is a shortcut mostly for errors testing whenDropwizardTestSupport.before()assumed to fail to make sureafter()will be called in any case:testSupport.run(null).- Type Parameters:
T- result type- Parameters:
callback- callback (may be null)- Returns:
- callback result
- Throws:
Exception- any appeared exception
-
run
Normally,DropwizardTestSupport.before()andafter()methods are called separately. This method is a shortcut mostly for errors testing whenDropwizardTestSupport.before()assumed to fail to make sureafter()will be called in any case:testSupport.run(null).- Returns:
- execution result (with all required objects for verification)
- Throws:
Exception- any appeared exception
-
getBean
Shortcut for accessing guice beans.- Type Parameters:
T- bean type- Parameters:
type- target bean type- Returns:
- bean instance
-
getBean
public <T> T getBean(com.google.inject.Key<T> key) Shortcut for accessing guice beans.- Type Parameters:
T- bean type- Parameters:
key- binding key- Returns:
- bean instance
-
after
public void after()- Overrides:
afterin classio.dropwizard.testing.DropwizardTestSupport<C extends io.dropwizard.core.Configuration>
-