/** * Use the provided databaseTester to prep the database with the provided prep dataset. See {@link * org.dbunit.IDatabaseTester#onSetup()}. * * @throws Exception */ public void setupData() throws Exception { LOG.debug("setupData: setting prep dataset and inserting rows"); if (databaseTester == null) { throw new IllegalStateException("databaseTester is null; must configure or set it first"); } databaseTester.setDataSet(prepDs); databaseTester.onSetup(); }
protected void setUp() throws Exception { logger.debug("setUp() - start"); super.setUp(); final IDatabaseTester databaseTester = getDatabaseTester(); assertNotNull("DatabaseTester is not set", databaseTester); databaseTester.setSetUpOperation(getSetUpOperation()); databaseTester.setDataSet(getDataSet()); databaseTester.setOperationListener(getOperationListener()); databaseTester.onSetup(); }
/** {@inheritDoc} */ public void cleanupData() throws Exception { IDataSet dataset = new CompositeDataSet(prepDs, expectedDs); String tableNames[] = dataset.getTableNames(); int count = tableNames.length; LOG.info("cleanupData: about to clean up {} tables={}", new Integer(count), tableNames); if (databaseTester == null) { throw new IllegalStateException("databaseTester is null; must configure or set it first"); } databaseTester.setDataSet(dataset); databaseTester.onTearDown(); LOG.debug("cleanupData: Clean up done"); }
protected void tearDown() throws Exception { logger.debug("tearDown() - start"); try { final IDatabaseTester databaseTester = getDatabaseTester(); assertNotNull("DatabaseTester is not set", databaseTester); databaseTester.setTearDownOperation(getTearDownOperation()); databaseTester.setDataSet(getDataSet()); databaseTester.setOperationListener(getOperationListener()); databaseTester.onTearDown(); } finally { tester = null; super.tearDown(); } }
/** {@inheritDoc} Uses the connection from the provided databaseTester. */ public void verifyData() throws Exception { if (databaseTester == null) { throw new IllegalStateException("databaseTester is null; must configure or set it first"); } IDatabaseConnection connection = databaseTester.getConnection(); try { int count = tableDefs.length; LOG.info("verifyData: about to verify {} tables={}", new Integer(count), tableDefs); if (count == 0) { LOG.warn("verifyData: No tables to verify;" + " no VerifyTableDefinitions specified"); } for (int i = 0; i < count; i++) { VerifyTableDefinition td = tableDefs[i]; String[] excludeColumns = td.getColumnExclusionFilters(); String[] includeColumns = td.getColumnInclusionFilters(); String tableName = td.getTableName(); LOG.info("verifyData: Verifying table '{}'", tableName); LOG.debug("verifyData: Loading its rows from expected dataset"); ITable expectedTable = null; try { expectedTable = expectedDs.getTable(tableName); } catch (Exception e) { final String msg = "verifyData: Problem obtaining table '" + tableName + "' from expected dataset"; LOG.error(msg, e); throw new DataSetException(msg, e); } LOG.debug("verifyData: Loading its rows from actual table"); ITable actualTable = null; try { actualTable = connection.createTable(tableName); } catch (Exception e) { final String msg = "verifyData: Problem obtaining table '" + tableName + "' from actual dataset"; LOG.error(msg, e); throw new DataSetException(msg, e); } verifyData(expectedTable, actualTable, excludeColumns, includeColumns); } } finally { LOG.debug("verifyData: Verification done, closing connection"); connection.close(); } }