use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SelectHandlerTest method testAddStringVar.
@Test
public void testAddStringVar() {
Var v = Var.alloc("foo");
handler.addVar("rand()", v);
VarExprList expr = query.getProject();
assertEquals(1, expr.size());
Expr e = expr.getExpr(Var.alloc("foo"));
assertNotNull("expression should not be null", e);
assertTrue("Should be an E_Random", e instanceof E_Random);
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SolutionModifierHandlerTest method testSetVarsHaving.
@Test
public void testSetVarsHaving() {
Var v = Var.alloc("v");
solutionModifier.addHaving(v);
String[] s = byLine(query.toString());
assertContainsRegex(HAVING + var("v"), s);
Map<Var, Node> values = new HashMap<>();
values.put(v, Var.alloc("v2"));
solutionModifier.setVars(values);
s = byLine(query.toString());
assertContainsRegex(HAVING + var("v2"), s);
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class SolutionModifierHandlerTest method testSetVarsOrderBy.
@Test
public void testSetVarsOrderBy() {
Var v = Var.alloc("v");
solutionModifier.addOrderBy(v);
String[] s = byLine(query.toString());
assertContainsRegex(ORDER_BY + var("v"), s);
Map<Var, Node> values = new HashMap<>();
values.put(v, Var.alloc("v2"));
solutionModifier.setVars(values);
s = byLine(query.toString());
assertContainsRegex(ORDER_BY + var("v2"), s);
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class ValuesHandlerTest method twoVarTwoBlocksWithVarReplacement.
@Test
public void twoVarTwoBlocksWithVarReplacement() {
Node n = NodeFactory.createLiteral("hello");
Node nn = NodeFactory.createLiteral("hola");
Node n2 = NodeFactory.createLiteral("there");
Node nn2 = NodeFactory.createLiteral("aqui");
Var v = Var.alloc("x");
Var v2 = Var.alloc("y");
handler.addValueVar(v, null);
handler.addValueVar(v2, null);
handler.addValueRow(Arrays.asList(n, n2));
handler.addValueRow(Arrays.asList(nn, nn2));
Map<Var, Node> replaceVars = new HashMap<Var, Node>();
replaceVars.put(v2, NodeFactory.createBlankNode());
handler.setVars(replaceVars);
handler.build();
List<Var> vars = query.getValuesVariables();
assertEquals(1, vars.size());
assertEquals(v, vars.get(0));
assertNotNull(query.getValuesData());
List<Binding> lb = query.getValuesData();
assertEquals(2, lb.size());
List<Node> ln = new ArrayList<Node>();
ln.add(n);
ln.add(nn);
for (Binding b : lb) {
assertTrue(b.contains(v));
assertFalse(b.contains(v2));
assertTrue(ln.contains(b.get(v)));
ln.remove(b.get(v));
}
}
use of org.apache.jena.sparql.core.Var in project jena by apache.
the class AbstractQueryBuilderTest method testMakeVar.
@Test
public void testMakeVar() {
Var v = AbstractQueryBuilder.makeVar(null);
assertEquals(Var.ANON, v);
v = AbstractQueryBuilder.makeVar("a");
assertEquals(Var.alloc("a"), v);
v = AbstractQueryBuilder.makeVar("?a");
assertEquals(Var.alloc("a"), v);
Node n = NodeFactory.createVariable("foo");
v = AbstractQueryBuilder.makeVar(n);
assertEquals(Var.alloc("foo"), v);
NodeFront nf = new NodeFront(n);
v = AbstractQueryBuilder.makeVar(nf);
assertEquals(Var.alloc("foo"), v);
v = AbstractQueryBuilder.makeVar(Node_RuleVariable.WILD);
assertNull(v);
ExprVar ev = new ExprVar("bar");
v = AbstractQueryBuilder.makeVar(ev);
assertEquals(Var.alloc("bar"), v);
ev = new ExprVar(n);
v = AbstractQueryBuilder.makeVar(ev);
assertEquals(Var.alloc("foo"), v);
ev = new ExprVar(Var.ANON);
v = AbstractQueryBuilder.makeVar(ev);
assertEquals(Var.ANON, v);
}
Aggregations