use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestService method service_query_bad_3.
@Test(expected = QueryExceptionHTTP.class)
public void service_query_bad_3() {
DatasetGraph dsg = env.dsg();
dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
// Not a dataset of the server
String queryString = "SELECT * { SERVICE <http://nosuchsite/> { ?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");
}
}
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestAuthRemote method auth_header_1.
@Test
public void auth_header_1() {
Triple triple = SSE.parseTriple("(<x:s> <x:p> <x:o>)");
Graph graph = GraphFactory.createDefaultGraph();
graph.add(triple);
GSP.service(env.datasetURL()).httpHeader(HttpNames.hAuthorization, HttpLib.basicAuth(user, password)).defaultGraph().POST(graph);
// By query.
try (QueryExec qExec = QueryExecHTTP.newBuilder().endpoint(env.datasetURL()).queryString("ASK{ <x:s> <x:p> <x:o> }").httpHeader(HttpNames.hAuthorization, HttpLib.basicAuth(user, password)).build()) {
boolean b = qExec.ask();
assertTrue(b);
}
// By GSP
Graph graph2 = GSP.service(env.datasetURL()).httpHeader(HttpNames.hAuthorization, HttpLib.basicAuth(user, password)).defaultGraph().GET();
assertTrue(graph.isIsomorphicWith(graph2));
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class TestAuthRemote method auth_service_tuning_1_RegistryRequestModifier.
// Other ways of setting auth.
// Using HttpClient is preferred but the basic operations can use
// ServiceTuning or directly supply the headers.
// ServiceTuning
@Test
public void auth_service_tuning_1_RegistryRequestModifier() {
// using RegistryRequestModifier
HttpRequestModifier mods = (params, headers) -> headers.put(HttpNames.hAuthorization, HttpLib.basicAuth(user, password));
RegistryRequestModifier svcReg = new RegistryRequestModifier();
svcReg.add(env.datasetURL(), mods);
ARQ.getContext().put(ARQ.httpRegistryRequestModifer, svcReg);
try {
// Component level
UpdateExecHTTP.newBuilder().endpoint(env.datasetURL()).updateString("INSERT DATA { <x:s> <x:p> <x:o> }").build().execute();
try (QueryExec qExec = QueryExecHTTP.newBuilder().endpoint(env.datasetURL()).queryString("ASK{ <x:s> <x:p> <x:o> }").build()) {
boolean b = qExec.ask();
assertTrue(b);
}
} finally {
// clear up
ARQ.getContext().remove(ARQ.httpRegistryRequestModifer);
}
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class QueryExecUtils method exec.
public static void exec(Query query, DatasetGraph dsg) {
QueryExec qExec = QueryExec.dataset(dsg).query(query).build();
exec(qExec);
}
use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.
the class AbstractTestAdditional method substitute_1.
/**
* Check substitution into patterns.
*/
@Test
public void substitute_1() {
Dataset dataset = dataset();
String resultsStr = StrUtils.strjoinNL("(resultset (?s ?p ?o)", "(row (?s :s1) (?p :p) (?o :o))", ")");
RowSetRewindable expected = SSE.parseRowSet(resultsStr).rewindable();
Txn.executeWrite(dataset, () -> {
String data = StrUtils.strjoinNL("(dataset", " (:g1 :s1 :p :o)", " (:g1 :s2 :p :o)", " (:g2 :s1 :p :o)", " (:g2 :s2 :p :o)", ")");
DatasetGraph dsg = SSE.parseDatasetGraph(data);
dataset.asDatasetGraph().addAll(dsg);
String qs = PREFIXES + "SELECT * { VALUES ?s { :s1 } GRAPH <" + Quad.unionGraph + "> { ?s ?p ?o } }";
Query query = QueryFactory.create(qs);
try (QueryExec qExec = QueryExec.dataset(dsg).query(query).build()) {
RowSetRewindable rs = qExec.select().rewindable();
testRS(expected, rs);
}
});
}
Aggregations