Search in sources :

Example 16 with Namespace

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

the class DbRollbackCommandTest method testRollbackToDateAsDryRun.

@Test
public void testRollbackToDateAsDryRun() throws Exception {
    // Migrate some DDL changes to the database
    long migrationDate = System.currentTimeMillis();
    migrateCommand.run(null, new Namespace(ImmutableMap.of()), conf);
    // Print out a rollback script for both changes after the migration date
    rollbackCommand.setOutputStream(new PrintStream(baos, true));
    rollbackCommand.run(null, new Namespace(ImmutableMap.of("date", new Date(migrationDate - 1000), "dry-run", true)), conf);
    assertThat(baos.toString(UTF_8)).containsIgnoringCase("ALTER TABLE PUBLIC.persons DROP COLUMN email;").containsIgnoringCase("DROP TABLE PUBLIC.persons;");
}
Also used : PrintStream(java.io.PrintStream) Namespace(net.sourceforge.argparse4j.inf.Namespace) Date(java.util.Date) Test(org.junit.Test)

Example 17 with Namespace

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

the class DbRollbackCommandTest method testRollbackNChanges.

@Test
public void testRollbackNChanges() throws Exception {
    // Migrate some DDL changes to the database
    migrateCommand.run(null, new Namespace(ImmutableMap.of()), conf);
    // Rollback the last one (the email field)
    rollbackCommand.run(null, new Namespace(ImmutableMap.of("count", 1)), conf);
    // Now we can add it
    dbi.useHandle(h -> h.execute("alter table persons add column email varchar(128)"));
}
Also used : Namespace(net.sourceforge.argparse4j.inf.Namespace) Test(org.junit.Test)

Example 18 with Namespace

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

the class DbRollbackCommandTest method testRollbackToTagAsDryRun.

@Test
public void testRollbackToTagAsDryRun() throws Exception {
    // Migrate the first DDL change to the database
    migrateCommand.run(null, new Namespace(ImmutableMap.of("count", 1)), conf);
    // Tag it
    final DbTagCommand<TestMigrationConfiguration> tagCommand = new DbTagCommand<>(new TestMigrationDatabaseConfiguration(), TestMigrationConfiguration.class, migrationsFileName);
    tagCommand.run(null, new Namespace(ImmutableMap.of("tag-name", ImmutableList.of("v1"))), conf);
    // Migrate the second change
    migrateCommand.run(null, new Namespace(ImmutableMap.of()), conf);
    // Print out the rollback script for the second change
    rollbackCommand.setOutputStream(new PrintStream(baos, true));
    rollbackCommand.run(null, new Namespace(ImmutableMap.of("tag", "v1", "dry-run", true)), conf);
    assertThat(baos.toString(UTF_8)).containsIgnoringCase("ALTER TABLE PUBLIC.persons DROP COLUMN email;");
}
Also used : PrintStream(java.io.PrintStream) Namespace(net.sourceforge.argparse4j.inf.Namespace) Test(org.junit.Test)

Example 19 with Namespace

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

the class DbLocksCommandTest method testListLocks.

@Test
public void testListLocks() throws Exception {
    final PrintStream printStream = new PrintStream(new ByteArrayOutputStream());
    locksCommand.setPrintStream(printStream);
    // We can't create locks in the database, so use mocks
    final Liquibase liquibase = Mockito.mock(Liquibase.class);
    locksCommand.run(new Namespace(ImmutableMap.of("list", true, "release", false)), liquibase);
    Mockito.verify(liquibase).reportLocks(printStream);
}
Also used : Liquibase(liquibase.Liquibase) PrintStream(java.io.PrintStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Namespace(net.sourceforge.argparse4j.inf.Namespace) Test(org.junit.Test)

Example 20 with Namespace

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

the class DbLocksCommandTest method testRelease.

@Test
public void testRelease() throws Exception {
    // We can't create locks in the database, so use mocks
    final Liquibase liquibase = Mockito.mock(Liquibase.class);
    locksCommand.run(new Namespace(ImmutableMap.of("list", false, "release", true)), liquibase);
    Mockito.verify(liquibase).forceReleaseLocks();
}
Also used : Liquibase(liquibase.Liquibase) 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