Search in sources :

Example 1 with RDFLinkHTTPBuilder

use of org.apache.jena.rdflink.RDFLinkHTTPBuilder in project jena by apache.

the class TestRDFLinkFusekiBinary method rdflink_fuseki_1.

@Test
public void rdflink_fuseki_1() {
    // Tests all run, in order, on one connection.
    Triple triple = SSE.parseTriple("(:s :p <_:b3456>)");
    Graph graph = GraphFactory.createDefaultGraph();
    graph.add(triple);
    FusekiServer server = createFusekiServer().build().start();
    int port = server.getPort();
    try {
        String dsURL = "http://localhost:" + port + "/ds";
        assertTrue(HttpLib.isFuseki(dsURL));
        RDFLinkHTTPBuilder builder = RDFLinkFuseki.newBuilder().destination(dsURL);
        try (RDFLinkFuseki link = (RDFLinkFuseki) builder.build()) {
            // assertTrue(isFuseki(link));
            // GSP
            link.put(graph);
            checkGraph(link, "b3456");
            // Query forms.
            link.querySelect("SELECT * {?s ?p ?o}", x -> {
                Node obj = x.get(Var.alloc("o"));
                assertTrue(obj.isBlank());
                assertEquals("b3456", obj.getBlankNodeLabel());
            });
            try (QueryExec qExec = link.query("ASK {?s ?p <_:b3456>}")) {
                boolean bool = qExec.ask();
                assertTrue(bool);
            }
            try (QueryExec qExec = link.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (sameTerm(?o, <_:b3456>)) }")) {
                Graph graph2 = qExec.construct();
                checkGraph(graph2, "b3456");
            }
            try (QueryExec qExec = link.query("DESCRIBE ?s WHERE { ?s ?p <_:b3456>}")) {
                Graph graph2 = qExec.describe();
                checkGraph(graph2, "b3456");
            }
            // Update
            link.update("CLEAR DEFAULT");
            link.update("INSERT DATA { <x:s> <x:p> <_:b789> }");
            checkGraph(link, "b789");
            link.update("CLEAR DEFAULT");
            link.update("INSERT DATA { <x:s> <x:p> <_:6789> }");
            checkGraph(link, "6789");
        }
    } finally {
        server.stop();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) QueryExec(org.apache.jena.sparql.exec.QueryExec) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Node(org.apache.jena.graph.Node) RDFLinkFuseki(org.apache.jena.rdflink.RDFLinkFuseki) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) RDFLinkHTTPBuilder(org.apache.jena.rdflink.RDFLinkHTTPBuilder) Test(org.junit.Test)

Aggregations

FusekiServer (org.apache.jena.fuseki.main.FusekiServer)1 Graph (org.apache.jena.graph.Graph)1 Node (org.apache.jena.graph.Node)1 Triple (org.apache.jena.graph.Triple)1 RDFLinkFuseki (org.apache.jena.rdflink.RDFLinkFuseki)1 RDFLinkHTTPBuilder (org.apache.jena.rdflink.RDFLinkHTTPBuilder)1 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)1 QueryExec (org.apache.jena.sparql.exec.QueryExec)1 Test (org.junit.Test)1