Class CommandRunBuilder<C extends io.dropwizard.core.Configuration>
- java.lang.Object
-
- ru.vyarus.dropwizard.guice.test.builder.BaseBuilder<C,CommandRunBuilder<C>>
-
- ru.vyarus.dropwizard.guice.test.cmd.CommandRunBuilder<C>
-
- Type Parameters:
C
- configuration type
public class CommandRunBuilder<C extends io.dropwizard.core.Configuration> extends BaseBuilder<C,CommandRunBuilder<C>>
Builder forCommandTestSupport
. 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 Classes Modifier and Type Class Description static interface
CommandRunBuilder.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, propertyPrefix
-
-
Constructor Summary
Constructors Constructor Description CommandRunBuilder(java.lang.Class<? extends io.dropwizard.core.Application<C>> app)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description CommandRunBuilder<C>
consoleInputs(java.lang.String... inputs)
The amount af answers should not be less than provided answers count.CommandRunBuilder<C>
listen(CommandRunBuilder.CommandListener<C> listener)
Simple listener to setup and cleanup something before and after command execution.CommandResult<C>
run(java.lang.String... args)
Execute dropwizard command.CommandResult<C>
runApp()
Shortcut forrun("server")
to start application.-
Methods inherited from class ru.vyarus.dropwizard.guice.test.builder.BaseBuilder
config, config, configOverride, configOverride, configOverride, configOverrides, configSourceProvider, hooks, hooks, prepareOverrides, propertyPrefix, restMapping
-
-
-
-
Constructor Detail
-
CommandRunBuilder
public CommandRunBuilder(java.lang.Class<? extends io.dropwizard.core.Application<C>> app)
-
-
Method Detail
-
consoleInputs
public CommandRunBuilder<C> consoleInputs(java.lang.String... inputs)
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
public CommandRunBuilder<C> listen(CommandRunBuilder.CommandListener<C> listener)
Simple listener to setup and cleanup something before and after command execution.- Parameters:
listener
- listener- Returns:
- builder instance for chained calls
-
runApp
public CommandResult<C> 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
public CommandResult<C> run(java.lang.String... args)
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
-
-