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) {
}
}
}
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();
}
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();
}
}
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();
}
}
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();
}
}
Aggregations