Search in sources :

Example 1 with E_Random

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

the class SelectClauseTest method testAddStringVar.

@ContractTest
public void testAddStringVar() throws Exception {
    SelectClause<?> selectClause = getProducer().newInstance();
    AbstractQueryBuilder<?> aqb = selectClause.addVar("rand()", Var.alloc("foo"));
    Query query = getQuery(aqb);
    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 : Query(org.apache.jena.query.Query) Expr(org.apache.jena.sparql.expr.Expr) E_Random(org.apache.jena.sparql.expr.E_Random) VarExprList(org.apache.jena.sparql.core.VarExprList) ContractTest(org.xenei.junit.contract.ContractTest)

Example 2 with E_Random

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

the class SelectClauseTest method testAddExprVar.

@ContractTest
public void testAddExprVar() throws Exception {
    SelectClause<?> selectClause = getProducer().newInstance();
    AbstractQueryBuilder<?> aqb = selectClause.addVar(new E_Random(), Var.alloc("foo"));
    Query query = getQuery(aqb);
    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 : Query(org.apache.jena.query.Query) Expr(org.apache.jena.sparql.expr.Expr) E_Random(org.apache.jena.sparql.expr.E_Random) VarExprList(org.apache.jena.sparql.core.VarExprList) ContractTest(org.xenei.junit.contract.ContractTest)

Example 3 with E_Random

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

the class SolutionModifierTest method testAddHavingExpr.

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

Example 4 with E_Random

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

the class SolutionModifierTest method testAddGroupByVarAndExpr.

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

Example 5 with E_Random

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

the class SolutionModifierTest method testAddOrderByExprAscending.

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

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