use of org.dbunit.assertion.Difference in project sonarqube by SonarSource.
the class AbstractDbTester method assertDbUnit.
public void assertDbUnit(Class testClass, String filename, String[] excludedColumnNames, String... tables) {
IDatabaseConnection connection = null;
try {
connection = dbUnitConnection();
IDataSet dataSet = connection.createDataSet();
String path = "/" + testClass.getName().replace('.', '/') + "/" + filename;
InputStream inputStream = testClass.getResourceAsStream(path);
if (inputStream == null) {
throw new IllegalStateException(String.format("File '%s' does not exist", path));
}
IDataSet expectedDataSet = dbUnitDataSet(inputStream);
for (String table : tables) {
DiffCollectingFailureHandler diffHandler = new DiffCollectingFailureHandler();
ITable filteredTable = DefaultColumnFilter.excludedColumnsTable(dataSet.getTable(table), excludedColumnNames);
ITable filteredExpectedTable = DefaultColumnFilter.excludedColumnsTable(expectedDataSet.getTable(table), excludedColumnNames);
Assertion.assertEquals(filteredExpectedTable, filteredTable, diffHandler);
// Evaluate the differences and ignore some column values
List diffList = diffHandler.getDiffList();
for (Object o : diffList) {
Difference diff = (Difference) o;
if (!"[ignore]".equals(diff.getExpectedValue())) {
throw new DatabaseUnitException(diff.toString());
}
}
}
} catch (DatabaseUnitException e) {
e.printStackTrace();
fail(e.getMessage());
} catch (Exception e) {
throw translateException("Error while checking results", e);
} finally {
closeQuietly(connection);
}
}
Aggregations