Search in sources :

Example 6 with QueryExec

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

the class TestService method service_query_disabled_queryexec.

@Test(expected = QueryExecException.class)
public void service_query_disabled_queryexec() {
    String queryString = "ASK { SERVICE <" + SERVICE + "?format=json> { BIND(now() AS ?now) } }";
    Context context = Context.create().set(Service.httpServiceAllowed, false);
    try (QueryExec qExec = QueryExec.dataset(localDataset()).query(queryString).context(context).build()) {
        qExec.ask();
    }
}
Also used : Context(org.apache.jena.sparql.util.Context) QueryExec(org.apache.jena.sparql.exec.QueryExec) EnvTest(org.apache.jena.test.conn.EnvTest) Test(org.junit.Test)

Example 7 with QueryExec

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

the class TestService method service_query_silent_nosite.

@Test
public void service_query_silent_nosite() {
    logOnlyErrors(QueryIterService.class, () -> {
        DatasetGraph dsg = env.dsg();
        String queryString = "SELECT * { SERVICE SILENT <http://nosuchsite/> { VALUES ?X { 1 2 } }} ";
        try (RDFLink link = RDFLinkFactory.connect(localDataset())) {
            try (QueryExec qExec = link.query(queryString)) {
                RowSet rs = qExec.select();
                assertTrue(rs.hasNext());
                Binding binding = rs.next();
                assertFalse(rs.hasNext());
                assertTrue(binding.isEmpty());
            }
        }
    });
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) 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 8 with QueryExec

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

the class AbstractTestRDFLink method query_02.

@Test
public void query_02() {
    try (RDFLink link = link()) {
        Txn.executeRead(link, () -> {
            try (QueryExec qExec = link.query("ASK{}")) {
                boolean b = qExec.ask();
                assertTrue(b);
            }
        });
    }
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) Test(org.junit.Test)

Example 9 with QueryExec

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

the class AbstractTestRDFLink method query_03.

@Test
public void query_03() {
    try (RDFLink link = link()) {
        Txn.executeRead(link, () -> {
            try (QueryExec qExec = link.query("CONSTRUCT WHERE{}")) {
                Graph g = qExec.construct();
                assertNotNull(g);
            }
        });
    }
}
Also used : QueryExec(org.apache.jena.sparql.exec.QueryExec) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) Test(org.junit.Test)

Example 10 with QueryExec

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

the class AbstractTestRDFLink method query_build_02.

@Test
public void query_build_02() {
    try (RDFLink link = link()) {
        Txn.executeRead(link, () -> {
            Binding binding = SSE.parseBinding("(binding (?X 123))");
            QueryExec qExec = link.newQuery().query("SELECT ?X { }").substitution(binding).build();
            RowSet rs = qExec.select();
            Node x = rs.next().get(Var.alloc("X"));
            assertNotNull(x);
        });
    }
}
Also used : Binding(org.apache.jena.sparql.engine.binding.Binding) QueryExec(org.apache.jena.sparql.exec.QueryExec) Node(org.apache.jena.graph.Node) RowSet(org.apache.jena.sparql.exec.RowSet) 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