Search in sources :

Example 21 with ResultSet

use of org.apache.jena.query.ResultSet in project jena by apache.

the class TestResultSet method test_RS_peeking_9.

@Test
public void test_RS_peeking_9() {
    // Check that peeking causes the correct row to be returned when we actually access the rows
    Node first = NodeFactory.createURI("tag:first");
    Node second = NodeFactory.createURI("tag:second");
    Var x = Var.alloc("x");
    ResultSet inner = new ResultSetMem(make("x", first), make("x", second));
    ResultSetPeekable rs = ResultSetFactory.makePeekable(inner);
    assertTrue(rs.hasNext());
    // Peek and check row is as expected
    Binding peeked = rs.peekBinding();
    assertNotNull(peeked);
    assertTrue(first.equals(peeked.get(x)));
    // Check first row is as expected
    Binding next = rs.nextBinding();
    assertNotNull(next);
    assertTrue(first.equals(next.get(x)));
    // Repeat for second row
    peeked = rs.peekBinding();
    assertNotNull(peeked);
    assertTrue(second.equals(peeked.get(x)));
    next = rs.nextBinding();
    assertNotNull(next);
    assertTrue(second.equals(next.get(x)));
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 22 with ResultSet

use of org.apache.jena.query.ResultSet in project jena by apache.

the class TestResultSet method test_RS_2_str.

@Test
public void test_RS_2_str() {
    ResultSetRewindable rs1 = makeRewindable("x", org.apache.jena.graph.NodeFactory.createURI("tag:local"));
    String x = ResultSetFormatter.asXMLString(rs1);
    rs1.reset();
    ResultSet rs2 = ResultSetFactory.fromXML(x);
    assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2));
}
Also used : BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 23 with ResultSet

use of org.apache.jena.query.ResultSet in project jena by apache.

the class TestResultSet method makeRewindable.

private ResultSetRewindable makeRewindable(String var, Node val) {
    ResultSet rs = make(var, val);
    ResultSetRewindable rsw = ResultSetFactory.makeRewindable(rs);
    return rsw;
}
Also used : BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable)

Example 24 with ResultSet

use of org.apache.jena.query.ResultSet in project jena by apache.

the class TestResultSet method makePeekable.

private ResultSetPeekable makePeekable(String var, Node val) {
    ResultSet rs = make(var, val);
    ResultSetPeekable rsp = ResultSetFactory.makePeekable(rs);
    return rsp;
}
Also used : BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet)

Example 25 with ResultSet

use of org.apache.jena.query.ResultSet in project jena by apache.

the class TestResultSetFormat1 method resultset_03.

@Test
public void resultset_03() {
    ResultSet rs = make($rs);
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ResultSetFormatter.outputAsJSON(out, rs);
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    ResultSet rs2 = ResultSetFactory.fromJSON(in);
    areIsomorphic(rs, rs2);
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Aggregations

ResultSet (org.apache.jena.query.ResultSet)79 Test (org.junit.Test)43 BuilderResultSet (org.apache.jena.sparql.sse.builders.BuilderResultSet)33 BaseTest (org.apache.jena.atlas.junit.BaseTest)27 QueryExecution (org.apache.jena.query.QueryExecution)18 QuerySolution (org.apache.jena.query.QuerySolution)15 ByteArrayInputStream (java.io.ByteArrayInputStream)13 Query (org.apache.jena.query.Query)11 ResultSetRewindable (org.apache.jena.query.ResultSetRewindable)11 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)8 ResultSetStream (org.apache.jena.sparql.engine.ResultSetStream)8 ArrayList (java.util.ArrayList)7 Node (org.apache.jena.graph.Node)7 Model (org.apache.jena.rdf.model.Model)6 ConfigTest (org.apache.jena.tdb.ConfigTest)6 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)5 Var (org.apache.jena.sparql.core.Var)5 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)4 Binding (org.apache.jena.sparql.engine.binding.Binding)4