Search in sources :

Example 26 with ExprVar

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

the class ExprFactoryTest method asVarTest.

@Test
public void asVarTest() {
    Expr e = factory.asVar("hello");
    assertTrue(e instanceof ExprVar);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) Test(org.junit.Test)

Example 27 with ExprVar

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

the class ExprFactoryTest method asVarTest_null.

@Test
public void asVarTest_null() {
    Expr e = factory.asVar(null);
    assertTrue(e instanceof ExprVar);
    ExprVar v = (ExprVar) e;
    assertEquals("?_", v.asVar().getName());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) Test(org.junit.Test)

Example 28 with ExprVar

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

the class SolutionModifierTest method testAddHavingObject.

@ContractTest
public void testAddHavingObject() throws ParseException {
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addHaving(Var.alloc("foo"));
    Query query = builder.build();
    assertTrue(query.hasHaving());
    List<Expr> having = query.getHavingExprs();
    assertEquals(1, having.size());
    Expr exp = having.get(0);
    assertTrue(exp.isVariable());
    assertEquals(new ExprVar("foo"), exp.getExprVar());
    builder = solutionModifier.addHaving("?having2");
    query = builder.build();
    assertTrue(query.hasHaving());
    having = query.getHavingExprs();
    assertEquals(2, having.size());
    exp = having.get(0);
    assertTrue(exp.isVariable());
    assertEquals(new ExprVar("foo"), exp.getExprVar());
    exp = having.get(1);
    assertTrue(exp.isVariable());
    assertEquals(new ExprVar("having2"), exp.getExprVar());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Query(org.apache.jena.query.Query) Expr(org.apache.jena.sparql.expr.Expr) ContractTest(org.xenei.junit.contract.ContractTest)

Example 29 with ExprVar

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

the class SolutionModifierTest method testSetVarsOrderBy_NodeVariable.

@ContractTest
public void testSetVarsOrderBy_NodeVariable() {
    Node v = NodeFactory.createVariable("v");
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy(v);
    List<SortCondition> lst = builder.build().getOrderBy();
    Assert.assertEquals(1, lst.size());
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc(v)), Query.ORDER_DEFAULT), lst.get(0));
    builder.setVar(v, Var.alloc("v2"));
    lst = builder.build().getOrderBy();
    Assert.assertEquals(1, lst.size());
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("v2")), Query.ORDER_DEFAULT), lst.get(0));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) SortCondition(org.apache.jena.query.SortCondition) Node(org.apache.jena.graph.Node) ContractTest(org.xenei.junit.contract.ContractTest)

Example 30 with ExprVar

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

the class SolutionModifierTest method testAddOrderByStringAscending.

@ContractTest
public void testAddOrderByStringAscending() {
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy("foo", Order.ASCENDING);
    List<SortCondition> lst = builder.build().getOrderBy();
    Assert.assertEquals(1, lst.size());
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("foo")), Query.ORDER_ASCENDING), lst.get(0));
    builder = solutionModifier.addOrderBy("bar");
    lst = builder.build().getOrderBy();
    Assert.assertEquals(2, lst.size());
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("foo")), Query.ORDER_ASCENDING), lst.get(0));
    Assert.assertEquals(new SortCondition(new ExprVar(Var.alloc("bar")), Query.ORDER_DEFAULT), lst.get(1));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) SortCondition(org.apache.jena.query.SortCondition) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ExprVar (org.apache.jena.sparql.expr.ExprVar)51 Expr (org.apache.jena.sparql.expr.Expr)34 Test (org.junit.Test)17 ContractTest (org.xenei.junit.contract.ContractTest)15 Var (org.apache.jena.sparql.core.Var)12 SortCondition (org.apache.jena.query.SortCondition)11 Node (org.apache.jena.graph.Node)9 Op (org.apache.jena.sparql.algebra.Op)7 Triple (org.apache.jena.graph.Triple)6 Query (org.apache.jena.query.Query)6 E_LessThan (org.apache.jena.sparql.expr.E_LessThan)5 E_Random (org.apache.jena.sparql.expr.E_Random)5 NodeValueInteger (org.apache.jena.sparql.expr.nodevalue.NodeValueInteger)5 OpBGP (org.apache.jena.sparql.algebra.op.OpBGP)4 BasicPattern (org.apache.jena.sparql.core.BasicPattern)4 E_Multiply (org.apache.jena.sparql.expr.E_Multiply)4 ElementFilter (org.apache.jena.sparql.syntax.ElementFilter)4 ArrayList (java.util.ArrayList)3 E_Regex (org.apache.jena.sparql.expr.E_Regex)3 Random (java.util.Random)2