use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class ExprFactoryTest method asVarTest.
@Test
public void asVarTest() {
Expr e = factory.asVar("hello");
assertTrue(e instanceof ExprVar);
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class ExprFactoryTest method asVarTest_null.
@Test
public void asVarTest_null() {
Expr e = factory.asVar(null);
assertTrue(e instanceof ExprVar);
ExprVar v = (ExprVar) e;
assertEquals("?_", v.asVar().getName());
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class SolutionModifierTest method testAddHavingObject.
@ContractTest
public void testAddHavingObject() throws ParseException {
SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
AbstractQueryBuilder<?> builder = solutionModifier.addHaving(Var.alloc("foo"));
Query query = builder.build();
assertTrue(query.hasHaving());
List<Expr> having = query.getHavingExprs();
assertEquals(1, having.size());
Expr exp = having.get(0);
assertTrue(exp.isVariable());
assertEquals(new ExprVar("foo"), exp.getExprVar());
builder = solutionModifier.addHaving("?having2");
query = builder.build();
assertTrue(query.hasHaving());
having = query.getHavingExprs();
assertEquals(2, having.size());
exp = having.get(0);
assertTrue(exp.isVariable());
assertEquals(new ExprVar("foo"), exp.getExprVar());
exp = having.get(1);
assertTrue(exp.isVariable());
assertEquals(new ExprVar("having2"), exp.getExprVar());
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class SolutionModifierTest method testSetVarsOrderBy_NodeVariable.
@ContractTest
public void testSetVarsOrderBy_NodeVariable() {
Node v = NodeFactory.createVariable("v");
SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy(v);
List<SortCondition> lst = builder.build().getOrderBy();
Assert.assertEquals(1, lst.size());
Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc(v)), Query.ORDER_DEFAULT), lst.get(0));
builder.setVar(v, Var.alloc("v2"));
lst = builder.build().getOrderBy();
Assert.assertEquals(1, lst.size());
Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("v2")), Query.ORDER_DEFAULT), lst.get(0));
}
use of org.apache.jena.sparql.expr.ExprVar in project jena by apache.
the class SolutionModifierTest method testAddOrderByStringAscending.
@ContractTest
public void testAddOrderByStringAscending() {
SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy("foo", Order.ASCENDING);
List<SortCondition> lst = builder.build().getOrderBy();
Assert.assertEquals(1, lst.size());
Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("foo")), Query.ORDER_ASCENDING), 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_ASCENDING), lst.get(0));
Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("bar")), Query.ORDER_DEFAULT), lst.get(1));
}
Aggregations