void printFailedResultSetTest( Query query, QueryExecution qe, ResultSetRewindable qrExpected, ResultSetRewindable qrActual) { PrintStream out = System.out; out.println(); out.println("======================================="); out.println("Failure: " + description()); out.println("Query: \n" + query); // if ( qe != null && qe.getDataset() != null ) // { // out.println("Data: \n"+qe.getDataset().asDatasetGraph()) ; // } out.println("Got: " + qrActual.size() + " --------------------------------"); qrActual.reset(); ResultSetFormatter.out(out, qrActual, query.getPrefixMapping()); qrActual.reset(); out.flush(); out.println("Expected: " + qrExpected.size() + " -----------------------------"); qrExpected.reset(); ResultSetFormatter.out(out, qrExpected, query.getPrefixMapping()); qrExpected.reset(); out.println(); out.flush(); }
public static boolean resultSetEquivalent( Query query, ResultSetRewindable resultsExpected, ResultSetRewindable resultsActual) { final boolean testByValue = true; if (testByValue) { if (query.isOrdered()) return ResultSetCompare.equalsByValueAndOrder(resultsExpected, resultsActual); else return ResultSetCompare.equalsByValue(resultsExpected, resultsActual); } else { if (query.isOrdered()) return ResultSetCompare.equalsByTermAndOrder(resultsExpected, resultsActual); else return ResultSetCompare.equalsByTerm(resultsExpected, resultsActual); } }
@Override protected void runTestForReal() throws Throwable { Query query = null; try { try { query = queryFromTestItem(testItem); } catch (QueryException qEx) { query = null; qEx.printStackTrace(System.err); fail("Parse failure: " + qEx.getMessage()); throw qEx; } Dataset dataset = setUpDataset(query, testItem); if (dataset == null && !doesQueryHaveDataset(query)) fail("No dataset for query"); QueryExecution qe = null; if (dataset == null) qe = QueryExecutionFactory.create(query, queryFileManager); else qe = QueryExecutionFactory.create(query, dataset); try { if (query.isSelectType()) runTestSelect(query, qe); else if (query.isConstructType()) runTestConstruct(query, qe); else if (query.isDescribeType()) runTestDescribe(query, qe); else if (query.isAskType()) runTestAsk(query, qe); } finally { qe.close(); } } catch (IOException ioEx) { // log.debug("IOException: ",ioEx) ; fail("IOException: " + ioEx.getMessage()); throw ioEx; } catch (NullPointerException ex) { throw ex; } catch (Exception ex) { ex.printStackTrace(System.err); fail("Exception: " + ex.getClass().getName() + ": " + ex.getMessage()); } }
void runTestSelect(Query query, QueryExecution qe) throws Exception { // Do the query! ResultSetRewindable resultsActual = ResultSetFactory.makeRewindable(qe.execSelect()); qe.close(); if (results == null) return; // Assumes resultSetCompare can cope with full isomorphism possibilities. ResultSetRewindable resultsExpected; if (results.isResultSet()) resultsExpected = ResultSetFactory.makeRewindable(results.getResultSet()); else if (results.isModel()) resultsExpected = ResultSetFactory.makeRewindable(results.getModel()); else { fail("Wrong result type for SELECT query"); resultsExpected = null; // Keep the compiler happy } if (query.isReduced()) { // Reduced - best we can do is DISTINCT resultsExpected = unique(resultsExpected); resultsActual = unique(resultsActual); } // Hack for CSV : tests involving bNodes need manually checking. if (testItem.getResultFile().endsWith(".csv")) { resultsActual = convertToStrings(resultsActual); resultsActual.reset(); int nActual = ResultSetFormatter.consume(resultsActual); int nExpected = ResultSetFormatter.consume(resultsExpected); resultsActual.reset(); resultsExpected.reset(); assertEquals("CSV: Different number of rows", nExpected, nActual); boolean b = resultSetEquivalent(query, resultsExpected, resultsActual); if (!b) System.out.println("Manual check of CSV results required: " + testItem.getName()); return; } boolean b = resultSetEquivalent(query, resultsExpected, resultsActual); if (!b) { resultsExpected.reset(); resultsActual.reset(); boolean b2 = resultSetEquivalent(query, resultsExpected, resultsActual); printFailedResultSetTest(query, qe, resultsExpected, resultsActual); } assertTrue("Results do not match: " + testItem.getName(), b); return; }
private void compareGraphResults(Model resultsActual, Query query) { if (results != null) { try { if (!results.isGraph()) fail("Expected results are not a graph: " + testItem.getName()); Model resultsExpected = results.getModel(); if (!resultsExpected.isIsomorphicWith(resultsActual)) { printFailedModelTest(query, resultsExpected, resultsActual); fail("Results do not match: " + testItem.getName()); } } catch (Exception ex) { String typeName = (query.isConstructType() ? "construct" : "describe"); fail("Exception in result testing (" + typeName + "): " + ex); } } }
private static boolean doesQueryHaveDataset(Query query) { return query.hasDatasetDescription(); }