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 for 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
  • Constructor Details

    • CommandRunBuilder

      public CommandRunBuilder(Class<? extends io.dropwizard.core.Application<C>> app)
      Create builder.
      Parameters:
      app - application class
  • Method Details

    • consoleInputs

      public CommandRunBuilder<C> consoleInputs(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

      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 for run("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(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