Search in sources :

Example 1 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class TestAuthRemote method exec_register_test.

private void exec_register_test() {
    try (QueryExec qExec = QueryExecHTTP.newBuilder().endpoint(env.datasetURL()).queryString("ASK{  }").build()) {
        boolean b = qExec.ask();
        assertTrue(b);
    }
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec)

Example 2 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class TestRDFLinkFusekiBinary method rdflink_fuseki_1.

@Test
public void rdflink_fuseki_1() {
    // Tests all run, in order, on one connection.
    Triple triple = SSE.parseTriple("(:s :p <_:b3456>)");
    Graph graph = GraphFactory.createDefaultGraph();
    graph.add(triple);
    FusekiServer server = createFusekiServer().build().start();
    int port = server.getPort();
    try {
        String dsURL = "http://localhost:" + port + "/ds";
        assertTrue(HttpLib.isFuseki(dsURL));
        RDFLinkHTTPBuilder builder = RDFLinkFuseki.newBuilder().destination(dsURL);
        try (RDFLinkFuseki link = (RDFLinkFuseki) builder.build()) {
            // assertTrue(isFuseki(link));
            // GSP
            link.put(graph);
            checkGraph(link, "b3456");
            // Query forms.
            link.querySelect("SELECT * {?s ?p ?o}", x -> {
                Node obj = x.get(Var.alloc("o"));
                assertTrue(obj.isBlank());
                assertEquals("b3456", obj.getBlankNodeLabel());
            });
            try (QueryExec qExec = link.query("ASK {?s ?p <_:b3456>}")) {
                boolean bool = qExec.ask();
                assertTrue(bool);
            }
            try (QueryExec qExec = link.query("CONSTRUCT { ?s ?p ?o } WHERE { ?s ?p ?o . FILTER (sameTerm(?o, <_:b3456>)) }")) {
                Graph graph2 = qExec.construct();
                checkGraph(graph2, "b3456");
            }
            try (QueryExec qExec = link.query("DESCRIBE ?s WHERE { ?s ?p <_:b3456>}")) {
                Graph graph2 = qExec.describe();
                checkGraph(graph2, "b3456");
            }
            // Update
            link.update("CLEAR DEFAULT");
            link.update("INSERT DATA { <x:s> <x:p> <_:b789> }");
            checkGraph(link, "b789");
            link.update("CLEAR DEFAULT");
            link.update("INSERT DATA { <x:s> <x:p> <_:6789> }");
            checkGraph(link, "6789");
        }
    } finally {
        server.stop();
    }
}
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) Node(org.apache.jena.graph.Node) RDFLinkFuseki(org.apache.jena.rdflink.RDFLinkFuseki) FusekiServer(org.apache.jena.fuseki.main.FusekiServer) RDFLinkHTTPBuilder(org.apache.jena.rdflink.RDFLinkHTTPBuilder) Test(org.junit.Test)

Example 3 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec 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());
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 4 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec 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());
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) RowSet(org.apache.jena.sparql.exec.RowSet) RDFLink(org.apache.jena.rdflink.RDFLink) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 5 with QueryExec

use of org.apache.jena.sparql.exec.QueryExec in project jena by apache.

the class TestService method service_query_bad_no_dataset.

@Test(expected = QueryExceptionHTTP.class)
public void service_query_bad_no_dataset() {
    DatasetGraph dsg = env.dsg();
    dsg.executeWrite(() -> dsg.add(SSE.parseQuad("(_ :s :p :o)")));
    // Not a dataset of the server
    String queryString = "SELECT * { SERVICE <" + env.serverPath("JUNK") + "> { ?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)

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