use of org.dbunit.DatabaseUnitException 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.DatabaseUnitException in project head by mifos.
the class DbUnitUtilities method verifySortedTableWithOrdering.
public void verifySortedTableWithOrdering(String tableName, IDataSet databaseDataSet, IDataSet expectedDataSet, String[] sortingColumns, Boolean actualDBComparableFlag, Boolean expectedDBComparableFlag) throws DataSetException, DatabaseUnitException {
Assert.assertNotNull("Didn't find requested table [" + tableName + "] in columnsToIgnoreWhenVerifyingTables map.", columnsToIgnoreWhenVerifyingTables.get(tableName));
ITable expectedTable = getCaseInsensitiveTable(tableName, expectedDataSet);
ITable actualTable = getCaseInsensitiveTable(tableName, databaseDataSet);
actualTable = DefaultColumnFilter.includedColumnsTable(actualTable, expectedTable.getTableMetaData().getColumns());
SortedTable sortedExpectedTable = new SortedTable(expectedTable, sortingColumns);
sortedExpectedTable.setUseComparable(expectedDBComparableFlag);
expectedTable = sortedExpectedTable;
SortedTable sortedActualTable = new SortedTable(actualTable, sortingColumns);
sortedActualTable.setUseComparable(actualDBComparableFlag);
actualTable = sortedActualTable;
if (LOG.isDebugEnabled()) {
printTable(expectedTable);
printTable(actualTable);
}
try {
Assertion.assertEqualsIgnoreCols(expectedTable, actualTable, columnsToIgnoreWhenVerifyingTables.get(tableName));
} catch (AssertionError e) {
throw new DatabaseUnitException(getTableDiff(expectedTable, actualTable), e);
}
}
use of org.dbunit.DatabaseUnitException 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);
}
}
use of org.dbunit.DatabaseUnitException in project head by mifos.
the class DbUnitUtilities method verifyTable.
/**
* Compare two tables using DbUnit DataSets
* @param tableName
* @param databaseDataSet
* @param expectedDataSet
* @throws DataSetException
* @throws DatabaseUnitException
*/
public void verifyTable(String tableName, IDataSet databaseDataSet, IDataSet expectedDataSet) throws DataSetException, DatabaseUnitException {
Assert.assertNotNull("Didn't find requested table [" + tableName + "] in columnsToIgnoreWhenVerifyingTables map.", columnsToIgnoreWhenVerifyingTables.get(tableName));
ITable expectedTable = getCaseInsensitiveTable(tableName, expectedDataSet);
ITable actualTable = getCaseInsensitiveTable(tableName, databaseDataSet);
actualTable = DefaultColumnFilter.includedColumnsTable(actualTable, expectedTable.getTableMetaData().getColumns());
try {
Assertion.assertEqualsIgnoreCols(expectedTable, actualTable, columnsToIgnoreWhenVerifyingTables.get(tableName));
} catch (AssertionError e) {
throw new DatabaseUnitException(getTableDiff(expectedTable, actualTable), e);
}
}
Aggregations