Search in sources :

Example 1 with RDFConnectionRemoteBuilder

use of org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder in project jena by apache.

the class TestConfigFile method stdServicesOldStyle.

// Named services mirrored onto the dataset
@Test
public void stdServicesOldStyle() {
    FusekiServer server = server(0, "std-old-style.ttl");
    server.start();
    int port = server.getPort();
    String serverURL = "http://localhost:" + port + "/ds0";
    try {
        RDFConnectionRemoteBuilder builderUnamedServices = RDFConnectionRemote.newBuilder().destination(serverURL).updateEndpoint("").queryEndpoint("");
        RDFConnectionRemoteBuilder builderNamedServices = RDFConnectionRemote.newBuilder().destination(serverURL).queryEndpoint("sparql").updateEndpoint("update").gspEndpoint("data");
        try (RDFConnection conn = builderNamedServices.build()) {
            conn.update("INSERT DATA { <x:s> <x:p> 123 }");
            Graph g = conn.fetch().getGraph();
            assertEquals(1, g.size());
        }
        try (RDFConnection conn = builderNamedServices.build()) {
            conn.queryAsk("ASK{}");
            Graph g = conn.fetch().getGraph();
            assertEquals(1, g.size());
        }
        try (RDFConnection conn = builderUnamedServices.build()) {
            conn.update("INSERT DATA { <x:s> <x:p> 456 }");
            conn.queryAsk("ASK{}");
            Graph g = conn.fetch().getGraph();
            assertEquals(2, g.size());
        }
    } finally {
        server.stop();
    }
}
Also used : Graph(org.apache.jena.graph.Graph) RDFConnection(org.apache.jena.rdfconnection.RDFConnection) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder) Test(org.junit.Test)

Example 2 with RDFConnectionRemoteBuilder

use of org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder in project jena by apache.

the class TestConfigFile method stdServicesNoConfig.

@Test
public void stdServicesNoConfig() {
    FusekiServer server = server(0, "std-empty.ttl");
    server.start();
    int port = server.getPort();
    String serverURL = "http://localhost:" + port + "/ds-no-ep";
    try {
        try (RDFConnection conn = RDFConnection.connect(serverURL)) {
            // 400 if on the dataset
            expect400(() -> conn.queryAsk("ASK{}"));
        }
        RDFConnectionRemoteBuilder builder = RDFConnectionRemote.newBuilder().destination(serverURL).queryEndpoint("sparql").updateEndpoint("update").gspEndpoint("data");
        try (RDFConnection conn = builder.build()) {
            // 404 if on an absent named service
            expect404(() -> conn.queryAsk("ASK{}"));
        }
    } finally {
        server.stop();
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder) Test(org.junit.Test)

Example 3 with RDFConnectionRemoteBuilder

use of org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder in project jena by apache.

the class TestRDFConnectionFusekiBinary method rdfconnection_fuseki_1.

@Test
public void rdfconnection_fuseki_1() {
    // Tests all run, in order, on one connection.
    Triple triple = SSE.parseTriple("(:s :p <_:b3456>)");
    // Goes in as URI! (pre this PR)
    Model model = ModelFactory.createDefaultModel();
    model.getGraph().add(triple);
    int PORT = WebLib.choosePort();
    FusekiServer server = createFusekiServer(PORT).build().start();
    try {
        String dsURL = "http://localhost:" + PORT + "/ds";
        assertTrue(HttpLib.isFuseki(dsURL));
        RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create().destination(dsURL);
        try (RDFConnectionFuseki conn = (RDFConnectionFuseki) builder.build()) {
            assertTrue(HttpLib.isFuseki(dsURL));
            // GSP
            conn.put(model);
            checkModel(conn, "b3456");
            // Query forms.
            conn.querySelect("SELECT * {?s ?p ?o}", x -> {
                Node obj = x.get("o").asNode();
                assertTrue(obj.isBlank());
                assertEquals("b3456", obj.getBlankNodeLabel());
            });
            try (QueryExecution qExec = conn.query("ASK {?s ?p <_:b3456>}")) {
                boolean bool = qExec.execAsk();
                assertTrue(bool);
            }
            try (QueryExecution qExec = conn.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (sameTerm(?o, <_:b3456>)) }")) {
                Model model2 = qExec.execConstruct();
                checkModel(model2, "b3456");
            }
            try (QueryExecution qExec = conn.query("DESCRIBE ?s WHERE { ?s ?p <_:b3456>}")) {
                Model model2 = qExec.execConstruct();
                checkModel(model2, "b3456");
            }
            // Update
            conn.update("CLEAR DEFAULT");
            conn.update("INSERT DATA { <x:s> <x:p> <_:b789> }");
            checkModel(conn, "b789");
            conn.update("CLEAR DEFAULT");
            conn.update("INSERT DATA { <x:s> <x:p> <_:6789> }");
            checkModel(conn, "6789");
        }
    } finally {
        server.stop();
    }
}
Also used : Triple(org.apache.jena.graph.Triple) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) RDFConnectionFuseki(org.apache.jena.rdfconnection.RDFConnectionFuseki) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) QueryExecution(org.apache.jena.query.QueryExecution) Test(org.junit.Test)

