use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestAuth method query_with_auth_13.
@Test
public void query_with_auth_13() throws URISyntaxException {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password and scoped to
// base URI of the actual service URL
qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
Assert.assertTrue(qe.execAsk());
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestAuth method query_with_auth_01.
@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_01() {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// No auth credentials should result in an error
qe.execAsk();
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestAuth method query_with_auth_02.
@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_02() {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with bad password
qe.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
qe.execAsk();
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestAuth method query_with_auth_14.
@Test
public void query_with_auth_14() throws URISyntaxException {
QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
// Auth credentials for valid user with correct password and scoped to
// base URI of the actual service URL
qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
Assert.assertTrue(qe.execAsk());
}
use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.
the class TestService method query_service_context_application_02.
@SuppressWarnings("unchecked")
@Test
public void query_service_context_application_02() {
// This test requires us to set some authentication credentials for the
// service
Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
if (serviceContextMap == null) {
ARQ.getContext().put(Service.serviceContext, new HashMap<String, Context>());
serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
}
if (serviceContextMap.get(SERVICE) == null) {
serviceContextMap.put(SERVICE, new Context(ARQ.getContext()));
}
Context serviceContext = serviceContextMap.get(SERVICE);
try {
HttpClient testClient = HttpClients.custom().build();
serviceContext.put(Service.queryClient, testClient);
Query q = QueryFactory.create("ASK { }");
QueryEngineHTTP engine = QueryExecutionFactory.createServiceRequest(SERVICE, q);
Assert.assertNotNull(engine);
// Check that no settings were changed
Assert.assertEquals(-1, engine.getTimeout1());
Assert.assertEquals(-1, engine.getTimeout2());
Assert.assertTrue(engine.getAllowCompression());
Assert.assertEquals(testClient, engine.getClient());
} finally {
serviceContext.remove(Service.queryClient);
}
}
Aggregations