Package spark.api

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


            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

  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

    }
  }
 
  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

      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

      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

Related Classes of spark.api.Solutions

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.