use of org.dbunit.database.IDatabaseConnection in project sonarqube by SonarSource.
the class AbstractDbTester method dbUnitConnection.
private IDatabaseConnection dbUnitConnection() {
try {
IDatabaseConnection connection = db.getDbUnitTester().getConnection();
connection.getConfig().setProperty(DatabaseConfig.PROPERTY_DATATYPE_FACTORY, db.getDbUnitFactory());
return connection;
} catch (Exception e) {
throw translateException("Error while getting connection", e);
}
}
use of org.dbunit.database.IDatabaseConnection 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);
}
}
use of org.dbunit.database.IDatabaseConnection in project sonarqube by SonarSource.
the class AbstractDbTester method prepareDbUnit.
private void prepareDbUnit(InputStream... dataSetStream) {
IDatabaseConnection connection = null;
try {
IDataSet[] dataSets = new IDataSet[dataSetStream.length];
for (int i = 0; i < dataSetStream.length; i++) {
dataSets[i] = dbUnitDataSet(dataSetStream[i]);
}
db.getDbUnitTester().setDataSet(new CompositeDataSet(dataSets));
connection = dbUnitConnection();
new InsertIdentityOperation(DatabaseOperation.INSERT).execute(connection, db.getDbUnitTester().getDataSet());
} catch (Exception e) {
throw translateException("Could not setup DBUnit data", e);
} finally {
closeQuietly(connection);
}
}
use of org.dbunit.database.IDatabaseConnection 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.IDatabaseConnection 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);
}
}
Aggregations