use of org.dbunit.dataset.IDataSet in project head by mifos.
the class MifosIntegrationTestCase method dbVerificationTearDown.
private void dbVerificationTearDown() throws Exception, FileNotFoundException, MalformedURLException {
if (verifyDatabaseState) {
Connection connection = StaticHibernateUtil.getSessionTL().connection();
connection.setAutoCommit(false);
DatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
IDataSet upgradeDataDump = new FilteredDataSet(excludeTables, dbUnitConnection.createDataSet());
String tmpDir = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator");
FlatXmlDataSet.write(upgradeDataDump, new FileOutputStream(tmpDir + "upgradeDataDump.xml"));
FlatXmlDataSetBuilder fxmlBuilder = new FlatXmlDataSetBuilder();
upgradeDataDump = fxmlBuilder.build(new File(tmpDir + "upgradeDataDump.xml"));
Assertion.assertEquals(latestDataDump, upgradeDataDump);
}
}
use of org.dbunit.dataset.IDataSet in project head by mifos.
the class DbUnitUtilities method dumpDatabase.
public void dumpDatabase(String fileName, Connection jdbcConnection) throws SQLException, DatabaseUnitException, FileNotFoundException, IOException {
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
IDataSet fullDataSet = connection.createDataSet();
FlatXmlDataSet.write(fullDataSet, new FileOutputStream(fileName));
}
use of org.dbunit.dataset.IDataSet in project head by mifos.
the class DbUnitUtilities method loadDataFromFile.
public void loadDataFromFile(String filename, DriverManagerDataSource dataSource) throws DatabaseUnitException, SQLException, IOException {
Connection jdbcConnection = null;
IDataSet dataSet = getDataSetFromDataSetDirectoryFile(filename);
try {
jdbcConnection = DataSourceUtils.getConnection(dataSource);
IDatabaseConnection databaseConnection = new DatabaseConnection(jdbcConnection);
DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
} finally {
if (jdbcConnection != null) {
jdbcConnection.close();
}
DataSourceUtils.releaseConnection(jdbcConnection, dataSource);
}
}
use of org.dbunit.dataset.IDataSet in project head by mifos.
the class AcceptanceDatabaseTestUtils method deleteDataFromTable.
public void deleteDataFromTable(String tableName, DriverManagerDataSource dataSource) throws IOException, DataSetException, SQLException, DatabaseUnitException {
StringReader dataSetXmlStream = new StringReader("<dataset><" + tableName + "/></dataset>");
IDataSet dataSet = new FlatXmlDataSet(dataSetXmlStream);
IDatabaseConnection databaseConnection = new DatabaseDataSourceConnection(dataSource);
databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
}
use of org.dbunit.dataset.IDataSet 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);
}
}
Aggregations