Package org.openrdf.result

Examples of org.openrdf.result.TupleResult


      String chordataQuery = "SELECT DISTINCT * WHERE {<" + RNA_CHORDATA + "> ?P ?Y . } ";

      // first test: evaluate the query anonymously
      TupleQuery query = conn.prepareTupleQuery(QueryLanguage.SPARQL, chordataQuery);

      TupleResult tr = query.evaluate();
      try {
        assertFalse(
            "query result should be empty: item is protected and current user has no viewing permission",
            tr.hasNext());
      }
      finally {
        tr.close();
      }

      // second test: evaluate the query as an unauthorized user
      Session session = SessionManager.getOrCreate();
      session.setUsername("no_access");
      tr = query.evaluate();
      try {
        assertFalse(
            "query result should be empty: item is protected and current user has no viewing permission",
            tr.hasNext());
      }
      finally {
        tr.close();
      }

      // third test: evaluate the query as an authorized user
      session.setUsername("trezorix");
      tr = query.evaluate();
      try {
        assertTrue(
            "query result should not be empty: current user has viewing permission by inheritance",
            tr.hasNext());
      }
      finally {
        tr.close();
      }

      // fourth test: evaluate the query after user has logged out
      SessionManager.remove();
      tr = query.evaluate();
      try {
        assertFalse(
            "query result should be empty: item is protected and current user has no viewing permission",
            tr.hasNext());
      }
      finally {
        tr.close();
      }
    }
    finally {
      conn.close();
    }
View Full Code Here


      session.setUsername("trezorix");

      String conceptQuery = "SELECT DISTINCT ?X WHERE {?X a <" + SKOS_NS + "Concept" + "> ; ?P ?Y . } ";
      TupleQuery query = con.prepareTupleQuery(QueryLanguage.SPARQL, conceptQuery);

      TupleResult tr = query.evaluate();
      System.out.println(query.toString());

      try {
        List<String> headers = tr.getBindingNames();

        boolean nsrRetrieved = false;
        boolean animaliaRetrieved = false;
        while (tr.hasNext()) {
          BindingSet bs = tr.next();

          for (String header : headers) {
            Value value = bs.getValue(header);

            if (!nsrRetrieved && RNA_NSR.equals(value.stringValue())) {
              nsrRetrieved = true;
            }

            if (!animaliaRetrieved && RNA_ANIMALIA.equals(value.stringValue())) {
              animaliaRetrieved = true;
            }

            assertFalse(RNA_NATURALIS + " should not be retrieved",
                RNA_NATURALIS.equals(value.stringValue()));
          }
        }

        assertTrue(RNA_NSR + " was not retrieved", nsrRetrieved);
        assertTrue(RNA_ANIMALIA + " was not retrieved", animaliaRetrieved);

      }
      finally {
        tr.close();
      }
    }
    finally {
      con.close();
    }
View Full Code Here

  }

  private void assertQuery(String qry)
    throws Exception
  {
    TupleResult expected = reference.prepareTupleQuery(SPARQL, WHERE + qry).evaluate();
    TupleResult result = con.prepareTupleQuery(SPARQL, WHERE + qry).evaluate();
    compareTupleQueryResults(expected, result);
  }
View Full Code Here

    List<String> labels = new ArrayList<String>();
    RepositoryConnection con = repository.getConnection();
    try {
      assertTrue(con.size() > 0);
      TupleQuery qry = con.prepareTupleQuery(SPARQL, query);
      TupleResult result = qry.evaluate();
      try {
        while (result.hasNext()) {
          Value value = result.next().getValue(name);
          if (value == null) {
            labels.add(null);
          } else {
            labels.add(value.stringValue());
          }
        }
      }
      finally {
        result.close();
      }
    }
    finally {
      con.close();
    }
