Search in sources :

Example 21 with Namespace

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"));
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Namespace(net.sourceforge.argparse4j.inf.Namespace) Test(org.junit.Test)

Example 22 with Namespace

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"));
    }
}
Also used : DBI(org.skife.jdbi.v2.DBI) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Namespace(net.sourceforge.argparse4j.inf.Namespace) Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Example 23 with Namespace

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));
    });
}
Also used : DBI(org.skife.jdbi.v2.DBI) Namespace(net.sourceforge.argparse4j.inf.Namespace) Test(org.junit.Test)

Example 24 with Namespace

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);
    }
}
Also used : DBI(org.skife.jdbi.v2.DBI) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) Namespace(net.sourceforge.argparse4j.inf.Namespace) Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Example 25 with Namespace

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");
}
Also used : LoggingFactory(io.dropwizard.logging.LoggingFactory) JarLocation(io.dropwizard.util.JarLocation) Configuration(io.dropwizard.Configuration) Argument(net.sourceforge.argparse4j.inf.Argument) Namespace(net.sourceforge.argparse4j.inf.Namespace) IOException(java.io.IOException) ConfigurationException(io.dropwizard.configuration.ConfigurationException) ConfigurationSourceProvider(io.dropwizard.configuration.ConfigurationSourceProvider) ConfigurationFactory(io.dropwizard.configuration.ConfigurationFactory) Subparser(net.sourceforge.argparse4j.inf.Subparser) Bootstrap(io.dropwizard.setup.Bootstrap) Test(org.junit.Test)

Aggregations

Namespace (net.sourceforge.argparse4j.inf.Namespace)46 Test (org.junit.Test)36 PrintStream (java.io.PrintStream)9 Handle (org.skife.jdbi.v2.Handle)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 Liquibase (liquibase.Liquibase)6 ArgumentParserException (net.sourceforge.argparse4j.inf.ArgumentParserException)6 DBI (org.skife.jdbi.v2.DBI)6 ArgumentParser (net.sourceforge.argparse4j.inf.ArgumentParser)5 IOException (java.io.IOException)4 Properties (java.util.Properties)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 File (java.io.File)3 Configuration (io.dropwizard.Configuration)2 Bootstrap (io.dropwizard.setup.Bootstrap)2 ArrayList (java.util.ArrayList)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 Element (org.w3c.dom.Element)2