use of org.apache.jena.sparql.expr.E_Random in project jena by apache.
the class SolutionModifierTest method testAddOrderByExpr.
@ContractTest
public void testAddOrderByExpr() {
SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
Expr e = new E_Random();
AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy(e);
assertContainsRegex(ORDER_BY + "rand" + OPEN_PAREN + CLOSE_PAREN, builder.buildString());
builder = solutionModifier.addOrderBy("bar");
assertContainsRegex(ORDER_BY + "rand" + OPEN_PAREN + CLOSE_PAREN + SPACE + var("bar"), builder.buildString());
}
use of org.apache.jena.sparql.expr.E_Random 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.expr.E_Random 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.expr.E_Random in project jena by apache.
the class SolutionModifierHandlerTest method testAddHavingExpr.
@Test
public void testAddHavingExpr() throws ParseException {
solutionModifier.addHaving(new E_Random());
assertContainsRegex(HAVING + "rand" + OPEN_PAREN + CLOSE_PAREN, query.toString());
solutionModifier.addHaving("?having2");
assertContainsRegex(HAVING + "rand" + OPEN_PAREN + CLOSE_PAREN + SPACE + var("having2"), query.toString());
}
use of org.apache.jena.sparql.expr.E_Random in project jena by apache.
the class SolutionModifierHandlerTest method testAddGroupByVarAndExpr.
@Test
public void testAddGroupByVarAndExpr() {
solutionModifier.addGroupBy(Var.alloc("groupBy"), new E_Random());
String[] s = byLine(query.toString());
assertContainsRegex(GROUP_BY + OPEN_PAREN + "rand" + OPEN_PAREN + CLOSE_PAREN + SPACE + "AS" + SPACE + var("groupBy") + CLOSE_PAREN, s);
solutionModifier.addGroupBy(Var.alloc("groupBy2"));
s = byLine(query.toString());
assertContainsRegex(GROUP_BY + OPEN_PAREN + "rand" + OPEN_PAREN + CLOSE_PAREN + SPACE + "AS" + SPACE + var("groupBy") + CLOSE_PAREN + SPACE + var("groupBy2"), s);
}
Aggregations