View Full Code Here

    String query = "SELECT testName, inputURL, outputURL " + "FROM {} mf:name {testName}; "
        + "        mf:result {outputURL}; " + "        mf:action {} qt:data {inputURL} "
        + "USING NAMESPACE " + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all positive parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testName = bindingSet.getValue("testName").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();
      String outputURL = bindingSet.getValue("outputURL").toString();

      String baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new PositiveParserTest(testName, inputURL, outputURL, baseURL));
    }

    queryResult.close();

    // Add the manifest for negative test cases to a repository and query it
    con.clear();
    url = TriGParserTestCase.class.getResource(MANIFEST_BAD_URL);
    con.add(url, base(url.toExternalForm()), RDFFormat.TURTLE);

    query = "SELECT testName, inputURL " + "FROM {} mf:name {testName}; "
        + "        mf:action {} qt:data {inputURL} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all negative parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testName = bindingSet.getValue("testName").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();

      String baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new NegativeParserTest(testName, inputURL, baseURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

        + "FROM {testURI} rdf:type {n3test:PositiveParserTest}; "
        + "               n3test:inputDocument {inputURL}; "
        + "               n3test:outputDocument {outputURL} "
        + "USING NAMESPACE n3test = <http://www.w3.org/2004/11/n3test#>";

    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testURI = bindingSet.getValue("testURI").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();
      String outputURL = bindingSet.getValue("outputURL").toString();

      suite.addTest(new PositiveParserTest(testURI, inputURL, outputURL));
    }

    queryResult.close();

    // Add all negative parser tests to the test suite
    query = "SELECT testURI, inputURL " + "FROM {testURI} rdf:type {n3test:NegativeParserTest}; "
        + "               n3test:inputDocument {inputURL} "
        + "USING NAMESPACE n3test = <http://www.w3.org/2004/11/n3test#>";

    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String testURI = bindingSet.getValue("testURI").toString();
      String inputURL = bindingSet.getValue("inputURL").toString();

      suite.addTest(new NegativeParserTest(testURI, inputURL));
    }
    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

    String query = "SELECT testName, inputURL, outputURL " + "FROM {} mf:name {testName}; "
        + "        mf:result {outputURL}; " + "        mf:action {} qt:data {inputURL} "
        + "USING NAMESPACE " + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";

    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all positive parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      testName = ((Literal)bindingSet.getValue("testName")).getLabel();
      inputURL = ((URI)bindingSet.getValue("inputURL")).toString();
      outputURL = ((URI)bindingSet.getValue("outputURL")).toString();

      baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new PositiveParserTest(testName, inputURL, outputURL, baseURL));
    }

    queryResult.close();

    // Add the manifest for negative test cases to a repository and query it
    con.clear();
    url = TurtleParserTestCase.class.getResource(MANIFEST_BAD_URL);
    con.add(url, base(url.toExternalForm()), RDFFormat.TURTLE);

    query = "SELECT testName, inputURL " + "FROM {} mf:name {testName}; "
        + "        mf:action {} qt:data {inputURL} " + "USING NAMESPACE "
        + "  mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
        + "  qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();

    // Add all negative parser tests to the test suite
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      testName = ((Literal)bindingSet.getValue("testName")).toString();
      inputURL = ((URI)bindingSet.getValue("inputURL")).toString();

      baseURL = BASE_URL + testName + ".ttl";

      suite.addTest(new NegativeParserTest(testName, inputURL, baseURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

        + "from {TESTCASE} rdf:type {test:PositiveParserTest}; "
        + "                test:inputDocument {INPUT}; "
        + "                test:outputDocument {OUTPUT}; "
        + "                test:status {\"APPROVED\"} "
        + "using namespace test = <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#>";
    TupleResult queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String caseURI = bindingSet.getValue("TESTCASE").toString();
      String inputURL = bindingSet.getValue("INPUT").toString();
      String outputURL = bindingSet.getValue("OUTPUT").toString();
      suite.addTest(new PositiveParserTest(caseURI, inputURL, outputURL));
    }

    queryResult.close();

    // Add all negative parser tests
    query = "select TESTCASE, INPUT " + "from {TESTCASE} rdf:type {test:NegativeParserTest}; "
        + "                test:inputDocument {INPUT}; " + "                test:status {\"APPROVED\"} "
        + "using namespace test = <http://www.w3.org/2000/10/rdf-tests/rdfcore/testSchema#>";
    queryResult = con.prepareTupleQuery(QueryLanguage.SERQL, query).evaluate();
    while (queryResult.hasNext()) {
      BindingSet bindingSet = queryResult.next();
      String caseURI = bindingSet.getValue("TESTCASE").toString();
      String inputURL = bindingSet.getValue("INPUT").toString();
      suite.addTest(new NegativeParserTest(caseURI, inputURL));
    }

    queryResult.close();
    con.close();
    repository.shutDown();

    return suite;
  }
View Full Code Here

  private void testQueryResultFormat(TupleQueryResultFormat format)
    throws IOException, QueryResultParseException, TupleQueryResultHandlerException,
    UnsupportedQueryResultFormatException, StoreException
  {
    TupleResult input = createQueryResult();
    TupleResult expected = createQueryResult();

    ByteArrayOutputStream out = new ByteArrayOutputStream(4096);
    QueryResultIO.write(input, format, out);
    input.close();

    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    TupleResult output = QueryResultIO.parse(in, format);

    assertTrue(QueryResultUtil.equals(expected, output));
  }
View Full Code Here

  }

  public NamespaceResult list()
    throws StoreException
  {
    TupleResult result = client.list();
    if (result == null) {
      return null;
    }
    return new NamespaceResultImpl(new ConvertingCursor<BindingSet, Namespace>(result) {
View Full Code Here

TOP

Related Classes of org.openrdf.result.TupleResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.