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