use of io.dropwizard.util.JarLocation in project dropwizard by dropwizard.
the class InheritedServerCommandTest method usesDefaultConfigPath.
@Test
void usesDefaultConfigPath() throws Exception {
class SingletonConfigurationFactory implements ConfigurationFactory<Configuration> {
@Override
public Configuration build(final ConfigurationSourceProvider provider, final String path) {
return configuration;
}
@Override
public Configuration build() {
throw new AssertionError("Didn't use the default config path variable");
}
}
when(configuration.getLoggingFactory()).thenReturn(mock(LoggingFactory.class));
final Bootstrap<Configuration> bootstrap = new Bootstrap<>(application);
bootstrap.setConfigurationFactoryFactory((klass, validator, objectMapper, propertyPrefix) -> new SingletonConfigurationFactory());
bootstrap.addCommand(new ConfiguredCommand<Configuration>("test", "a test command") {
@Override
protected void run(final Bootstrap<Configuration> bootstrap, final Namespace namespace, final Configuration configuration) {
assertThat(namespace.getString("file")).isNotEmpty().isEqualTo("yaml/server.yml");
}
@Override
protected Argument addFileArgument(final Subparser subparser) {
return super.addFileArgument(subparser).setDefault("yaml/server.yml");
}
});
final JarLocation location = mock(JarLocation.class);
when(location.toString()).thenReturn("dw-thing.jar");
when(location.getVersion()).thenReturn(Optional.of("1.0.0"));
Cli cli = new Cli(location, bootstrap, System.out, System.err);
cli.run("test");
}
use of io.dropwizard.util.JarLocation in project dropwizard by dropwizard.
the class Application method run.
/**
* Parses command-line arguments and runs the application. Call this method from a {@code public
* static void main} entry point in your application.
*
* @param arguments the command-line arguments
* @throws Exception if something goes wrong
*/
public void run(String... arguments) throws Exception {
final Bootstrap<T> bootstrap = new Bootstrap<>(this);
addDefaultCommands(bootstrap);
initialize(bootstrap);
// Should be called after initialize to give an opportunity to set a custom metric registry
bootstrap.registerMetrics();
final Cli cli = new Cli(new JarLocation(getClass()), bootstrap, System.out, System.err);
// only exit if there's an error running the command
cli.run(arguments).ifPresent(this::onFatalError);
}
use of io.dropwizard.util.JarLocation in project dropwizard by dropwizard.
the class CommandTest method setUp.
@BeforeEach
void setUp() {
final JarLocation location = mock(JarLocation.class);
final Bootstrap<Configuration> bootstrap = new Bootstrap<>(app);
when(location.toString()).thenReturn("dw-thing.jar");
when(location.getVersion()).thenReturn(Optional.of("1.0.0"));
bootstrap.addCommand(command);
cli = new Cli(location, bootstrap, stdOut, stdErr);
}
Aggregations