use of org.dbunit.IDatabaseTester in project sharding-jdbc by dangdangdotcom.
the class AbstractDBUnitTest method importDataSet.
@Before
public final void importDataSet() throws Exception {
for (String each : getDataSetFiles()) {
InputStream is = AbstractDBUnitTest.class.getClassLoader().getResourceAsStream(each);
IDataSet dataSet = new FlatXmlDataSetBuilder().build(new InputStreamReader(is));
IDatabaseTester databaseTester = new ShardingJdbcDatabaseTester(dbEnv.getDriverClassName(), dbEnv.getURL(getFileName(each)), dbEnv.getUsername(), dbEnv.getPassword());
databaseTester.setSetUpOperation(DatabaseOperation.CLEAN_INSERT);
databaseTester.setDataSet(dataSet);
databaseTester.onSetup();
}
}
use of org.dbunit.IDatabaseTester in project head by mifos.
the class DatabaseTestUtils method verifyTable.
/**
* Verify that a database table matches a dataSet table. dataSetXml must be formatted as a DBUnit
* xml dataset. This method can be safely invoked inside a Spring-managed transaction.
* @param dataSetXml
* @param tableName
* @param dataSource
* @throws Exception
*/
// one of the dependent methods throws Exception
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public void verifyTable(String dataSetXml, String tableName, DriverManagerDataSource dataSource) throws Exception {
Connection jdbcConnection = null;
StringReader dataSetXmlStream = new StringReader(dataSetXml);
try {
jdbcConnection = DataSourceUtils.getConnection(dataSource);
IDatabaseTester databaseTester = new DataSourceDatabaseTester(dataSource);
IDatabaseConnection databaseConnection = databaseTester.getConnection();
databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
IDataSet databaseDataSet = databaseConnection.createDataSet();
ITable actualTable = databaseDataSet.getTable(tableName);
IDataSet expectedDataSet = new FlatXmlDataSet(dataSetXmlStream);
ITable expectedTable = expectedDataSet.getTable(tableName);
Assertion.assertEqualsIgnoreCols(expectedTable, actualTable, new String[] { "id" });
} finally {
if (null != jdbcConnection) {
jdbcConnection.close();
}
DataSourceUtils.releaseConnection(jdbcConnection, dataSource);
}
}
use of org.dbunit.IDatabaseTester in project head by mifos.
the class DbUnitUtilities method getDataSetForTables.
/**
* Returns a DbUnit DataSet for several tables.
* @param driverManagerDataSource TODO
* @param tableNames
* @return IDataSet
* @throws Exception
*/
// one of the dependent methods throws Exception
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
public IDataSet getDataSetForTables(DriverManagerDataSource driverManagerDataSource, String[] tableNames) throws Exception {
Connection jdbcConnection = null;
IDataSet databaseDataSet = null;
try {
jdbcConnection = DataSourceUtils.getConnection(driverManagerDataSource);
IDatabaseTester databaseTester = new DataSourceDatabaseTester(driverManagerDataSource);
IDatabaseConnection databaseConnection = databaseTester.getConnection();
databaseDataSet = databaseConnection.createDataSet(tableNames);
} finally {
jdbcConnection.close();
DataSourceUtils.releaseConnection(jdbcConnection, driverManagerDataSource);
}
return databaseDataSet;
}
Aggregations