Search in sources :

Example 91 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class SolutionModifierTest method testSetVarsOrderBy.

@ContractTest
public void testSetVarsOrderBy() {
    Var v = Var.alloc("v");
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy("?v");
    String[] s = byLine(builder);
    assertContainsRegex(ORDER_BY + var("v"), s);
    builder.setVar(v, Var.alloc("v2"));
    s = byLine(builder);
    assertContainsRegex(ORDER_BY + var("v2"), s);
}
Also used : Var(org.apache.jena.sparql.core.Var) ContractTest(org.xenei.junit.contract.ContractTest)

Example 92 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class SolutionModifierTest method testSetVarsHaving.

@ContractTest
public void testSetVarsHaving() throws ParseException {
    Var v = Var.alloc("v");
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addHaving("?v");
    String[] s = byLine(builder);
    assertContainsRegex(HAVING + var("v"), s);
    builder.setVar(v, Var.alloc("v2"));
    s = byLine(builder);
    assertContainsRegex(HAVING + var("v2"), s);
}
Also used : Var(org.apache.jena.sparql.core.Var) ContractTest(org.xenei.junit.contract.ContractTest)

Example 93 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class WhereClauseTest method testBindExprVar.

@ContractTest
public void testBindExprVar() {
    Var v = Var.alloc("foo");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addBind(new E_Random(), v);
    assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, NodeFactory.createURI("three"));
    Query q = builder.build();
    ElementGroup eg = (ElementGroup) q.getQueryPattern();
    List<Element> lst = eg.getElements();
    assertEquals("Should only be one element", 1, lst.size());
    assertTrue("Should have an ElementTriplesBlock", lst.get(0) instanceof ElementTriplesBlock);
    ElementTriplesBlock etb = (ElementTriplesBlock) lst.get(0);
    assertTrue("ElementGroup should be empty", etb.isEmpty());
}
Also used : Query(org.apache.jena.query.Query) E_Random(org.apache.jena.sparql.expr.E_Random) Var(org.apache.jena.sparql.core.Var) Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ContractTest(org.xenei.junit.contract.ContractTest)

Example 94 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class WhereClauseTest method testSetVarsInTriple.

@ContractTest
public void testSetVarsInTriple() {
    Var v = Var.alloc("v");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, NodeFactory.createURI("three"));
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, NodeFactory.createURI("four"));
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("four") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, null);
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
}
Also used : Triple(org.apache.jena.graph.Triple) Var(org.apache.jena.sparql.core.Var) ContractTest(org.xenei.junit.contract.ContractTest)

Example 95 with Var

use of org.apache.jena.sparql.core.Var in project jena by apache.

the class SelectHandlerTest method testAddVar.

@Test
public void testAddVar() {
    Var v = Var.alloc("one");
    handler.addVar(v);
    VarExprList expr = query.getProject();
    assertEquals(1, expr.size());
    assertTrue(expr.contains(v));
}
Also used : Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Aggregations

Var (org.apache.jena.sparql.core.Var)264 Node (org.apache.jena.graph.Node)83 ArrayList (java.util.ArrayList)53 Test (org.junit.Test)47 Binding (org.apache.jena.sparql.engine.binding.Binding)33 VarExprList (org.apache.jena.sparql.core.VarExprList)30 Op (org.apache.jena.sparql.algebra.Op)29 Expr (org.apache.jena.sparql.expr.Expr)28 Triple (org.apache.jena.graph.Triple)17 HashMap (java.util.HashMap)15 ContractTest (org.xenei.junit.contract.ContractTest)13 BindingMap (org.apache.jena.sparql.engine.binding.BindingMap)12 Query (org.apache.jena.query.Query)11 ExprList (org.apache.jena.sparql.expr.ExprList)11 SortCondition (org.apache.jena.query.SortCondition)10 ExprVar (org.apache.jena.sparql.expr.ExprVar)10 HashSet (java.util.HashSet)9 Pair (org.apache.jena.atlas.lib.Pair)9 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)9 QueryIterator (org.apache.jena.sparql.engine.QueryIterator)9