Search in sources :

Example 41 with ContractTest

use of org.xenei.junit.contract.ContractTest 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 42 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class SelectClauseTest method testAddVarAsterisk.

@ContractTest
public void testAddVarAsterisk() throws Exception {
    SelectClause<?> selectClause = getProducer().newInstance();
    selectClause.addVar("*");
    Query query = getQuery(selectClause.addVar("*"));
    VarExprList expr = query.getProject();
    assertEquals(0, expr.size());
    assertTrue(query.isQueryResultStar());
}
Also used : Query(org.apache.jena.query.Query) VarExprList(org.apache.jena.sparql.core.VarExprList) ContractTest(org.xenei.junit.contract.ContractTest)

Example 43 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class SelectClauseTest method testAddVarString.

@ContractTest
public void testAddVarString() throws Exception {
    Var v = Var.alloc("one");
    SelectClause<?> selectClause = getProducer().newInstance();
    selectClause.addVar("one");
    Query query = getQuery(selectClause.addVar("one"));
    VarExprList expr = query.getProject();
    assertEquals(1, expr.size());
    assertTrue(expr.contains(v));
}
Also used : Query(org.apache.jena.query.Query) Var(org.apache.jena.sparql.core.Var) VarExprList(org.apache.jena.sparql.core.VarExprList) ContractTest(org.xenei.junit.contract.ContractTest)

Example 44 with ContractTest

use of org.xenei.junit.contract.ContractTest 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 45 with ContractTest

use of org.xenei.junit.contract.ContractTest in project jena by apache.

the class SolutionModifierTest method testSetVarsOrderBy.

@ContractTest
public void testSetVarsOrderBy() {
    Var v = Var.alloc("v");
    SolutionModifierClause<?> solutionModifier = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = solutionModifier.addOrderBy("?v");
    String[] s = byLine(builder);
    assertContainsRegex(ORDER_BY + var("v"), s);
    builder.setVar(v, Var.alloc("v2"));
    s = byLine(builder);
    assertContainsRegex(ORDER_BY + var("v2"), s);
}
Also used : Var(org.apache.jena.sparql.core.Var) ContractTest(org.xenei.junit.contract.ContractTest)

Aggregations

ContractTest (org.xenei.junit.contract.ContractTest)102 GraphHelper.memGraph (org.apache.jena.testing_framework.GraphHelper.memGraph)51 Graph (org.apache.jena.graph.Graph)16 Var (org.apache.jena.sparql.core.Var)13 Query (org.apache.jena.query.Query)9 E_Random (org.apache.jena.sparql.expr.E_Random)9 SelectBuilder (org.apache.jena.arq.querybuilder.SelectBuilder)6 DeleteDeniedException (org.apache.jena.shared.DeleteDeniedException)6 VarExprList (org.apache.jena.sparql.core.VarExprList)6 MalformedURLException (java.net.MalformedURLException)5 URISyntaxException (java.net.URISyntaxException)5 ClosedException (org.apache.jena.shared.ClosedException)5 Expr (org.apache.jena.sparql.expr.Expr)5 Triple (org.apache.jena.graph.Triple)4 PrefixMapping (org.apache.jena.shared.PrefixMapping)3 TriplePath (org.apache.jena.sparql.core.TriplePath)3 Node (org.apache.jena.graph.Node)2 TransactionHandler (org.apache.jena.graph.TransactionHandler)2 Intersection (org.apache.jena.graph.compose.Intersection)2 GraphWithPerform (org.apache.jena.graph.impl.GraphWithPerform)2