Class TestSupportBuilder<C extends io.dropwizard.core.Configuration>
- Type Parameters:
C- configuration type
DropwizardTestSupport and
GuiceyTestSupport objects. Allows using all available options. This builder
should be suitable for cases when junit 5 extensions could not be used.
Use TestSupport.build(Class) to build instance.
Builder is not supposed to be used for multiple runs: registered hooks will be applied only once. This limitation is not possible to avoid because builder could be used for support objects creation, which are not aware of hooks. So hooks could be registered globally only in time of addition to the builder.
- Since:
- 14.11.2023
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceTestSupportBuilder.TestListener<C extends io.dropwizard.core.Configuration>Listener forTestSupport.build(Class)builder. -
Field Summary
Fields inherited from class ru.vyarus.dropwizard.guice.test.builder.BaseBuilder
app, configObject, configOverrides, configPath, configSourceProvider, modifiers, propertyPrefix, restMapping -
Constructor Summary
ConstructorsConstructorDescriptionTestSupportBuilder(Class<? extends io.dropwizard.core.Application<C>> app) Create builder. -
Method Summary
Modifier and TypeMethodDescriptionShortcut forclientFactory(ru.vyarus.dropwizard.guice.test.client.TestClientFactory)to configureApacheTestClientFactory.Build a test support object with web servicesDropwizardTestSupport.io.dropwizard.testing.DropwizardTestSupport<C>buildWeb()Build a test support object with web servicesDropwizardTestSupport.clientFactory(TestClientFactory factory) Custom client factory implementation used forClientSupportobject creation (this special client class automatically constructs base urls for application under test, based on its configuration).listen(TestSupportBuilder.TestListener<C> listener) Listener used ONLY when builder run methods used!Shortcut to enable random web ports.randomPorts(boolean randomPorts) Use random http ports (applicable only for web).runCore()Start and stop application without web services.<T> TrunCore(TestSupport.RunCallback<T> action) Start and stop application without web services.Start and stop application without web services.<T> TrunCoreWithoutManaged(TestSupport.RunCallback<T> action) Start and stop application without web services.runWeb()Start and stop application with web services.<T> TrunWeb(TestSupport.RunCallback<T> action) Start and stop application with web services.Methods inherited from class ru.vyarus.dropwizard.guice.test.builder.BaseBuilder
config, config, configModifiers, configModifiers, configOverride, configOverride, configOverride, configOverrides, configSourceProvider, hooks, hooks, prepareOverrides, propertyPrefix, restMapping
-
Constructor Details
-
TestSupportBuilder
Create builder.- Parameters:
app- application type
-
-
Method Details
-
randomPorts
Shortcut to enable random web ports.- Returns:
- builder instance for chained calls
-
randomPorts
Use random http ports (applicable only for web). Useful to separate concurrent web instances runs.- Parameters:
randomPorts- true to use random ports- Returns:
- builder instance for chained calls
-
clientFactory
Custom client factory implementation used forClientSupportobject creation (this special client class automatically constructs base urls for application under test, based on its configuration).Client instance could be accessed at any time (during test) with
TestSupportHolder.getClient()- Parameters:
factory- factory instance- Returns:
- builder instance for chained calls
-
apacheClient
Shortcut forclientFactory(ru.vyarus.dropwizard.guice.test.client.TestClientFactory)to configureApacheTestClientFactory. The defaultHttpUrlConnectorProvidersupports only HTTP 1.1 methods and have problem with PATCH method usage on jdk > 16.- Returns:
- builder instance for chained calls
-
listen
Listener used ONLY when builder run methods used! Listener may be used to perform additional initialization or cleanup before/after application execution.- Parameters:
listener- execution listener- Returns:
- builder instance for chained calls
-
buildCore
Build a test support object with web servicesDropwizardTestSupport. Method supposed to be used only byTestSupportfor support objects creation. Prefer direct run (runCore()) method usage (used support object could be easily obtained withTestSupport.getContext()in any place).IMPORTANT: listeners could not be used (because they are implemented as a custom run callback). Custom
TestClientFactorywould also be lost! Use direct run methods to not lose them.- Returns:
- guicey test support implementation
-
buildWeb
Build a test support object with web servicesDropwizardTestSupport. Method supposed to be used only byTestSupportfor support objects creation. Prefer direct run (runWeb()) method usage (used support object could be easily obtained withTestSupport.getContext()in any place).IMPORTANT: listeners could not be used (because they are implemented as a custom run callback). Custom
TestClientFactorywould also be lost! Use direct run methods to not lose them.- Returns:
- dropwizard test support implementation
-
runCore
Start and stop application without web services. Mostly useful to test application startup errors (with proper application shutdown).NOTE: method not supposed to be used for multiple calls. For example, registered hooks would only work on first execution.
- Returns:
- action result
- Throws:
Exception- any appeared exception (throws may easily be added directly to test method and, without extra exception wrapper, we get exact exceptions as they would be thrown in real application)
-
runCore
Start and stop application without web services. Provided action would be executed in time of application life.NOTE: method not supposed to be used for multiple calls. For example, registered hooks would only work on first execution.
- Type Parameters:
T- result type- Parameters:
action- action to execute while the application is running- Returns:
- action result
- Throws:
Exception- any appeared exception (throws may easily be added directly to test method and, without extra exception wrapper, we get exact exceptions as they would be thrown in real application)
-
runCoreWithoutManaged
Start and stop application without web services. Provided action would be executed in time of application life. Does not simulateManagedobjects lifecycle (start/stop would not be called).NOTE: method not supposed to be used for multiple calls. For example, registered hooks would only work on first execution.
- Returns:
- execution result (with all required objects for verification)
- Throws:
Exception- any appeared exception (throws may easily be added directly to test method and, without extra exception wrapper, we get exact exceptions as they would be thrown in real application)
-
runCoreWithoutManaged
Start and stop application without web services. Provided action would be executed in time of application life. Does not simulateManagedobjects lifecycle (start/stop would not be called).NOTE: method not supposed to be used for multiple calls. For example, registered hooks would only work on first execution.
- Type Parameters:
T- result type- Parameters:
action- action to execute while the application is running- Returns:
- action result
- Throws:
Exception- any appeared exception (throws may easily be added directly to test method and, without extra exception wrapper, we get exact exceptions as they would be thrown in real application)
-
runWeb
Start and stop application with web services. Mostly useful to test application startup errors (with proper application shutdown).NOTE: method not supposed to be used for multiple calls. For example, registered hooks would only work on first execution.
- Returns:
- result action
- Throws:
Exception- any appeared exception (throws may easily be added directly to test method and, without extra exception wrapper, we get exact exceptions as they would be thrown in real application)
-
runWeb
Start and stop application with web services. Provided action would be executed in time of application life.NOTE: method not supposed to be used for multiple calls. For example, registered hooks would only work on first execution.
- Type Parameters:
T- result type- Parameters:
action- action to execute while the application is running- Returns:
- action result
- Throws:
Exception- any appeared exception (throws may easily be added directly to test method and, without extra exception wrapper, we get exact exceptions as they would be thrown in real application)
-