use of org.dbunit.database.DatabaseConnection 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.database.DatabaseConnection in project head by mifos.
the class MifosIntegrationTestCase method dbVerificationSetUp.
private void dbVerificationSetUp() throws Exception {
if (verifyDatabaseState) {
excludeTables.excludeTable("BATCH_JOB_EXECUTION");
Connection connection = StaticHibernateUtil.getSessionTL().connection();
connection.setAutoCommit(false);
DatabaseConnection dbUnitConnection = new DatabaseConnection(connection);
latestDataDump = new FilteredDataSet(excludeTables, dbUnitConnection.createDataSet());
String tmpDir = System.getProperty("java.io.tmpdir") + System.getProperty("file.separator");
FlatXmlDataSet.write(latestDataDump, new FileOutputStream(tmpDir + "latestDataDump.xml"));
FlatXmlDataSetBuilder fxmlBuilder = new FlatXmlDataSetBuilder();
latestDataDump = fxmlBuilder.build(new File(tmpDir + "latestDataDump.xml"));
}
}
use of org.dbunit.database.DatabaseConnection 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.database.DatabaseConnection 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.database.DatabaseConnection in project head by mifos.
the class DatabaseTestUtils method saveTables.
/**
* Return the current contents of the specified tables as a DBUnit dataset as XML string.
* This method can be invoked safely inside a Spring-managed transaction.
*
* @param dataSource
* @param tableNames variable parameter list of table names
* @return XML string containing the current contents of the specified tables
* @throws IOException
* @throws DataSetException
* @throws SQLException
* @throws DatabaseUnitException
*/
@SuppressWarnings("PMD.DataflowAnomalyAnalysis")
public //Rationale: You cannot define new local variables in the try block because the finally block must reference it.
String saveTables(DriverManagerDataSource dataSource, String... tableNames) throws IOException, DataSetException, SQLException, DatabaseUnitException {
Connection jdbcConnection = null;
try {
jdbcConnection = DataSourceUtils.getConnection(dataSource);
ByteArrayOutputStream stream = new ByteArrayOutputStream();
FlatXmlDataSet.write(new DatabaseConnection(jdbcConnection).createDataSet(tableNames), stream);
return stream.toString();
} finally {
if (null != jdbcConnection) {
jdbcConnection.close();
}
DataSourceUtils.releaseConnection(jdbcConnection, dataSource);
}
}
Aggregations