Examples of Solutions


Examples of spark.api.Solutions

    Connection conn = ds.getConnection(NoCredentials.INSTANCE);
    Command command = conn.createCommand(query);
    command.setTimeout(120000);
   
    System.out.println("Executing query....");
    Solutions results = command.executeQuery();
   
    System.out.println("\nResults:");
    int count = 0;
    Iterator<Map<String,RDFNode>> iter = results.iterator();
    for (; iter.hasNext(); ) {
      Map<String,RDFNode> tuple = iter.next();
      count++;
      for(Map.Entry<String, RDFNode> entry : tuple.entrySet()) {
        System.out.print("\t" + entry.getKey() + ": " + entry.getValue());
View Full Code Here

Examples of spark.api.Solutions

 
  public void helpTestQueryCursor(int resultRows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(resultRows);

    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);

      TestCursor.assertCursor(solutions, BEFORE_FIRST);
     
      int counter = 0;
      while (solutions.next()) {
        Map<String,RDFNode> solution = solutions.getResult();
        Assert.assertNotNull(solution);
        Assert.assertEquals(++counter, solutions.getRow());
        int state = ((counter == 1) ? FIRST : NONE) | ((counter == resultRows) ? LAST : NONE);
        TestCursor.assertCursor(solutions, state);
      }

      TestCursor.assertCursor(solutions, AFTER_LAST);
View Full Code Here

Examples of spark.api.Solutions

  }

  public void helpTestIteratorNormal(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator in a normal fashion.
      while (iter.hasNext()) {
        data.add(iter.next());
View Full Code Here

Examples of spark.api.Solutions

  }
 
  public void helpTestIteratorParanoid(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator, with lots of extra checks to hasNext();
      Assert.assertEquals(rows > 0, iter.hasNext());
      Assert.assertEquals(rows > 0, iter.hasNext());
View Full Code Here

Examples of spark.api.Solutions

  }
 
  public void helpTestIteratorCount(int rows, int batchSize) {
    DummySherpaServer server = new DummySherpaServer(rows);
    try {
      Solutions solutions = helpExecuteQuery(server, batchSize);
      Iterator<Map<String,RDFNode>> iter = solutions.iterator();
      Assert.assertNotNull(iter);
      List<Map<String,RDFNode>> data = new ArrayList<Map<String,RDFNode>>(rows);
      // Traverse the iterator without calling hasNext()
      for (int i = 0; i < rows; i++) {
        data.add(iter.next());
View Full Code Here

Examples of spark.api.Solutions

            new Object[] { iri(uri2), iri(uri1), toInt(lit2) }
        });
   
    DummySherpaServer server = new DummySherpaServer(data);
    try {
      Solutions s = helpExecuteQuery(server, 5);
     
      Assert.assertTrue(s.next());
      Map<String, RDFNode> solution = s.getResult();
      Assert.assertEquals(3, solution.size());
      Assert.assertEquals(uri1, solution.get("a"));
      Assert.assertEquals(uri2, solution.get("b"));
      Assert.assertEquals(lit1, solution.get("c"));
     
      Assert.assertTrue(s.next());
      Assert.assertEquals(uri2, s.getBinding("a"));
      Assert.assertEquals(uri2, s.getNamedNode("a"));
      Assert.assertEquals(uri1, s.getBinding("b"));
      Assert.assertEquals(uri1.getURI(), s.getURI("b"));
      Assert.assertEquals(lit2, s.getBinding("c"));     
      Assert.assertEquals(lit2, s.getLiteral("c"));     
      Assert.assertEquals(20, s.getInt("c"));
     
      Assert.assertFalse(s.next());
    } finally {
      server.shutdown();
    }
  }
View Full Code Here

Examples of spark.api.Solutions

  private static Solutions getTestData(String testName) throws Exception {
    return getTestData(null, testName);
  }
 
  public void testEmptyResults() throws Exception {
    Solutions s = getTestData("empty-results");
    assertNotNull(s);
    try {
      assertTrue(s instanceof ProtocolResult);
      assertTrue(((ProtocolResult)s).getMetadata().isEmpty());
     
      assertEquals(Arrays.asList("foo", "bar"), s.getVariables());
     
      // Check cursor methods.
      TestCursor.assertCursor(s, BEFORE_FIRST);
     
      // Assert no results.
      assertFalse(s.next());
     
      // Check cursor methods.
      TestCursor.assertCursor(s, AFTER_LAST);
    } finally {
      s.close();
    }
  }
View Full Code Here

Examples of spark.api.Solutions

    }
  }
 
  public void testSingleResult() throws Exception {
    URI u = URI.create("http://example.org/members/Member00004403730");
    Solutions s = getTestData("single-result");
    assertNotNull(s);
    try {
      assertTrue(s instanceof ProtocolResult);
      assertTrue(((ProtocolResult)s).getMetadata().isEmpty());
     
      assertEquals(Arrays.asList("x", "y", "z"), s.getVariables());
     
      // Check cursor methods.
      TestCursor.assertCursor(s, BEFORE_FIRST);
     
      // Check single row
      assertTrue(s.next());
      TestCursor.assertCursor(s, FIRST | LAST);
      assertEquals(new NamedNodeImpl(u), s.getBinding("x"));
      assertEquals(u, s.getURI("x"));
      assertEquals(new PlainLiteralImpl("John Doe"), s.getBinding("y"));
      assertFalse(s.isBound("z"));
      assertNull(s.getBinding("z"));
     
      // Check end of results.
      assertFalse(s.next());
      TestCursor.assertCursor(s, AFTER_LAST);
    } finally {
      s.close();
    }
  }
