Search in sources :

Example 11 with E_Random

use of org.apache.jena.sparql.expr.E_Random in project jena by apache.

the class SolutionModifierHandlerTest method testAddGroupByExpr.

@Test
public void testAddGroupByExpr() {
    solutionModifier.addGroupBy(new E_Random());
    String[] s = byLine(query.toString());
    assertContainsRegex(GROUP_BY + "rand" + OPEN_PAREN + CLOSE_PAREN, s);
    solutionModifier.addGroupBy(Var.alloc("groupBy2"));
    s = byLine(query.toString());
    assertContainsRegex(GROUP_BY + "rand" + OPEN_PAREN + CLOSE_PAREN + SPACE + var("groupBy2"), s);
}
Also used : E_Random(org.apache.jena.sparql.expr.E_Random) Test(org.junit.Test)

Example 12 with E_Random

use of org.apache.jena.sparql.expr.E_Random in project jena by apache.

the class WhereHandlerTest method testBindExprVar.

@Test
public void testBindExprVar() {
    Var v = Var.alloc("foo");
    handler.addBind(new E_Random(), v);
    assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, query.toString());
}
Also used : E_Random(org.apache.jena.sparql.expr.E_Random) Var(org.apache.jena.sparql.core.Var) Test(org.junit.Test)

Example 13 with E_Random

use of org.apache.jena.sparql.expr.E_Random in project jena by apache.

the class SelectHandlerTest method testAddExprVar.

@Test
public void testAddExprVar() {
    Var v = Var.alloc("foo");
    handler.addVar(new E_Random(), 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 14 with E_Random

use of org.apache.jena.sparql.expr.E_Random in project jena by apache.

the class SolutionModifierTest method testAddOrderByExprDescending.

@ContractTest
public void testAddOrderByExprDescending() {
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    Expr e = new E_Random();
    AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy(e, Order.DESCENDING);
    assertContainsRegex(ORDER_BY + "DESC" + OPEN_PAREN + "rand" + OPEN_PAREN + CLOSE_PAREN + CLOSE_PAREN, builder.buildString());
    builder = solutionModifier.addOrderBy("bar");
    assertContainsRegex(ORDER_BY + "DESC" + OPEN_PAREN + "rand" + OPEN_PAREN + CLOSE_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 15 with E_Random

use of org.apache.jena.sparql.expr.E_Random in project jena by apache.

the class SolutionModifierTest method testAddGroupByExpr.

@ContractTest
public void testAddGroupByExpr() {
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addGroupBy(new E_Random());
    assertContainsRegex(GROUP_BY + "rand" + OPEN_PAREN + CLOSE_PAREN, builder.buildString());
    builder = solutionModifier.addGroupBy("bar");
    assertContainsRegex(GROUP_BY + "rand" + OPEN_PAREN + CLOSE_PAREN + SPACE + var("bar"), builder.buildString());
}
Also used : E_Random(org.apache.jena.sparql.expr.E_Random) ContractTest(org.xenei.junit.contract.ContractTest)

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