Search in sources :

Example 1 with RDFLink

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);
    }
}
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) RDFLink(org.apache.jena.rdflink.RDFLink) HttpRequestModifier(org.apache.jena.http.sys.HttpRequestModifier) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 2 with RDFLink

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());
}
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 3 with RDFLink

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);
        });
    }
}
Also used : 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 4 with RDFLink

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);
    }
}
Also used : 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 5 with RDFLink

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());
}
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)

Aggregations

RDFLink (org.apache.jena.rdflink.RDFLink)14 Test (org.junit.Test)13 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)12 EnvTest (org.apache.jena.test.conn.EnvTest)12 QueryExec (org.apache.jena.sparql.exec.QueryExec)8 RowSet (org.apache.jena.sparql.exec.RowSet)7 HttpRequestModifier (org.apache.jena.http.sys.HttpRequestModifier)4 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 Graph (org.apache.jena.graph.Graph)2 RegistryRequestModifier (org.apache.jena.http.sys.RegistryRequestModifier)2 RDFLinkHTTP (org.apache.jena.rdflink.RDFLinkHTTP)2 DatasetGraphFactory (org.apache.jena.sparql.core.DatasetGraphFactory)2 Binding (org.apache.jena.sparql.engine.binding.Binding)2 GSP (org.apache.jena.sparql.exec.http.GSP)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 FusekiServer (org.apache.jena.fuseki.main.FusekiServer)1 FusekiLogging (org.apache.jena.fuseki.system.FusekiLogging)1 HttpTest.expect401 (org.apache.jena.fuseki.test.HttpTest.expect401)1 Triple (org.apache.jena.graph.Triple)1 ARQ (org.apache.jena.query.ARQ)1