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