use of org.dbunit.dataset.IDataSet in project head by mifos.
the class DatabaseTestUtils method cleanAndInsertDataSet.
/**
* Execute a DbUnit CLEAN_INSERT. Parameter xmlString must be formatted as a DBUnit
* xml dataset. This method can be safely invoked inside a Spring-managed transaction.
* @param xmlString
* @param dataSource
* @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.
void cleanAndInsertDataSet(String xmlString, DriverManagerDataSource dataSource) throws IOException, DataSetException, SQLException, DatabaseUnitException {
StringReader dataSetXmlStream = new StringReader(xmlString);
IDataSet dataSet = new FlatXmlDataSet(dataSetXmlStream);
cleanAndInsertDataSet(dataSource, dataSet);
}
use of org.dbunit.dataset.IDataSet in project head by mifos.
the class DbUnitDataImportExport method loadDataFromFile.
private void loadDataFromFile(String fileName) throws DatabaseUnitException, SQLException, IOException, ClassNotFoundException {
Class.forName("com.mysql.jdbc.Driver");
Connection jdbcConnection = null;
boolean enableColumnSensing = true;
IDataSet dataSet = new FlatXmlDataSet(new File(fileName), false, enableColumnSensing);
try {
jdbcConnection = DriverManager.getConnection("jdbc:mysql://localhost/" + databaseName + "?sessionVariables=FOREIGN_KEY_CHECKS=0", user, password);
IDatabaseConnection databaseConnection = new DatabaseConnection(jdbcConnection);
databaseConnection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
DatabaseOperation.CLEAN_INSERT.execute(databaseConnection, dataSet);
} finally {
if (jdbcConnection != null) {
jdbcConnection.close();
}
}
}
use of org.dbunit.dataset.IDataSet in project head by mifos.
the class DbUnitDataImportExport method dumpData.
public void dumpData(String fileName) throws ClassNotFoundException, SQLException, DatabaseUnitException, FileNotFoundException, IOException {
// database connection
Class.forName("com.mysql.jdbc.Driver");
Connection jdbcConnection = null;
IDataSet fullDataSet;
try {
jdbcConnection = DriverManager.getConnection("jdbc:mysql://localhost/" + databaseName, user, password);
IDatabaseConnection connection = new DatabaseConnection(jdbcConnection);
connection.getConfig().setProperty(DatabaseConfig.FEATURE_CASE_SENSITIVE_TABLE_NAMES, Boolean.TRUE);
// sequenced data should not be necessary when foreign key constraints
// are turned off on the connection...
fullDataSet = connection.createDataSet();
FlatXmlDataSet.write(fullDataSet, new FileOutputStream(fileName));
} finally {
if (jdbcConnection != null) {
jdbcConnection.close();
}
}
}
use of org.dbunit.dataset.IDataSet in project head by mifos.
the class CollectionSheetEntryCustomerAccountTest method verifyCollectionSheetData.
@SuppressWarnings("PMD.SignatureDeclareThrowsException")
private // one of the dependent methods throws Exception
void verifyCollectionSheetData(String filename) throws Exception {
IDataSet expectedDataSet = dbUnitUtilities.getDataSetFromDataSetDirectoryFile(filename);
IDataSet databaseDataSet = dbUnitUtilities.getDataSetForTables(dataSource, new String[] { FEE_TRXN_DETAIL, ACCOUNT_TRXN, LOAN_TRXN_DETAIL, ACCOUNT_PAYMENT, LOAN_SUMMARY, LOAN_SCHEDULE, LOAN_ACTIVITY_DETAILS, ACCOUNT_STATUS_CHANGE_HISTORY, FINANCIAL_TRXN, CUSTOMER_ACCOUNT_ACTIVITY, CUSTOMER_TRXN_DETAIL });
verifyTransactionsAfterSortingTables(expectedDataSet, databaseDataSet);
}
use of org.dbunit.dataset.IDataSet in project sonarqube by SonarSource.
the class AbstractDbTester method assertDbUnitTable.
public void assertDbUnitTable(Class testClass, String filename, String table, String... columns) {
IDatabaseConnection connection = dbUnitConnection();
try {
IDataSet dataSet = connection.createDataSet();
String path = "/" + testClass.getName().replace('.', '/') + "/" + filename;
IDataSet expectedDataSet = dbUnitDataSet(testClass.getResourceAsStream(path));
ITable filteredTable = DefaultColumnFilter.includedColumnsTable(dataSet.getTable(table), columns);
ITable filteredExpectedTable = DefaultColumnFilter.includedColumnsTable(expectedDataSet.getTable(table), columns);
Assertion.assertEquals(filteredExpectedTable, filteredTable);
} catch (DatabaseUnitException e) {
fail(e.getMessage());
} catch (SQLException e) {
throw translateException("Error while checking results", e);
} finally {
closeQuietly(connection);
}
}
Aggregations