use of org.apache.jena.rdflink.RDFLink in project jena by apache.
the class TestAuthRemote method auth_service_tuning_2_HttpRequestModifer.
@Test
public void auth_service_tuning_2_HttpRequestModifer() {
// As HttpRequestModifer
HttpRequestModifier mods = (params, headers) -> headers.put(HttpNames.hAuthorization, HttpLib.basicAuth(user, password));
ARQ.getContext().put(ARQ.httpRequestModifer, mods);
try {
try (RDFLink link = RDFLinkHTTP.newBuilder().destination(env.datasetURL()).build()) {
link.update("INSERT DATA { <x:s> <x:p> <x:z> }");
boolean b = link.queryAsk("ASK{ <x:s> <x:p> <x:z> }");
assertTrue(b);
}
} finally {
// clear up
ARQ.getContext().remove(ARQ.httpRequestModifer);
}
}
use of org.apache.jena.rdflink.RDFLink 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.rdflink.RDFLink in project jena by apache.
the class TestService method service_query_RDFLink.
@Test
public void service_query_RDFLink() {
DatasetGraph dsg = env.dsg();
dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
String queryString = "SELECT * { SERVICE <" + SERVICE + "> { ?s ?p ?o }} ";
// Connect to local, unused, permanently empty dataset
try (RDFLink link = RDFLinkFactory.connect(localDataset())) {
link.queryRowSet(queryString, rs -> {
long x = Iter.count(rs);
assertEquals(1, x);
});
}
}
use of org.apache.jena.rdflink.RDFLink in project jena by apache.
the class TestService method service_query_disabled_local_dataset.
// Same except set the QExec context.
@Test(expected = QueryExecException.class)
public void service_query_disabled_local_dataset() {
String queryString = "ASK { SERVICE <" + SERVICE + "?format=json> { BIND(now() AS ?now) } }";
DatasetGraph localdsg = localDataset();
localdsg.getContext().set(Service.httpServiceAllowed, false);
try (RDFLink link = RDFLinkFactory.connect(localdsg)) {
boolean b = link.queryAsk(queryString);
}
}
use of org.apache.jena.rdflink.RDFLink 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());
}
Aggregations