Class CommandResult<C extends io.dropwizard.core.Configuration>

java.lang.Object
ru.vyarus.dropwizard.guice.test.cmd.CommandResult<C>
Type Parameters:
C - configuration type

public class CommandResult<C extends io.dropwizard.core.Configuration> extends Object
Dropwizard command execution result. Note that command execution never throws exceptions: instead, all thrown exceptions are intercepted and provided as the unsuccessful execution result.

Depending on executed command type, some object might be null (injector would be available only for environment commands).

Output contains both out and err streams (to simulate console view, when both streams are shown in console). Error output is also collected separately for validation (all these messages are present in common output too).

Since:
20.11.2023
  • Constructor Summary

    Constructors
    Constructor
    Description
    CommandResult(boolean success, Throwable exception, String output, String errorOutput, io.dropwizard.core.cli.Command command, io.dropwizard.core.Application<C> app, io.dropwizard.core.setup.Bootstrap<C> bootstrap, C configuration, io.dropwizard.core.setup.Environment environment, com.google.inject.Injector injector)
    Command result.
  • Method Summary

    Modifier and Type
    Method
    Description
    io.dropwizard.core.Application<C>
     
    io.dropwizard.core.setup.Bootstrap<C>
     
    io.dropwizard.core.cli.Command
    Could be null only if incorrect command name was specified (in this case help message would be shown by dropwizard instead of execution).
    Could be null for command without configuration and in case of configuration parse errors.
    io.dropwizard.core.setup.Environment
     
    Note that default command Command.onError(io.dropwizard.core.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
     
    com.google.inject.Injector
    Note: injector created only for EnvironmentCommand.
    Note that default command Command.onError(io.dropwizard.core.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
    boolean
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • CommandResult

      public CommandResult(boolean success, @Nullable Throwable exception, String output, String errorOutput, @Nullable io.dropwizard.core.cli.Command command, io.dropwizard.core.Application<C> app, io.dropwizard.core.setup.Bootstrap<C> bootstrap, @Nullable C configuration, @Nullable io.dropwizard.core.setup.Environment environment, @Nullable com.google.inject.Injector injector)
      Command result.
      Parameters:
      success - success indicator
      exception - exception instance
      output - console output
      errorOutput - console error output
      command - command instance
      app - application instance
      bootstrap - bootstrap instance
      configuration - configuration instance
      environment - environment instance
      injector - injector instance
  • Method Details

    • isSuccess

      public boolean isSuccess()
      Returns:
      true for successful execution, false is exception was thrown
    • getException

      @Nullable public Throwable getException()
      Returns:
      exception, thrown during command execution (or null for successful execution)
    • getOutput

      public String getOutput()
      Note that default command Command.onError(io.dropwizard.core.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
      Returns:
      console output (together with error stream to get output exactly as it would be in console) or empty string if no output
      See Also:
    • getErrorOutput

      public String getErrorOutput()
      Note that default command Command.onError(io.dropwizard.core.cli.Cli, net.sourceforge.argparse4j.inf.Namespace, Throwable) implementation simply prints error stack trace to console, so output would contain this trace.
      Returns:
      error output or empty string
    • getCommand

      @Nullable public io.dropwizard.core.cli.Command getCommand()
      Could be null only if incorrect command name was specified (in this case help message would be shown by dropwizard instead of execution). In all other cases command should not be null (it is searched manually in the bootstrap object before execution).
      Returns:
      command instance, used for execution
    • getApplication

      public io.dropwizard.core.Application<C> getApplication()
      Returns:
      application instance used for execution
    • getBootstrap

      public io.dropwizard.core.setup.Bootstrap<C> getBootstrap()
      Returns:
      bootstrap object used for execution
    • getConfiguration

      @Nullable public C getConfiguration()
      Could be null for command without configuration and in case of configuration parse errors.
      Returns:
      configuration instance used or null
    • getEnvironment

      @Nullable public io.dropwizard.core.setup.Environment getEnvironment()
      Returns:
      environment instance or null (for non-environment commands or startup error)
    • getInjector

      @Nullable public com.google.inject.Injector getInjector()
      Note: injector created only for EnvironmentCommand.
      Returns:
      injector instance or null (for non-environment commands or due to injector startup errors)