private Dataset setUpDataset(Query query, TestItem testItem) {
    try {
      // testItem.requiresTextIndex()

      if (doesQueryHaveDataset(query) && doesTestItemHaveDataset(testItem)) {
        // Only warn if there are results to test
        // Syntax tests may have FROM etc and a manifest data file.
        if (testItem.getResultFile() != null)
          Log.warn(this, testItem.getName() + " : query data source and also in test file");
      }

      // In test file?
      if (doesTestItemHaveDataset(testItem))
        // Not specified in the query - get from test item and load
        return createDataset(testItem.getDefaultGraphURIs(), testItem.getNamedGraphURIs());

      // Check 3 - were there any at all?

      if (!doesQueryHaveDataset(query)) fail("No dataset");

      // Left to query
      return null;

    } catch (JenaException jEx) {
      fail("JenaException creating data source: " + jEx.getMessage());
      return null;
    }
  }
  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 String makeDescription() {
    String tmp = "";
    if (testItem.getDefaultGraphURIs() != null) {
      for (Iterator<String> iter = testItem.getDefaultGraphURIs().iterator(); iter.hasNext(); )
        tmp = tmp + iter.next();
    }
    if (testItem.getNamedGraphURIs() != null) {
      for (Iterator<String> iter = testItem.getNamedGraphURIs().iterator(); iter.hasNext(); )
        tmp = tmp + iter.next();
    }

    String d = "Test " + testNumber + " :: " + testItem.getName();
    // +" :: QueryFile="+testItem.getQueryFile()+
    //          ", DataFile="+tmp+", ResultsFile="+testItem.getResultFile() ;
    return d;
  }
  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);
      }
    }
  }
  @Override
  protected void setUp() throws Exception {
    super.setUp();
    // SPARQL and ARQ tests are done with no value matching (for query execution and results
    // testing)
    resetNeeded = true;
    ARQ.setTrue(ARQ.strictGraph);
    // Turn parser warnings off for the test data.
    oldWarningFlag = CheckerLiterals.WarnOnBadLiterals;
    CheckerLiterals.WarnOnBadLiterals = false;

    // Sort out results.
    results = testItem.getResults();
  }
 public QueryTest(String testName, EarlReport earl, FileManager fm, TestItem t) {
   super(TestUtils.safeName(testName), t.getURI(), earl);
   queryFileManager = fm;
   testItem = t;
 }
 @Override
 public String toString() {
   if (testItem.getName() != null) return testItem.getName();
   return super.getName();
 }
 private static boolean doesTestItemHaveDataset(TestItem testItem) {
   boolean r =
       (testItem.getDefaultGraphURIs() != null && testItem.getDefaultGraphURIs().size() > 0)
           || (testItem.getNamedGraphURIs() != null && testItem.getNamedGraphURIs().size() > 0);
   return r;
 }