Class CommandRunBuilder<C extends io.dropwizard.core.Configuration>
- Type Parameters:
C- configuration type
CommandTestSupport. Provides almost the same methods
as application support builder (TestSupportBuilder).
Use TestSupport.buildCommandRunner(Class) for builder creation.
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:
- 20.11.2023
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceCommandRunBuilder.CommandListener<C extends io.dropwizard.core.Configuration>Command execution listener. -
Field Summary
Fields inherited from class ru.vyarus.dropwizard.guice.test.builder.BaseBuilder
app, configObject, configOverrides, configPath, configSourceProvider, modifiers, propertyPrefix, restMapping -
Constructor Summary
ConstructorsConstructorDescriptionCommandRunBuilder(Class<? extends io.dropwizard.core.Application<C>> app) Create builder. -
Method Summary
Modifier and TypeMethodDescriptionconsoleInputs(String... inputs) The amount af answers should not be less than provided answers count.listen(CommandRunBuilder.CommandListener<C> listener) Simple listener to setup and cleanup something before and after command execution.Execute dropwizard command.runApp()Shortcut forrun("server")to start application.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
-
CommandRunBuilder
Create builder.- Parameters:
app- application class
-
-
Method Details
-
consoleInputs
The amount af answers should not be less than provided answers count.- Parameters:
inputs- answers for command console questions- Returns:
- builder instance for chained calls
-
listen
Simple listener to setup and cleanup something before and after command execution.- Parameters:
listener- listener- Returns:
- builder instance for chained calls
-
runApp
Shortcut forrun("server")to start application. Should be used to test application startup errors. Error would be thrown if the application started successfully (to avoid frozen test).- Returns:
- execution result
-
run
Execute dropwizard command. Could be used to execute any command. The only difference with the usual usage is that configuration file should not be declared (as second argument). Config file could be specified - it would not lead to error (if the config file path was not declared in builder also).Execution never throws an exception! Any appeared exception would be returned inside an unsuccessful result.
As it is not possible to run any callback in time of command execution - all runtime objects are provided inside the result for inspection (some objects could be null, depending on a command type).
All command output would be available in the result. Also, output is streamed to console (to indicate the exact app froze point, if command hangs). Error stream is also available separately to simplify error check.
- Parameters:
args- command execution arguments (without configuration file)- Returns:
- command execution result
-