use of org.apache.jena.graph.Graph in project jena by apache.
the class TestAssemblerGroup method assertMemoryModel.
protected void assertMemoryModel(Object object) {
if (object instanceof Model) {
Graph g = ((Model) object).getGraph();
assertInstanceOf(GraphMemBase.class, g);
} else
fail("expected a Model, but got a " + object.getClass());
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class AbstractTripleBlankNodeTests method writeTuples.
@Override
protected void writeTuples(File f, List<Triple> tuples) throws FileNotFoundException {
Graph g = GraphFactory.createGraphMem();
for (Triple t : tuples) {
g.add(t);
}
RDFDataMgr.write(new FileOutputStream(f), g, getLanguage());
}
use of org.apache.jena.graph.Graph 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.graph.Graph in project jena by apache.
the class DatasetGraphAccessorBasic method httpDelete.
@Override
public void httpDelete(Node graphName) {
Graph ng = dataset.getGraph(graphName);
if (ng == null)
return;
dataset.removeGraph(graphName);
// clearGraph(ng) ;
}
use of org.apache.jena.graph.Graph in project jena by apache.
the class DatasetGraphAccessorBasic method httpPost.
@Override
public void httpPost(Node graphName, Graph data) {
Graph ng = dataset.getGraph(graphName);
if (ng == null) {
dataset.addGraph(graphName, data);
return;
}
mergeGraph(ng, data);
}
Aggregations