Search in sources :

Example 21 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class WhereClauseTest method testAddFilter.

@ContractTest
public void testAddFilter() throws ParseException {
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addFilter("?one<10");
    E_LessThan lt = new E_LessThan(new ExprVar(Var.alloc("one")), new NodeValueInteger(10));
    ElementFilter ef = new ElementFilter(lt);
    WhereValidator visitor = new WhereValidator(ef);
    builder.build().getQueryPattern().visit(visitor);
    assertTrue(visitor.matching);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) WhereValidator(org.apache.jena.arq.querybuilder.WhereValidator) ElementFilter(org.apache.jena.sparql.syntax.ElementFilter) NodeValueInteger(org.apache.jena.sparql.expr.nodevalue.NodeValueInteger) E_LessThan(org.apache.jena.sparql.expr.E_LessThan) ContractTest(org.xenei.junit.contract.ContractTest)

Example 22 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class SolutionModifierTest method testAddOrderByString.

@ContractTest
public void testAddOrderByString() {
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy("foo");
    List<SortCondition> lst = builder.build().getOrderBy();
    Assert.assertEquals(1, lst.size());
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("foo")), Query.ORDER_DEFAULT), lst.get(0));
    builder = solutionModifier.addOrderBy("bar");
    lst = builder.build().getOrderBy();
    Assert.assertEquals(2, lst.size());
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("foo")), Query.ORDER_DEFAULT), lst.get(0));
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("bar")), Query.ORDER_DEFAULT), lst.get(1));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) SortCondition(org.apache.jena.query.SortCondition) ContractTest(org.xenei.junit.contract.ContractTest)

Example 23 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class SolutionModifierTest method testAddOrderByExprDescending.

@ContractTest
public void testAddOrderByExprDescending() {
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    Expr e = new E_Random();
    AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy(e, Order.DESCENDING);
    Query query = builder.build();
    assertTrue(query.hasOrderBy());
    List<SortCondition> orderBy = query.getOrderBy();
    assertEquals(1, orderBy.size());
    assertEquals(Query.ORDER_DESCENDING, orderBy.get(0).getDirection());
    assertEquals(e, orderBy.get(0).getExpression());
    builder = solutionModifier.addOrderBy("bar");
    query = builder.build();
    assertTrue(query.hasOrderBy());
    orderBy = query.getOrderBy();
    assertEquals(2, orderBy.size());
    assertEquals(Query.ORDER_DESCENDING, orderBy.get(0).getDirection());
    assertEquals(e, orderBy.get(0).getExpression());
    assertEquals(Query.ORDER_DEFAULT, orderBy.get(1).getDirection());
    assertEquals(new ExprVar("bar"), orderBy.get(1).getExpression());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) SortCondition(org.apache.jena.query.SortCondition) Expr(org.apache.jena.sparql.expr.Expr) Query(org.apache.jena.query.Query) E_Random(org.apache.jena.sparql.expr.E_Random) ContractTest(org.xenei.junit.contract.ContractTest)

Example 24 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class SolutionModifierTest method testSetVarsHaving_Node_Variable.

@ContractTest
public void testSetVarsHaving_Node_Variable() throws ParseException {
    Node v = NodeFactory.createVariable("v");
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addHaving(v);
    List<Expr> exprs = builder.build().getHavingExprs();
    Assert.assertEquals(1, exprs.size());
    Assert.assertEquals(new ExprVar(Var.alloc(v)), exprs.get(0));
    builder.setVar(v, Var.alloc("v2"));
    exprs = builder.build().getHavingExprs();
    Assert.assertEquals(1, exprs.size());
    Assert.assertEquals(new ExprVar(Var.alloc("v2")), exprs.get(0));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) Node(org.apache.jena.graph.Node) ContractTest(org.xenei.junit.contract.ContractTest)

Example 25 with ExprVar

use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.

the class ExprFactoryTest method boundTest_ExprVar.

public void boundTest_ExprVar() {
    ExprVar ev = new ExprVar("hello");
    Expr e = factory.bound(ev);
    assertTrue(e instanceof E_Bound);
    assertEquals("?hello", e.getVarName());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) E_Bound(org.apache.jena.sparql.expr.E_Bound)

Aggregations

ExprVar (org.apache.jena.sparql.expr.ExprVar)51 Expr (org.apache.jena.sparql.expr.Expr)34 Test (org.junit.Test)17 ContractTest (org.xenei.junit.contract.ContractTest)15 Var (org.apache.jena.sparql.core.Var)12 SortCondition (org.apache.jena.query.SortCondition)11 Node (org.apache.jena.graph.Node)9 Op (org.apache.jena.sparql.algebra.Op)7 Triple (org.apache.jena.graph.Triple)6 Query (org.apache.jena.query.Query)6 E_LessThan (org.apache.jena.sparql.expr.E_LessThan)5 E_Random (org.apache.jena.sparql.expr.E_Random)5 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)5 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)4 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 E_Multiply (org.apache.jena.sparql.expr.E_Multiply)4 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)4 ArrayList (java.util.ArrayList)3 E_Regex (org.apache.jena.sparql.expr.E_Regex)3 Random (java.util.Random)2