Search in sources :

Example 61 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class PrologHandlerTest method testAddPrefixHandler.

@Test
public void testAddPrefixHandler() {
    PrologHandler handler2 = new PrologHandler(new Query());
    handler2.addPrefix("pfx", "uri");
    handler.addAll(handler2);
    String[] lst = byLine(query.toString());
    assertContainsRegex("PREFIX\\s+pfx:\\s+\\<uri\\>", lst);
}
Also used : Query(org.apache.jena.query.Query) PrologHandler(org.apache.jena.arq.querybuilder.handlers.PrologHandler) Test(org.junit.Test)

Example 62 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class SelectHandlerTest method setup.

@Before
public void setup() {
    query = new Query();
    AggregationHandler aggHandler = new AggregationHandler(query);
    handler = new SelectHandler(aggHandler);
}
Also used : Query(org.apache.jena.query.Query) Before(org.junit.Before)

Example 63 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class SolutionModifierHandlerTest method testAddAll.

@Test
public void testAddAll() throws ParseException {
    SolutionModifierHandler solutionModifier2 = new SolutionModifierHandler(new Query());
    solutionModifier2.addOrderBy(Var.alloc("orderBy"));
    solutionModifier2.addGroupBy(Var.alloc("groupBy"));
    solutionModifier2.addHaving("?having<10");
    solutionModifier2.setLimit(500);
    solutionModifier2.setOffset(200);
    solutionModifier.addAll(solutionModifier2);
    String[] s = byLine(query.toString());
    assertContainsRegex(GROUP_BY + var("groupBy"), s);
    assertContainsRegex(HAVING + OPEN_PAREN + var("having") + OPT_SPACE + LT + OPT_SPACE + "10" + CLOSE_PAREN, s);
    assertContainsRegex(ORDER_BY + var("orderBy"), s);
    assertContainsRegex(LIMIT + "500", s);
    assertContainsRegex(OFFSET + "200", s);
}
Also used : SolutionModifierHandler(org.apache.jena.arq.querybuilder.handlers.SolutionModifierHandler) Query(org.apache.jena.query.Query) Test(org.junit.Test)

Example 64 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class SolutionModifierHandlerTest method setup.

@Before
public void setup() {
    query = new Query();
    solutionModifier = new SolutionModifierHandler(query);
}
Also used : SolutionModifierHandler(org.apache.jena.arq.querybuilder.handlers.SolutionModifierHandler) Query(org.apache.jena.query.Query) Before(org.junit.Before)

Example 65 with Query

use of org.apache.jena.query.Query in project jena by apache.

the class WhereHandlerTest method testAddOptionalWhereHandler.

@Test
public void testAddOptionalWhereHandler() throws ParseException {
    WhereHandler pattern = new WhereHandler(new Query());
    Var s = Var.alloc("s");
    Node q = NodeFactory.createURI("urn:q");
    Node v = NodeFactory.createURI("urn:v");
    Var x = Var.alloc("x");
    Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
    pattern.addWhere(new TriplePath(new Triple(s, q, n123)));
    pattern.addWhere(new TriplePath(new Triple(s, v, x)));
    pattern.addFilter("?x>56");
    handler.addOptional(pattern);
    Query expected = QueryFactory.create("SELECT * WHERE { OPTIONAL { ?s <urn:q> '123'^^<http://www.w3.org/2001/XMLSchema#int> . ?s <urn:v> ?x . FILTER(?x>56) }}");
    Assert.assertEquals(expected.getQueryPattern(), query.getQueryPattern());
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) WhereHandler(org.apache.jena.arq.querybuilder.handlers.WhereHandler) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Aggregations

Query (org.apache.jena.query.Query)106 Test (org.junit.Test)22 Op (org.apache.jena.sparql.algebra.Op)17 QueryExecution (org.apache.jena.query.QueryExecution)13 ResultSet (org.apache.jena.query.ResultSet)11 Var (org.apache.jena.sparql.core.Var)11 HashMap (java.util.HashMap)9 QuerySolution (org.apache.jena.query.QuerySolution)9 ContractTest (org.xenei.junit.contract.ContractTest)9 Node (org.apache.jena.graph.Node)8 WhereHandler (org.apache.jena.arq.querybuilder.handlers.WhereHandler)7 VarExprList (org.apache.jena.sparql.core.VarExprList)7 Element (org.apache.jena.sparql.syntax.Element)7 Triple (org.apache.jena.graph.Triple)6 Before (org.junit.Before)6 Map (java.util.Map)5 QueryEngineHTTP (org.apache.jena.sparql.engine.http.QueryEngineHTTP)5 Context (org.apache.jena.sparql.util.Context)5 StringReader (java.io.StringReader)4 NodeAlignment (mom.trd.opentheso.bdd.helper.nodes.NodeAlignment)4