Example 4 with RDFConnectionRemoteBuilder

use of org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder in project jena by apache.

the class TestConfigFile method unionGraph.

private void unionGraph(String fnConfig, String dbName) {
    FusekiServer server = server(0, fnConfig);
    server.start();
    int port = server.getPort();
    String serverURL = "http://localhost:" + port + dbName;
    try {
        try (RDFConnection conn = RDFConnection.connect(serverURL)) {
            conn.update("INSERT DATA {" + NL + "<x:s> <x:p> 'dft'" + NL + "GRAPH <x:g1> { <x:s> <x:p> 'g1' }" + NL + "GRAPH <x:g2> { <x:s> <x:p> 'g2' }" + NL + " }");
            int x = countDftGraph(conn);
            assertEquals(1, x);
        }
        // Query union endpoint.
        RDFConnectionRemoteBuilder builder = RDFConnectionRemote.newBuilder().destination(serverURL).queryEndpoint("sparql-union");
        try (RDFConnection conn = builder.build()) {
            int x = countDftGraph(conn);
            assertEquals(2, x);
        }
    } finally {
        server.stop();
    }
}
Also used : RDFConnection(org.apache.jena.rdfconnection.RDFConnection) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder)

Example 5 with RDFConnectionRemoteBuilder

use of org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder in project jena by apache.

the class RDFConnectionExample6 method main.

public static void main(String... args) {
    RDFConnectionRemoteBuilder builder = RDFConnectionFuseki.create().destination("http://sparql.org/sparql");
    Query query = QueryFactory.create("SELECT * { BIND('Hello'as ?text) }");
    // In this variation, a connection is built each time.
    try (RDFConnectionFuseki conn = (RDFConnectionFuseki) builder.build()) {
        conn.queryResultSet(query, ResultSetFormatter::out);
    }
}
Also used : ResultSetFormatter(org.apache.jena.query.ResultSetFormatter) Query(org.apache.jena.query.Query) RDFConnectionRemoteBuilder(org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder) RDFConnectionFuseki(org.apache.jena.rdfconnection.RDFConnectionFuseki)

Aggregations

RDFConnectionRemoteBuilder (org.apache.jena.rdfconnection.RDFConnectionRemoteBuilder)6 RDFConnection (org.apache.jena.rdfconnection.RDFConnection)4 Test (org.junit.Test)3 Query (org.apache.jena.query.Query)2 ResultSetFormatter (org.apache.jena.query.ResultSetFormatter)2 RDFConnectionFuseki (org.apache.jena.rdfconnection.RDFConnectionFuseki)2 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 QueryExecution (org.apache.jena.query.QueryExecution)1 Model (org.apache.jena.rdf.model.Model)1