I'm trying to do a DbUnit data verification in an insert operation between a table in XML file and a table in the database. I´ve sorted both tables by "ID" and then ignored it in the comparison because its value is auto incremental and I don´t know what it is, but not well ordered. Here is the code according to the DbUnit documentation:
IDataSet databaseDataSet = getConnection().createDataSet();
ITable actualTable = databaseDataSet.getTable("TYPES");
FlatXmlDataSetBuilder flatXmlDataSetBuilder = new FlatXmlDataSetBuilder();
flatXmlDataSetBuilder.setColumnSensing(true);
FileInputStream fileInputStream = new FileInputStream(xml);
IDataSet expectedDataset = flatXmlDataSetBuilder.build(fileInputStream);
ITable expectedTable = expectedDataset.getTable("TYPES");
SortedTable sortedExpected = new SortedTable(expectedTable, new String[]{"ID"});
sortedExpected.setUseComparable(true);
SortedTable sortedActual = new SortedTable(actualTable, new String[]{"ID"});
sortedActual.setUseComparable(true);
Assertion.assertEqualsIgnoreCols(sortedExpected, sortedActual, new String[] {"ID"});
Current XML:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<TYPES ID="7" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
<TYPES ID="6" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="3" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="1" PARENTESCO="Padre/Madre politíco/a" USUARIOMOD="W"/>
<TYPES ID="4" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="5" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
<TYPES ID="1051" PARENTESCO="Primo" USUARIOMOD="A"/>
</dataset>
Expected XML:
<?xml version="1.0" encoding="UTF-8"?>
<dataset>
<TYPES ID="7" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
<TYPES ID="6" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="3" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="1" PARENTESCO="Padre/Madre politíco/a" USUARIOMOD="W"/>
<TYPES ID="4" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="5" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
<TYPES PARENTESCO="Primo" USUARIOMOD="A"/>
</dataset>
The last row is the row inserted. I don't specify the ID because I don't know what it is.
After sorting:
sortedActual:
<TYPES ID="1" PARENTESCO="Padre/Madre politíco/a" USUARIOMOD="W"/>
<TYPES ID="1051" PARENTESCO="Primo" USUARIOMOD="A"/>
<TYPES ID="3" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="4" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="5" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
<TYPES ID="6" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="7" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
sortedExpected:
<TYPES PARENTESCO="Primo" USUARIOMOD="A"/>
<TYPES ID="1" PARENTESCO="Padre/Madre politíco/a" USUARIOMOD="W"/>
<TYPES ID="3" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="4" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="5" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
<TYPES ID="6" PARENTESCO="Hijo/a" USUARIOMOD="q"/>
<TYPES ID="7" PARENTESCO="Cónyuge" USUARIOMOD="W"/>
Rows order is incorrect due to it´s sorted as a String and "ID" is numeric, so the comparison fails. Any ideas?