use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class AbstractJenaConnectionTests method connection_pre_processors_08.
/**
* Tests pre-processor management operations
*
* @throws SQLException
*/
@Test
public void connection_pre_processors_08() throws SQLException {
JenaConnection conn = this.getConnection();
Assert.assertFalse(conn.getPreProcessors().hasNext());
// Add a pre-processor
Echo echo = new Echo();
conn.addPreProcessor(echo);
Assert.assertTrue(conn.getPreProcessors().hasNext());
// Apply the pre-processor
UpdateRequest input = UpdateFactory.create("DELETE WHERE { ?s ?p ?o }");
UpdateRequest output = conn.applyPreProcessors(input);
Assert.assertEquals(input, output);
conn.close();
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class TestSyntaxTransform method testUpdate.
private void testUpdate(String input, String output, String varStr, String valStr) {
UpdateRequest req1 = UpdateFactory.create(PREFIX + input);
UpdateRequest reqExpected = UpdateFactory.create(PREFIX + output);
Map<Var, Node> map = new HashMap<>();
map.put(Var.alloc(varStr), SSE.parseNode(valStr));
UpdateRequest reqTrans = UpdateTransformOps.transform(req1, map);
// Crude.
String x1 = reqExpected.toString().replaceAll("[ \n\t]", "");
String x2 = reqTrans.toString().replaceAll("[ \n\t]", "");
//assertEquals(reqExpected, reqTrans) ;
assertEquals(x1, x2);
}
use of org.apache.jena.update.UpdateRequest 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.update.UpdateRequest in project jena by apache.
the class TestSPARQLProtocol method update_02.
@Test
public void update_02() {
UpdateRequest update = UpdateFactory.create("INSERT DATA {}");
UpdateProcessor proc = UpdateExecutionFactory.createRemoteForm(update, serviceUpdate());
proc.execute();
}
use of org.apache.jena.update.UpdateRequest in project jena by apache.
the class TestSPARQLProtocol method update_01.
@Test
public void update_01() {
UpdateRequest update = UpdateFactory.create("INSERT DATA {}");
UpdateProcessor proc = UpdateExecutionFactory.createRemote(update, serviceUpdate());
proc.execute();
}
Aggregations