CleanupStrategyProvider implements StrategyProvider<CleanupStrategyExecutor<IDatabaseConnection, IDataSet>> { @Override public CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strictStrategy() { return (final IDatabaseConnection connection, final List<IDataSet> initialDataSets, final String... tablesToExclude) -> { try { IDataSet dataSet = excludeTables(connection.createDataSet(), tablesToExclude); dataSet = new FilteredDataSet(new DatabaseSequenceFilter(connection), dataSet); DatabaseOperation.DELETE_ALL.execute(connection, dataSet); } catch (final SQLException | DatabaseUnitException e) { throw new DbFeatureException(UNABLE_TO_CLEAN_DATABASE, e); } }; }  @Override CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strictStrategy(); @Override CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedTablesOnlyStrategy(); @Override CleanupStrategyExecutor<IDatabaseConnection, IDataSet> usedRowsOnlyStrategy();  }
@Test public void testStrictCleanupWithInitialDataSets() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.strictStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Arrays.asList(initialDataSet)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(0)); }
@Test public void testStrictCleanupWithInitialDataSetsExcludingOneTable() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.strictStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Arrays.asList(initialDataSet), "XML_TABLE_2"); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(0)); }
@Test public void testStrictCleanupWithoutInitialDataSets() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.strictStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Collections.emptyList()); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(0)); }
@Test public void testStrictCleanupWithoutInitialDataSetsExcludingOneTable() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.strictStrategy(); assertThat(strategyExecutor, notNullValue()); strategyExecutor.execute(connection, Collections.emptyList(), "XML_TABLE_2"); assertThat(getRecordCountFromTable(connection, "XML_TABLE_1"), equalTo(0)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_2"), equalTo(1)); assertThat(getRecordCountFromTable(connection, "XML_TABLE_3"), equalTo(0)); }
@Test(expected = DbFeatureException.class) public void testStrictCleanupOnClosedConnection() throws Exception { final CleanupStrategyProvider provider = new CleanupStrategyProvider(); final CleanupStrategyExecutor<IDatabaseConnection, IDataSet> strategyExecutor = provider.strictStrategy(); assertThat(strategyExecutor, notNullValue()); connection.close(); strategyExecutor.execute(connection, Arrays.asList()); }