use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestAuthRemote method exec_register_test.
private void exec_register_test() {
try (QueryExec qExec = QueryExecHTTP.newBuilder().endpoint(env.datasetURL()).queryString("ASK{ }").build()) {
boolean b = qExec.ask();
assertTrue(b);
}
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestRDFLinkFusekiBinary method rdflink_fuseki_1.
@Test
public void rdflink_fuseki_1() {
// Tests all run, in order, on one connection.
Triple triple = SSE.parseTriple("(:s :p <_:b3456>)");
Graph graph = GraphFactory.createDefaultGraph();
graph.add(triple);
FusekiServer server = createFusekiServer().build().start();
int port = server.getPort();
try {
String dsURL = "http://localhost:" + port + "/ds";
assertTrue(HttpLib.isFuseki(dsURL));
RDFLinkHTTPBuilder builder = RDFLinkFuseki.newBuilder().destination(dsURL);
try (RDFLinkFuseki link = (RDFLinkFuseki) builder.build()) {
// assertTrue(isFuseki(link));
// GSP
link.put(graph);
checkGraph(link, "b3456");
// Query forms.
link.querySelect("SELECT * {?s ?p ?o}", x -> {
Node obj = x.get(Var.alloc("o"));
assertTrue(obj.isBlank());
assertEquals("b3456", obj.getBlankNodeLabel());
});
try (QueryExec qExec = link.query("ASK {?s ?p <_:b3456>}")) {
boolean bool = qExec.ask();
assertTrue(bool);
}
try (QueryExec qExec = link.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (sameTerm(?o, <_:b3456>)) }")) {
Graph graph2 = qExec.construct();
checkGraph(graph2, "b3456");
}
try (QueryExec qExec = link.query("DESCRIBE ?s WHERE { ?s ?p <_:b3456>}")) {
Graph graph2 = qExec.describe();
checkGraph(graph2, "b3456");
}
// Update
link.update("CLEAR DEFAULT");
link.update("INSERT DATA { <x:s> <x:p> <_:b789> }");
checkGraph(link, "b789");
link.update("CLEAR DEFAULT");
link.update("INSERT DATA { <x:s> <x:p> <_:6789> }");
checkGraph(link, "6789");
}
} finally {
server.stop();
}
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestService method service_query_modified_registry.
@Test
public void service_query_modified_registry() {
DatasetGraph dsg = env.dsg();
dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
String queryString = "SELECT * { SERVICE <" + SERVICE + "> { ?s ?p ?o }} ";
RDFLink link = RDFLinkFactory.connect(localDataset());
// RequestModifer that sets a flag to show it has been run.
AtomicInteger COUNTER = new AtomicInteger(0);
HttpRequestModifier testModifier = (Params params, Map<String, String> httpHeaders) -> {
COUNTER.incrementAndGet();
};
runWithModifier(SERVICE, testModifier, () -> {
// Connect to local, unused, permanently empty dataset
try (QueryExec qExec = QueryExec.dataset(localDataset()).query(queryString).build()) {
RowSet rs = qExec.select();
long x = Iter.count(rs);
assertEquals(1, x);
}
});
assertEquals("Modifier did not run", 1, COUNTER.get());
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestService method service_query_modified_cxt.
@Test
public void service_query_modified_cxt() {
DatasetGraph dsg = env.dsg();
String queryString = "SELECT * { SERVICE <" + SERVICE + "> { BIND (123 AS ?X) } }";
// RequestModifer that sets a flag to show it has been run.
AtomicInteger COUNTER = new AtomicInteger(0);
HttpRequestModifier testModifier = (Params params, Map<String, String> httpHeaders) -> {
COUNTER.incrementAndGet();
};
DatasetGraph localdsg = localDataset();
localdsg.getContext().put(ARQ.httpRequestModifer, testModifier);
try (RDFLink link = RDFLinkFactory.connect(localdsg)) {
try (QueryExec qExec = link.query(queryString)) {
RowSet rs = qExec.select();
long x = Iter.count(rs);
assertEquals(1, x);
}
}
assertEquals("Modifier did not run", 1, COUNTER.get());
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestService method service_query_bad_no_dataset.
@Test(expected = QueryExceptionHTTP.class)
public void service_query_bad_no_dataset() {
DatasetGraph dsg = env.dsg();
dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
// Not a dataset of the server
String queryString = "SELECT * { SERVICE <" + env.serverPath("JUNK") + "> { ?s ?p ?o }} ";
// Connect to local, unused, permanently empty dataset
try (RDFLink link = RDFLinkFactory.connect(localDataset())) {
try (QueryExec qExec = link.query(queryString)) {
// Where it should go wrong.
RowSet rs = qExec.select();
// Should go on execution.
rs.hasNext();
fail("Should not get here");
}
}
}
Aggregations