for (int i = 0; i < tables.length; i++) {
Table table = tables[i];
Column[] columns = table.getColumns();
Query query = mainDataContext.query().from(table).select(columns)
.toQuery();
DataSet dataSet = mainDataContext.executeQuery(query);
DataSet comparedDataSet = null;
if (comparedDataContext != null) {
Table comparedTable = comparedTables[i];
assertEquals(comparedTable.getName(), table.getName());
assertEquals(comparedTable.getColumnCount(),
table.getColumnCount());
Column[] comparedColumns = comparedTable.getColumns();
for (int j = 0; j < comparedColumns.length; j++) {
assertEquals(columns[j].getColumnNumber(),
comparedColumns[j].getColumnNumber());
}
Query comparedQuery = comparedDataContext.query()
.from(comparedTable).select(comparedColumns).toQuery();
comparedDataSet = comparedDataContext
.executeQuery(comparedQuery);
}
while (dataSet.next()) {
Row row = dataSet.getRow();
assertNotNull(row);
Object[] values = row.getValues();
assertEquals(values.length, table.getColumnCount());
if (comparedDataSet != null) {
boolean next = comparedDataSet.next();
assertTrue("No comparable row exists for: " + row, next);
Row comparedRow = comparedDataSet.getRow();
assertNotNull(comparedRow);
Object[] comparedValues = comparedRow.getValues();
assertEquals(comparedValues.length, table.getColumnCount());
for (int j = 0; j < comparedValues.length; j++) {
assertEquals(comparedValues[j], values[j]);
}
// compare styles
for (int j = 0; j < comparedValues.length; j++) {
Style style1 = comparedRow.getStyle(j);
Style style2 = row.getStyle(j);
assertEquals("Diff in style on row: " + row
+ " (value index = " + j + ")\nStyle 1: "
+ style1 + "\nStyle 2: " + style2 + ". ",
style1, style2);
}
}
}
dataSet.close();
if (comparedDataSet != null) {
assertFalse(comparedDataSet.next());
comparedDataSet.close();
}
}
}