marcphilipp/dbunit-datasetbuilder — Issue #1: Empty table not built properly
Author: pioterj
Created: 2012-02-19 09:15:09+00:00
State: open

Using XML data set you can assert that some table has no rows using adding an empty element. For example:

I use the following code with the above data set to assert that the database is in expected state:

IDataSet actualDataSet = databaseTester.getConnection().createDataSet();
if (logger.isDebugEnabled()) {
logger.debug("assert has data set:\n{}", dataSetToString(expectedDataSet));
}
ITableIterator tableIterator = expectedDataSet.iterator();
while (tableIterator.next()) {
ITable expectedTable = tableIterator.getTable();
String expectedTableName = expectedTable.getTableMetaData().getTableName();
SortedTable sortedExpectedTable = new SortedTable(expectedTable);
sortedExpectedTable.setUseComparable(true);
ITable actualTable = actualDataSet.getTable(expectedTableName);
SortedTable sortedActualTable = new SortedTable(actualTable);
sortedActualTable.setUseComparable(true);
assertEqualsIgnoreCols(sortedExpectedTable, sortedActualTable, ignoredColumns());
}

If dataset is read from XML it will work but when I use the builder like this it won't:

builder.newRow("PERSON").add();

The reason is that in this case the empty row is added to the data set's table map. It doesn't work this way in Flat XML data set reader.

The solution is to change notifyConsumer() method in DataSetBuilder like this:

private void notifyConsumer(Object[] values) throws DataSetException {
if (values.length > 0) {
consumer.row(values);
}
}