private void compareTupleQueryResults(TupleResult queryResult, TupleResult expectedResult)
throws Exception
{
// Create MutableTupleQueryResult to be able to re-iterate over the
// results
MutableTupleResult queryResultTable = new MutableTupleResult(queryResult);
MutableTupleResult expectedResultTable = new MutableTupleResult(expectedResult);
boolean resultsEqual;
if (laxCardinality) {
resultsEqual = QueryResultUtil.isSubset(queryResultTable, expectedResultTable);
}
else {
resultsEqual = QueryResultUtil.equals(queryResultTable, expectedResultTable);
}
if (!resultsEqual) {
queryResultTable.beforeFirst();
expectedResultTable.beforeFirst();
/*
* StringBuilder message = new StringBuilder(128);
* message.append("\n============ "); message.append(getName());
* message.append(" =======================\n");
* message.append("Expected result: \n"); while
* (expectedResultTable.hasNext()) {
* message.append(expectedResultTable.next()); message.append("\n"); }
* message.append("============="); StringUtil.appendN('=',
* getName().length(), message);
* message.append("========================\n"); message.append("Query
* result: \n"); while (queryResultTable.hasNext()) {
* message.append(queryResultTable.next()); message.append("\n"); }
* message.append("============="); StringUtil.appendN('=',
* getName().length(), message);
* message.append("========================\n");
*/
List<BindingSet> queryBindings = queryResultTable.asList();
List<BindingSet> expectedBindings = expectedResultTable.asList();
List<BindingSet> missingBindings = new ArrayList<BindingSet>(expectedBindings);
missingBindings.removeAll(queryBindings);
List<BindingSet> unexpectedBindings = new ArrayList<BindingSet>(queryBindings);