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 java.lang.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, java.lang.Throwable exception, java.lang.String output, java.lang.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)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description io.dropwizard.core.Application<C>
getApplication()
io.dropwizard.core.setup.Bootstrap<C>
getBootstrap()
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).C
getConfiguration()
Could be null for command without configuration and in case of configuration parse errors.io.dropwizard.core.setup.Environment
getEnvironment()
java.lang.String
getErrorOutput()
Note that default commandCommand.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.java.lang.Throwable
getException()
com.google.inject.Injector
getInjector()
Note: injector created only forEnvironmentCommand
.java.lang.String
getOutput()
Note that default commandCommand.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
isSuccess()
-
-
-
Constructor Detail
-
CommandResult
public CommandResult(boolean success, @Nullable java.lang.Throwable exception, java.lang.String output, java.lang.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)
-
-
Method Detail
-
isSuccess
public boolean isSuccess()
- Returns:
- true for successful execution, false is exception was thrown
-
getException
@Nullable public java.lang.Throwable getException()
- Returns:
- exception, thrown during command execution (or null for successful execution)
-
getOutput
public java.lang.String getOutput()
Note that default commandCommand.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:
for error output only
-
getErrorOutput
public java.lang.String getErrorOutput()
Note that default commandCommand.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 forEnvironmentCommand
.- Returns:
- injector instance or null (for non-environment commands or due to injector startup errors)
-
-