use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbMigrateCommandTest method testDryRun.
@Test
public void testDryRun() throws Exception {
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
migrateCommand.setOutputStream(new PrintStream(baos));
migrateCommand.run(null, new Namespace(ImmutableMap.of("dry-run", (Object) true)), conf);
assertThat(baos.toString(UTF_8)).startsWith(String.format("-- *********************************************************************%n" + "-- Update Database Script%n" + "-- *********************************************************************%n"));
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbMigrateCommandTest method testRun.
@Test
public void testRun() throws Exception {
migrateCommand.run(null, new Namespace(ImmutableMap.of()), conf);
try (Handle handle = new DBI(databaseUrl, "sa", "").open()) {
final List<Map<String, Object>> rows = handle.select("select * from persons");
assertThat(rows).hasSize(1);
assertThat(rows.get(0)).isEqualTo(ImmutableMap.of("id", 1, "name", "Bill Smith", "email", "bill@smith.me"));
}
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbMigrateCustomSchemaTest method testRunMigrationWithCustomSchema.
@Test
public void testRunMigrationWithCustomSchema() throws Exception {
String schemaName = "customschema";
DBI dbi = new DBI(databaseUrl, "sa", "");
dbi.useHandle(h -> h.execute("create schema " + schemaName));
Namespace namespace = new Namespace(ImmutableMap.of("schema", schemaName, "catalog", "public"));
migrateCommand.run(null, namespace, conf);
dbi.useHandle(handle -> {
assertThat(handle.select("select * from " + schemaName + ".persons")).hasSize(1).contains(ImmutableMap.of("id", 1, "name", "Bill Smith", "email", "bill@smith.me"), Index.atIndex(0));
});
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class DbMigrateDifferentFileCommandTest method testRun.
@Test
public void testRun() throws Exception {
migrateCommand.run(null, new Namespace(ImmutableMap.of()), conf);
try (Handle handle = new DBI(databaseUrl, "sa", "").open()) {
final List<Map<String, Object>> rows = handle.select("select * from persons");
assertThat(rows).hasSize(0);
}
}
use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.
the class InheritedServerCommandTest method usesDefaultConfigPath.
@Test
public void usesDefaultConfigPath() throws Exception {
class SingletonConfigurationFactory implements ConfigurationFactory {
@Override
public Object build(final ConfigurationSourceProvider provider, final String path) throws IOException, ConfigurationException {
return configuration;
}
@Override
public Object build() throws IOException, ConfigurationException {
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) throws Exception {
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");
}
Aggregations