View Full Code Here

Examples of spark.api.Solutions

      s.close();
    }
  }
 
  public void testResults() throws Exception {
    Solutions s = getTestData("sparql-results");
    assertNotNull(s);
    try {
      assertTrue(s instanceof ProtocolResult);
      assertTrue(((ProtocolResult)s).getMetadata().isEmpty());
     
      String var = "a";
      assertEquals(Arrays.asList(var), s.getVariables());
     
      // Check cursor methods.
      TestCursor.assertCursor(s, BEFORE_FIRST);

      // Check results.
      assertTrue(s.next());
      TestCursor.assertCursor(s, FIRST);
      assertEquals(URI.create("http://example.org/a"), s.getURI(var));
     
      assertTrue(s.next());
      TestCursor.assertCursor(s, NONE);
      assertEquals(new BlankNodeImpl("node0"), s.getBinding(var));
     
      assertTrue(s.next());
      TestCursor.assertCursor(s, NONE);
      assertEquals(new PlainLiteralImpl("xyz"), s.getBinding(var));
     
      assertTrue(s.next());
      TestCursor.assertCursor(s, NONE);
      assertEquals(new TypedLiteralImpl("100", XsdTypes.INT), s.getBinding(var));
      assertEquals(100, s.getInt(var));
     
      assertTrue(s.next());
      TestCursor.assertCursor(s, LAST);
      assertEquals(new PlainLiteralImpl("chat", "fr"), s.getBinding(var));
     
      // Check end of results.
      assertFalse(s.next());
      TestCursor.assertCursor(s, AFTER_LAST);
    } finally {
      s.close();
    }
  }
View Full Code Here

Examples of spark.api.Solutions

      s.close();
    }
  }
 
  static void metadataTest(Command cmd, String testName, String... metadata) throws Exception {
    Solutions s = getTestData(cmd, testName);
    try {
      assertNotNull(s);
      assertTrue(s instanceof ProtocolResult);
      List<String> md = ((ProtocolResult)s).getMetadata();
      assertNotNull(md);
      assertEquals(Arrays.asList(metadata), md);
     
      String varX = "x";
      String varY = "y";
      assertEquals(Arrays.asList(varX, varY), s.getVariables());
     
      TestCursor.assertCursor(s, BEFORE_FIRST);
     
      assertTrue(s.next());
      TestCursor.assertCursor(s, FIRST | LAST);
      assertEquals(URI.create("http://example.org/foo"), s.getURI(varX));
      assertEquals("bar", s.getString(varY));
     
      assertFalse(s.next());
      TestCursor.assertCursor(s, AFTER_LAST);
    } finally {
      s.close();
    }
  }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.