Search in sources :

Example 51 with ResultSet

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

the class TestResultSet method test_RS_cmp_4.

@Test
public void test_RS_cmp_4() {
    ResultSet rs1 = make("x", org.apache.jena.graph.NodeFactory.createURI("tag:local"));
    ResultSet rs2 = make("x", org.apache.jena.graph.NodeFactory.createURI("tag:local"));
    assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2));
    assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2));
}
Also used : 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 52 with ResultSet

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

the class TestResultSet method test_RS_3.

// RDF
@Test
public void test_RS_3() {
    ResultSetRewindable rs1 = new ResultSetMem();
    Model model = RDFOutput.encodeAsModel(rs1);
    rs1.reset();
    ResultSet rs2 = RDFInput.fromRDF(model);
    assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2));
}
Also used : Model(org.apache.jena.rdf.model.Model) 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 53 with ResultSet

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

the class TestResultSet method test_RS_peeking_5.

@Test
public void test_RS_peeking_5() {
    // Peeking should be able to cope with people moving on the underlying result set independently
    ResultSet inner = new ResultSetMem(make("x", NodeFactory.createURI("tag:local")), make("x", NodeFactory.createURI("tag:local")));
    ResultSetPeekable rs = ResultSetFactory.makePeekable(inner);
    assertTrue(rs.hasNext());
    assertNotNull(rs.peek());
    // Move on the inner result set independently
    inner.next();
    // Since we fiddled with the underlying result set there won't be further elements available anymore
    assertFalse(rs.hasNext());
}
Also used : 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 54 with ResultSet

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

the class TestResultSet method test_RS_1.

// Test reading, writing and comparison
@Test
public void test_RS_1() {
    ResultSetRewindable rs1 = new ResultSetMem();
    ByteArrayOutputStream arr = new ByteArrayOutputStream();
    ResultSetFormatter.outputAsXML(arr, rs1);
    rs1.reset();
    ByteArrayInputStream ins = new ByteArrayInputStream(arr.toByteArray());
    ResultSet rs2 = ResultSetFactory.fromXML(ins);
    assertTrue(ResultSetCompare.equalsByTerm(rs1, rs2));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) BuilderResultSet(org.apache.jena.sparql.sse.builders.BuilderResultSet) ResultSet(org.apache.jena.query.ResultSet) ResultSetRewindable(org.apache.jena.query.ResultSetRewindable) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BaseTest(org.apache.jena.atlas.junit.BaseTest) Test(org.junit.Test)

Example 55 with ResultSet

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

the class FusekiConfig method servicesAndDatasets.

private static List<DataAccessPoint> servicesAndDatasets(Model model) {
    // Old style configuration file : server to services.
    DatasetDescriptionRegistry dsDescMap = FusekiServer.registryForBuild();
    // ---- Services
    ResultSet rs = FusekiLib.query("SELECT * { ?s fu:services [ list:member ?service ] }", model);
    List<DataAccessPoint> accessPoints = new ArrayList<>();
    if (!rs.hasNext())
        // No "fu:services ( .... )" so try looking for services directly.
        // This means Fuseki2, service configuration files (no server section) work for --conf. 
        rs = FusekiLib.query("SELECT ?service { ?service a fu:Service }", model);
    for (; rs.hasNext(); ) {
        QuerySolution soln = rs.next();
        Resource svc = soln.getResource("service");
        DataAccessPoint acc = FusekiBuilder.buildDataAccessPoint(svc, dsDescMap);
        accessPoints.add(acc);
    }
    return accessPoints;
}
Also used : QuerySolution(org.apache.jena.query.QuerySolution) ResultSet(org.apache.jena.query.ResultSet) ArrayList(java.util.ArrayList)

Aggregations

ResultSet (org.apache.jena.query.ResultSet)75 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)14 ByteArrayInputStream (java.io.ByteArrayInputStream)13 QuerySolution (org.apache.jena.query.QuerySolution)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 Query (org.apache.jena.query.Query)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 Binding (org.apache.jena.sparql.engine.binding.Binding)4 AbstractRegexpBasedTest (org.apache.jena.arq.AbstractRegexpBasedTest)3