Search in sources :

Example 16 with QueryExec

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");
        }
    }
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 17 with QueryExec

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));
}
Also used : Triple(org.apache.jena.graph.Triple) QueryExec(org.apache.jena.sparql.exec.QueryExec) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 18 with QueryExec

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);
    }
}
Also used : DatasetGraphFactory(org.apache.jena.sparql.core.DatasetGraphFactory) RDFLinkHTTP(org.apache.jena.rdflink.RDFLinkHTTP) BeforeClass(org.junit.BeforeClass) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) RDFLinkFactory(org.apache.jena.rdflink.RDFLinkFactory) UpdateExecHTTP(org.apache.jena.sparql.exec.http.UpdateExecHTTP) RDFLink(org.apache.jena.rdflink.RDFLink) DSP(org.apache.jena.sparql.exec.http.DSP) Graph(org.apache.jena.graph.Graph) HttpNames(org.apache.jena.riot.web.HttpNames) QueryExecHTTP(org.apache.jena.sparql.exec.http.QueryExecHTTP) HttpTest.expect401(org.apache.jena.fuseki.test.HttpTest.expect401) EnvTest(org.apache.jena.test.conn.EnvTest) Before(org.junit.Before) AfterClass(org.junit.AfterClass) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) Assert.assertNotNull(org.junit.Assert.assertNotNull) Assert.assertTrue(org.junit.Assert.assertTrue) Triple(org.apache.jena.graph.Triple) Test(org.junit.Test) GSP(org.apache.jena.sparql.exec.http.GSP) SSE(org.apache.jena.sparql.sse.SSE) ARQ(org.apache.jena.query.ARQ) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) QueryExec(org.apache.jena.sparql.exec.QueryExec) GraphFactory(org.apache.jena.sparql.graph.GraphFactory) QueryExec(org.apache.jena.sparql.exec.QueryExec) RegistryRequestModifier(org.apache.jena.http.sys.RegistryRequestModifier) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 19 with QueryExec

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);
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec)

Example 20 with QueryExec

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);
        }
    });
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) RowSetRewindable(org.apache.jena.sparql.exec.RowSetRewindable) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Test(org.junit.Test)

Aggregations

QueryExec (org.apache.jena.sparql.exec.QueryExec)21 Test (org.junit.Test)18 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)14 EnvTest (org.apache.jena.test.conn.EnvTest)12 RowSet (org.apache.jena.sparql.exec.RowSet)11 RDFLink (org.apache.jena.rdflink.RDFLink)10 HttpRequestModifier (org.apache.jena.http.sys.HttpRequestModifier)5 Binding (org.apache.jena.sparql.engine.binding.Binding)5 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)4 Graph (org.apache.jena.graph.Graph)4 Node (org.apache.jena.graph.Node)4 Triple (org.apache.jena.graph.Triple)3 RegistryRequestModifier (org.apache.jena.http.sys.RegistryRequestModifier)3 RDFLinkFactory (org.apache.jena.rdflink.RDFLinkFactory)3 SSE (org.apache.jena.sparql.sse.SSE)3 AfterClass (org.junit.AfterClass)3 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 HashMap (java.util.HashMap)2 List (java.util.List)2