Search in sources :

Example 6 with E_Random

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());
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) E_Random(org.apache.jena.sparql.expr.E_Random) ContractTest(org.xenei.junit.contract.ContractTest)

Example 7 with E_Random

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());
}
Also used : Query(org.apache.jena.query.Query) E_Random(org.apache.jena.sparql.expr.E_Random) Var(org.apache.jena.sparql.core.Var) Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ContractTest(org.xenei.junit.contract.ContractTest)

Example 8 with E_Random

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);
}
Also used : Expr(org.apache.jena.sparql.expr.Expr) E_Random(org.apache.jena.sparql.expr.E_Random) Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList) Test(org.junit.Test)

Example 9 with 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());
}
Also used : E_Random(org.apache.jena.sparql.expr.E_Random) Test(org.junit.Test)

Example 10 with E_Random

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);
}
Also used : E_Random(org.apache.jena.sparql.expr.E_Random) Test(org.junit.Test)

Aggregations

E_Random (org.apache.jena.sparql.expr.E_Random)15 ContractTest (org.xenei.junit.contract.ContractTest)9 Expr (org.apache.jena.sparql.expr.Expr)7 Test (org.junit.Test)6 Var (org.apache.jena.sparql.core.Var)4 VarExprList (org.apache.jena.sparql.core.VarExprList)4 Query (org.apache.jena.query.Query)3 Element (org.apache.jena.sparql.syntax.Element)1 ElementGroup (org.apache.jena.sparql.syntax.ElementGroup)1 ElementTriplesBlock (org.apache.jena.sparql.syntax.ElementTriplesBlock)1