Search in sources :

Example 31 with Namespace

use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.

the class DbLocksCommandTest method testFailsWhenBothListAndRelease.

@Test
public void testFailsWhenBothListAndRelease() throws Exception {
    final Liquibase liquibase = Mockito.mock(Liquibase.class);
    assertThatExceptionOfType(IllegalArgumentException.class).isThrownBy(() -> locksCommand.run(new Namespace(ImmutableMap.of("list", true, "release", true)), liquibase)).withMessage("Must specify either --list or --force-release");
}
Also used : Liquibase(liquibase.Liquibase) Namespace(net.sourceforge.argparse4j.inf.Namespace) Test(org.junit.Test)

Example 32 with Namespace

use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.

the class DbMigrateDifferentFileCommandTest method testRunForFileFromFilesystem.

@Test
public void testRunForFileFromFilesystem() throws Exception {
    final String migrationsPath = new File(Resources.getResource("migrations.xml").toURI()).getAbsolutePath();
    migrateCommand.run(null, new Namespace(ImmutableMap.of("migrations-file", migrationsPath)), conf);
    try (Handle handle = new DBI(databaseUrl, "sa", "").open()) {
        assertThat(handle.select("select * from persons")).hasSize(1);
    }
}
Also used : DBI(org.skife.jdbi.v2.DBI) File(java.io.File) Namespace(net.sourceforge.argparse4j.inf.Namespace) Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Example 33 with Namespace

use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.

the class DbFastForwardCommandTest method testFastForwardFirst.

@Test
public void testFastForwardFirst() throws Exception {
    // Create the "persons" table manually
    try (Handle handle = dbi.open()) {
        handle.execute("create table persons(id int, name varchar(255))");
    }
    // Fast-forward one change
    fastForwardCommand.run(null, new Namespace(ImmutableMap.of("all", false, "dry-run", false)), conf);
    // 2nd and 3rd migrations is performed
    new DbMigrateCommand<>(TestMigrationConfiguration::getDataSource, TestMigrationConfiguration.class, "migrations.xml").run(null, new Namespace(ImmutableMap.of()), conf);
    // 1 entry has been added to the persons table
    try (Handle handle = dbi.open()) {
        assertThat(handle.createQuery("select count(*) from persons").mapTo(Integer.class).first()).isEqualTo(1);
    }
}
Also used : Namespace(net.sourceforge.argparse4j.inf.Namespace) Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Example 34 with Namespace

use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.

the class DbFastForwardCommandTest method testFastForwardAll.

@Test
public void testFastForwardAll() throws Exception {
    // Create the "persons" table manually and add some data
    try (Handle handle = dbi.open()) {
        handle.execute("create table persons(id int, name varchar(255))");
        handle.execute("insert into persons (id, name) values (12, 'Greg Young')");
    }
    // Fast-forward all the changes
    fastForwardCommand.run(null, new Namespace(ImmutableMap.of("all", true, "dry-run", false)), conf);
    // No migrations is performed
    new DbMigrateCommand<>(TestMigrationConfiguration::getDataSource, TestMigrationConfiguration.class, "migrations.xml").run(null, new Namespace(ImmutableMap.of()), conf);
    // Nothing is added to the persons table
    try (Handle handle = dbi.open()) {
        assertThat(handle.createQuery("select count(*) from persons").mapTo(Integer.class).first()).isEqualTo(1);
    }
}
Also used : Namespace(net.sourceforge.argparse4j.inf.Namespace) Handle(org.skife.jdbi.v2.Handle) Test(org.junit.Test)

Example 35 with Namespace

use of net.sourceforge.argparse4j.inf.Namespace in project dropwizard by dropwizard.

the class DbPrepareRollbackCommandTest method testPrepareOnlyChange.

@Test
public void testPrepareOnlyChange() throws Exception {
    final ByteArrayOutputStream baos = new ByteArrayOutputStream();
    prepareRollbackCommand.setOutputStream(new PrintStream(baos));
    prepareRollbackCommand.run(null, new Namespace(ImmutableMap.of("count", 1)), conf);
    assertThat(baos.toString(UTF_8)).contains("DROP TABLE PUBLIC.persons;");
}
Also used : PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Namespace(net.sourceforge.argparse4j.inf.Namespace) 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