Class CommandResult<C extends io.dropwizard.core.Configuration>
java.lang.Object
ru.vyarus.dropwizard.guice.test.cmd.CommandResult<C>
- Type Parameters:
C- configuration type
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
ConstructorsConstructorDescriptionCommandResult(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 TypeMethodDescriptionio.dropwizard.core.Application<C>io.dropwizard.core.setup.Bootstrap<C>io.dropwizard.core.cli.CommandCould 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.EnvironmentNote 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.com.google.inject.InjectorNote: injector created only forEnvironmentCommand.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
-
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 indicatorexception- exception instanceoutput- console outputerrorOutput- console error outputcommand- command instanceapp- application instancebootstrap- bootstrap instanceconfiguration- configuration instanceenvironment- environment instanceinjector- injector instance
-
-
Method Details
-
isSuccess
public boolean isSuccess()- Returns:
- true for successful execution, false is exception was thrown
-
getException
- Returns:
- exception, thrown during command execution (or null for successful execution)
-
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:
-
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
- Returns:
- application instance used for execution
-
getBootstrap
- Returns:
- bootstrap object used for execution
-
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)
-