Search in sources :

Example 41 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestMultipleEmbedded method multiple_02.

// Two servers, different ports -> good.
@Test
public void multiple_02() {
    DatasetGraph dsg = dataset();
    int port1 = FusekiLib.choosePort();
    FusekiEmbeddedServer server1 = FusekiEmbeddedServer.create().setPort(port1).add("/ds1", dsg).build();
    // Different port - good
    int port2 = FusekiLib.choosePort();
    FusekiEmbeddedServer server2 = FusekiEmbeddedServer.create().setPort(port2).add("/ds2", dsg).build();
    try {
        server1.start();
        server2.start();
    } finally {
        try {
            server1.stop();
        } catch (Exception ex) {
        }
        try {
            server2.stop();
        } catch (Exception ex) {
        }
    }
}
Also used : FusekiException(org.apache.jena.fuseki.FusekiException) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 42 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestEmbeddedFuseki method embedded_01.

// Test - build on default port. 
@Test
public void embedded_01() {
    DatasetGraph dsg = dataset();
    // Default port.
    int port = 3330;
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().add("/ds", dsg).build();
    assertTrue(server.getDataAccessPointRegistry().isRegistered("/ds"));
    server.start();
    query("http://localhost:" + port + "/ds/query", "SELECT * { ?s ?p ?o}", qExec -> {
        ResultSet rs = qExec.execSelect();
        assertFalse(rs.hasNext());
    });
    server.stop();
}
Also used : ResultSet(org.apache.jena.query.ResultSet) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 43 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestEmbeddedFuseki method embedded_04.

@Test
public void embedded_04() {
    DatasetGraph dsg = dataset();
    Txn.executeWrite(dsg, () -> {
        Quad q = SSE.parseQuad("(_ :s :p _:b)");
        dsg.add(q);
    });
    // A service with just being able to do quads operations
    // That is, GET, POST, PUT on  "/data" in N-quads and TriG. 
    DataService dataService = new DataService(dsg);
    dataService.addEndpoint(OperationName.Quads_RW, "");
    dataService.addEndpoint(OperationName.Query, "");
    dataService.addEndpoint(OperationName.Update, "");
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).add("/data", dataService).build();
    server.start();
    try {
        // Put data in.
        String data = "(graph (:s :p 1) (:s :p 2) (:s :p 3))";
        Graph g = SSE.parseGraph(data);
        HttpEntity e = graphToHttpEntity(g);
        HttpOp.execHttpPut("http://localhost:" + port + "/data", e);
        // Get data out.
        try (TypedInputStream in = HttpOp.execHttpGet("http://localhost:" + port + "/data")) {
            Graph g2 = GraphFactory.createDefaultGraph();
            RDFDataMgr.read(g2, in, RDFLanguages.contentTypeToLang(in.getContentType()));
            assertTrue(g.isIsomorphicWith(g2));
        }
        // Query.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(3, x);
        });
        // Update
        UpdateRequest req = UpdateFactory.create("CLEAR DEFAULT");
        UpdateExecutionFactory.createRemote(req, "http://localhost:" + port + "/data").execute();
        // Query again.
        query("http://localhost:" + port + "/data", "SELECT * { ?s ?p ?o}", qExec -> {
            ResultSet rs = qExec.execSelect();
            int x = ResultSetFormatter.consume(rs);
            assertEquals(0, x);
        });
    } finally {
        server.stop();
    }
}
Also used : Quad(org.apache.jena.sparql.core.Quad) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) HttpEntity(org.apache.http.HttpEntity) UpdateRequest(org.apache.jena.update.UpdateRequest) ResultSet(org.apache.jena.query.ResultSet) TypedInputStream(org.apache.jena.atlas.web.TypedInputStream) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService) Test(org.junit.Test)

Example 44 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestEmbeddedFuseki method embedded_08.

@Test
public void embedded_08() {
    DatasetGraph dsg = dataset();
    int port = FusekiLib.choosePort();
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().setPort(port).parseConfigFile(DIR + "config.ttl").build();
    server.start();
    try {
        query("http://localhost:" + port + "/FuTest", "SELECT * {}", x -> {
        });
    } finally {
        server.stop();
    }
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Example 45 with DatasetGraph

use of org.apache.jena.sparql.core.DatasetGraph in project jena by apache.

the class TestEmbeddedFuseki method embedded_20.

@Test
public void embedded_20() {
    DatasetGraph dsg = dataset();
    int port = FusekiLib.choosePort();
    DataService dSrv = new DataService(dsg);
    dSrv.addEndpoint(OperationName.Query, "q");
    dSrv.addEndpoint(OperationName.GSP_R, "gsp");
    FusekiEmbeddedServer server = FusekiEmbeddedServer.create().add("/dsrv1", dSrv).setPort(port).build();
    server.start();
    try {
        query("http://localhost:" + port + "/dsrv1/q", "ASK{}", x -> {
        });
        String x1 = HttpOp.execHttpGetString("http://localhost:" + port + "/dsrv1/gsp");
        assertNotNull(x1);
    } finally {
        server.stop();
    }
}
Also used : DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) DataService(org.apache.jena.fuseki.server.DataService) Test(org.junit.Test)

Aggregations

DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)222 Test (org.junit.Test)132 BaseTest (org.apache.jena.atlas.junit.BaseTest)59 Quad (org.apache.jena.sparql.core.Quad)47 Node (org.apache.jena.graph.Node)29 Graph (org.apache.jena.graph.Graph)18 StoreConnection (org.apache.jena.tdb.StoreConnection)17 DatasetGraphTxn (org.apache.jena.tdb.transaction.DatasetGraphTxn)15 Model (org.apache.jena.rdf.model.Model)10 IOException (java.io.IOException)7 Triple (org.apache.jena.graph.Triple)7 Dataset (org.apache.jena.query.Dataset)7 StreamRDF (org.apache.jena.riot.system.StreamRDF)7 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)5 ResultSet (org.apache.jena.query.ResultSet)5 JsonLDWriteContext (org.apache.jena.riot.JsonLDWriteContext)5 Element (org.apache.jena.sparql.syntax.Element)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)4 RiotException (org.apache.jena.riot.RiotException)4 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)4