final int expectedRowCount = expectedResults.size();
final int actualColumnCount = actualIdentifiers.size();
// Check for less records than in expected results
if (actualRowCount < expectedRowCount) {
throw new QueryTestFailedException(eMsg + "Expected " + expectedRowCount + //$NON-NLS-1$
" records but received only " + actualRowCount); //$NON-NLS-1$
} else if (actualRowCount > expectedRowCount) {
// Check also for more records than expected
throw new QueryTestFailedException(eMsg + "Expected " + expectedRowCount + //$NON-NLS-1$
" records but received " + actualRowCount); //$NON-NLS-1$
}
// DEBUG:
// debugOut.println("================== Compariing Rows ===================");
// Loop through rows
for (int row = 0; row < actualRowCount; row++) {
// Get actual record
final List actualRecord = (List)actualResults.get(row);
// Get expected record
final List expectedRecord = (List)expectedResults.get(row);
// DEBUG:
// debugOut.println("Row: " + (row + 1));
// debugOut.println(" expectedRecord: " + expectedRecord);
// debugOut.println(" actualRecord: " + actualRecord);
// Loop through columns
// Compare actual elements with expected elements column by column in this row
for (int col = 0; col < actualColumnCount; col++) {
// Get actual value
Object actualValue = actualRecord.get(col);
// Get expected value
Object expectedValue = expectedRecord.get(col);
// DEBUG:
// debugOut.println(" Col: " +(col +1) + ": expectedValue:[" + expectedValue + "] actualValue:[" + actualValue +
// "]");
// Compare these values
if ( ( expectedValue == null && actualValue != null) ||
(actualValue == null && expectedValue != null) ){
// Compare nulls
throw new QueryTestFailedException(eMsg + "Value mismatch at row " + (row + 1) //$NON-NLS-1$
+ " and column " + (col + 1) //$NON-NLS-1$
+ ": expected = [" //$NON-NLS-1$
+ (expectedValue!=null?expectedValue:"null") + "], actual = [" //$NON-NLS-1$
+ (actualValue!=null?actualValue:"null") + "]"); //$NON-NLS-1$
}
if (expectedValue == null && actualValue == null) {
continue;
}
if (actualValue instanceof Blob || actualValue instanceof Clob || actualValue instanceof SQLXML) {
if (actualValue instanceof Clob){
Clob c = (Clob)actualValue;
try {
actualValue = ObjectConverterUtil.convertToString(c.getAsciiStream());
} catch (Throwable e) {
// TODO Auto-generated catch block
throw new QueryTestFailedException(e);
}
} else if (actualValue instanceof Blob){
Blob b = (Blob)actualValue;
try {
actualValue = ObjectConverterUtil.convertToString(b.getBinaryStream());
} catch (Throwable e) {
// TODO Auto-generated catch block
throw new QueryTestFailedException(e);
}
} else if (actualValue instanceof SQLXML){
SQLXML s = (SQLXML)actualValue;
try {
actualValue = ObjectConverterUtil.convertToString(s.getBinaryStream());
} catch (Throwable e) {
// TODO Auto-generated catch block
throw new QueryTestFailedException(e);
}
}
if (!(expectedValue instanceof String)) {
expectedValue = expectedValue.toString();
}
}
// Compare values with equals
if (!expectedValue.equals(actualValue)) {
// DEBUG:
// debugOut.println(" ExpectedType: " + expectedValue.getClass() + " ActualType: " +
// actualValue.getClass());
if (expectedValue instanceof String) {
final String expectedString = (String)expectedValue;
// if (actualValue instanceof Blob || actualValue instanceof Clob || actualValue instanceof SQLXML) {
//
// Clob c = (Clob)actualValue;
// // LOB types are special case - metadata says they're Object types so
// // expected results are of type String. Actual object type is MMBlob, MMClob.
// // Must compare w/ String verion of actual!
// if (!expectedValue.equals(actualValue.toString())) {
// throw new QueryTestFailedException(eMsg + "LOB Value mismatch at row " + (row + 1) //$NON-NLS-1$
// + " and column " + (col + 1) //$NON-NLS-1$
// + ": expected = [" //$NON-NLS-1$
// + expectedValue + "], actual = [" //$NON-NLS-1$
// + actualValue + "]"); //$NON-NLS-1$
// }
// } else
if (!(actualValue instanceof String)) {
throw new QueryTestFailedException(eMsg + "Value mismatch at row " + (row + 1) //$NON-NLS-1$
+ " and column " + (col + 1) //$NON-NLS-1$
+ ": expected = [" //$NON-NLS-1$
+ expectedValue + "], actual = [" //$NON-NLS-1$
+ actualValue + "]"); //$NON-NLS-1$
} else if (expectedString.length() > 0) {
// Check for String difference
assertStringsMatch(expectedString, (String)actualValue, (row + 1), (col + 1), eMsg);
}
} else {
throw new QueryTestFailedException(eMsg + "Value mismatch at row " + (row + 1) //$NON-NLS-1$
+ " and column " + (col + 1) //$NON-NLS-1$
+ ": expected = [" //$NON-NLS-1$
+ expectedValue + "], actual = [" //$NON-NLS-1$
+ actualValue + "]"); //$NON-NLS-1$