Search in sources :

Example 36 with ExprVar

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

the class ExprFactoryTest method asListTest.

@Test
public void asListTest() {
    ExprList lst = factory.asList("?foo", "http://example.com", Converters.quoted("hello"), 1, 5L, 3.14f, 6.28d, Var.alloc("bar"), null, factory.rand());
    assertEquals(10, lst.size());
    assertEquals(new ExprVar("foo"), lst.get(0));
    // assertEquals( new ExprVar( "foo" ), lst.get(0));
    assertEquals(new NodeValueString("hello"), lst.get(2));
    assertEquals(1, lst.get(3).getConstant().asNode().getLiteralValue());
    assertEquals(5, lst.get(4).getConstant().asNode().getLiteralValue());
    assertEquals(3.14f, lst.get(5).getConstant().asNode().getLiteralValue());
    assertEquals(6.28, lst.get(6).getConstant().asNode().getLiteralValue());
    assertEquals(new ExprVar("bar"), lst.get(7));
    assertEquals(Expr.NONE, lst.get(8));
    assertEquals(new E_Random(), lst.get(9));
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) ExprList(org.apache.jena.sparql.expr.ExprList) E_Random(org.apache.jena.sparql.expr.E_Random) NodeValueString(org.apache.jena.sparql.expr.nodevalue.NodeValueString) Test(org.junit.Test)

Example 37 with ExprVar

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

the class ExprFactoryTest method asExprTest_var.

@Test
public void asExprTest_var() {
    Expr e = factory.asExpr(Var.alloc("hello"));
    assertTrue(e instanceof ExprVar);
    ExprVar v = (ExprVar) e;
    assertEquals("hello", v.asVar().getName());
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) Expr(org.apache.jena.sparql.expr.Expr) Test(org.junit.Test)

Example 38 with ExprVar

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

the class ExprFactoryTest method asExprTest_varString.

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

Example 39 with ExprVar

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

the class ExprFactoryTest method asVarTest_var.

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

Example 40 with ExprVar

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

the class ConvertersTest method makeVarTest.

@Test
public void makeVarTest() {
    Var v = Converters.makeVar(null);
    assertEquals(Var.ANON, v);
    v = Converters.makeVar("a");
    assertEquals(Var.alloc("a"), v);
    v = Converters.makeVar("?a");
    assertEquals(Var.alloc("a"), v);
    Node n = NodeFactory.createVariable("foo");
    v = Converters.makeVar(n);
    assertEquals(Var.alloc("foo"), v);
    NodeFront nf = new NodeFront(n);
    v = Converters.makeVar(nf);
    assertEquals(Var.alloc("foo"), v);
    v = Converters.makeVar(Node_RuleVariable.WILD);
    assertNull(v);
    ExprVar ev = new ExprVar("bar");
    v = Converters.makeVar(ev);
    assertEquals(Var.alloc("bar"), v);
    ev = new ExprVar(n);
    v = Converters.makeVar(ev);
    assertEquals(Var.alloc("foo"), v);
    ev = new ExprVar(Var.ANON);
    v = Converters.makeVar(ev);
    assertEquals(Var.ANON, v);
}
Also used : ExprVar(org.apache.jena.sparql.expr.ExprVar) ExprVar(org.apache.jena.sparql.expr.ExprVar) Var(org.apache.jena.sparql.core.Var) FrontsNode(org.apache.jena.graph.FrontsNode) Node(org.apache.jena.graph.Node) Test(org.junit.Test)

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