Search in sources :

Example 6 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestService method query_service_context_application_01.

@Test
public void query_service_context_application_01() {
    // This test requires no service context to be set
    @SuppressWarnings("unchecked") Map<String, Context> serviceContextMap = (Map<String, Context>) ARQ.getContext().get(Service.serviceContext);
    if (serviceContextMap != null) {
        serviceContextMap.remove(SERVICE);
    }
    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.assertNull(engine.getClient());
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Query(org.apache.jena.query.Query) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 7 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_04.

@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_04() {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with correct password BUT not in
    // correct role
    qe.setClient(withBasicAuth(ANY, "forbidden", "password"));
    qe.execAsk();
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Test(org.junit.Test)

Example 8 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_06.

@Test(expected = QueryExceptionHTTP.class)
public void query_with_auth_06() {
    // Uses auth and enables compression
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    qe.setAllowCompression(true);
    // Auth credentials for valid user with bad password
    qe.setClient(withBasicAuth(ANY, "allowed", "incorrect"));
    qe.execAsk();
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Test(org.junit.Test)

Example 9 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_03.

@Test
public void query_with_auth_03() {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with correct password
    qe.setClient(withBasicAuth(ANY, "allowed", "password"));
    Assert.assertTrue(qe.execAsk());
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) Test(org.junit.Test)

Example 10 with QueryEngineHTTP

use of org.apache.jena.sparql.engine.http.QueryEngineHTTP in project jena by apache.

the class TestAuth method query_with_auth_09.

@Test
public void query_with_auth_09() throws URISyntaxException {
    QueryEngineHTTP qe = (QueryEngineHTTP) QueryExecutionFactory.sparqlService(authServiceQuery, "ASK { }");
    // Auth credentials for valid user with correct password
    qe.setClient(withBasicAuth(new AuthScope("localhost", authPort), "allowed", "password"));
    Assert.assertTrue(qe.execAsk());
}
Also used : QueryEngineHTTP(org.apache.jena.sparql.engine.http.QueryEngineHTTP) AuthScope(org.apache.http.auth.AuthScope) Test(org.junit.Test)

Aggregations

QueryEngineHTTP (org.apache.jena.sparql.engine.http.QueryEngineHTTP)25 Test (org.junit.Test)23 HashMap (java.util.HashMap)7 Context (org.apache.jena.sparql.util.Context)7 Map (java.util.Map)5 AuthScope (org.apache.http.auth.AuthScope)5 Query (org.apache.jena.query.Query)5 HttpClient (org.apache.http.client.HttpClient)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 MediaType (org.apache.jena.atlas.web.MediaType)3 ServerTest (org.apache.jena.fuseki.ServerTest)3 ServerCtl.serviceQuery (org.apache.jena.fuseki.ServerCtl.serviceQuery)2 Triple (org.apache.jena.graph.Triple)1 Model (org.apache.jena.rdf.model.Model)1 Quad (org.apache.jena.sparql.core.Quad)1