package io.dropwizard.migrations; import com.google.common.collect.ImmutableMap; import liquibase.Liquibase; import net.jcip.annotations.NotThreadSafe; import net.sourceforge.argparse4j.inf.Namespace; import org.junit.Test; import org.mockito.Mockito; import java.io.ByteArrayOutputStream; import java.io.OutputStreamWriter; import java.io.PrintWriter; import static org.assertj.core.api.Assertions.assertThat; @NotThreadSafe public class DbClearChecksumsCommandTest extends AbstractMigrationTest { private DbClearChecksumsCommand<TestMigrationConfiguration> clearChecksums = new DbClearChecksumsCommand<>( TestMigrationConfiguration::getDataSource, TestMigrationConfiguration.class, "migrations.xml"); @Test public void testRun() throws Exception { final Liquibase liquibase = Mockito.mock(Liquibase.class); clearChecksums.run(new Namespace(ImmutableMap.of()), liquibase); Mockito.verify(liquibase).clearCheckSums(); } @Test public void testHelpPage() throws Exception { final ByteArrayOutputStream out = new ByteArrayOutputStream(); createSubparser(clearChecksums).printHelp(new PrintWriter(new OutputStreamWriter(out, UTF_8), true)); assertThat(out.toString(UTF_8)).isEqualTo(String.format( "usage: db clear-checksums [-h] [--migrations MIGRATIONS-FILE]%n" + " [--catalog CATALOG] [--schema SCHEMA] [file]%n" + "%n" + "Removes all saved checksums from the database log%n" + "%n" + "positional arguments:%n" + " file application configuration file%n" + "%n" + "optional arguments:%n" + " -h, --help show this help message and exit%n" + " --migrations MIGRATIONS-FILE%n" + " the file containing the Liquibase migrations for%n" + " the application%n" + " --catalog CATALOG Specify the database catalog (use database%n" + " default if omitted)%n" + " --schema SCHEMA Specify the database schema (use database default%n" + " if omitted)%n")); } }