Search in sources :

Example 51 with ContractTest

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

the class WhereClauseTest method testAddOptionalTriplePath.

@ContractTest
public void testAddOptionalTriplePath() {
    WhereClause<?> whereClause = getProducer().newInstance();
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("ts", "urn:test:");
    Path path = PathParser.parse("ts:two/ts:dos", pmap);
    AbstractQueryBuilder<?> builder = whereClause.addOptional(new TriplePath(NodeFactory.createURI("one"), path, NodeFactory.createURI("three")));
    assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("urn:test:two") + "/" + uri("urn:test:dos") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) TriplePath(org.apache.jena.sparql.core.TriplePath) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) ContractTest(org.xenei.junit.contract.ContractTest)

Example 52 with ContractTest

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

the class WhereClauseTest method testBindExprVar.

@ContractTest
public void testBindExprVar() {
    Var v = Var.alloc("foo");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addBind(new E_Random(), v);
    assertContainsRegex(OPEN_CURLY + BIND + OPEN_PAREN + "rand\\(\\)" + SPACE + "AS" + SPACE + var("foo") + CLOSE_PAREN + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, NodeFactory.createURI("three"));
    Query q = builder.build();
    ElementGroup eg = (ElementGroup) q.getQueryPattern();
    List<Element> lst = eg.getElements();
    assertEquals("Should only be one element", 1, lst.size());
    assertTrue("Should have an ElementTriplesBlock", lst.get(0) instanceof ElementTriplesBlock);
    ElementTriplesBlock etb = (ElementTriplesBlock) lst.get(0);
    assertTrue("ElementGroup should be empty", etb.isEmpty());
}
Also used : Query(org.apache.jena.query.Query) E_Random(org.apache.jena.sparql.expr.E_Random) Var(org.apache.jena.sparql.core.Var) Element(org.apache.jena.sparql.syntax.Element) ElementTriplesBlock(org.apache.jena.sparql.syntax.ElementTriplesBlock) ElementGroup(org.apache.jena.sparql.syntax.ElementGroup) ContractTest(org.xenei.junit.contract.ContractTest)

Example 53 with ContractTest

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

the class WhereClauseTest method testSetVarsInTriple.

@ContractTest
public void testSetVarsInTriple() {
    Var v = Var.alloc("v");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addWhere(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, NodeFactory.createURI("three"));
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, NodeFactory.createURI("four"));
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("four") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
    builder.setVar(v, null);
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
}
Also used : Triple(org.apache.jena.graph.Triple) Var(org.apache.jena.sparql.core.Var) ContractTest(org.xenei.junit.contract.ContractTest)

Example 54 with ContractTest

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

the class WhereClauseTest method testAddOptionalObjectsWithPath.

@ContractTest
public void testAddOptionalObjectsWithPath() {
    WhereClause<?> whereClause = getProducer().newInstance();
    PrefixMapping pmap = new PrefixMappingImpl();
    pmap.setNsPrefix("ts", "urn:test:");
    Path path = PathParser.parse("ts:two/ts:dos", pmap);
    AbstractQueryBuilder<?> builder = whereClause.addOptional(NodeFactory.createURI("one"), path, NodeFactory.createURI("three"));
    assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("urn:test:two") + "/" + uri("urn:test:dos") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, builder.buildString());
}
Also used : TriplePath(org.apache.jena.sparql.core.TriplePath) Path(org.apache.jena.sparql.path.Path) PrefixMapping(org.apache.jena.shared.PrefixMapping) PrefixMappingImpl(org.apache.jena.shared.impl.PrefixMappingImpl) ContractTest(org.xenei.junit.contract.ContractTest)

Example 55 with ContractTest

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

the class WhereClauseTest method testAddSubQuery.

@ContractTest
public void testAddSubQuery() {
    SelectBuilder sb = new SelectBuilder();
    sb.addPrefix("pfx", "urn:uri").addVar("?x").addWhere("pfx:one", "pfx:two", "pfx:three");
    WhereClause<?> whereClause = getProducer().newInstance();
    AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
    assertContainsRegex(PREFIX + "pfx:" + SPACE + uri("urn:uri") + SPACE + ".*" + WHERE + OPEN_CURLY + OPEN_CURLY + SELECT + var("x") + SPACE + WHERE + OPEN_CURLY + "pfx:one" + SPACE + "pfx:two" + SPACE + "pfx:three" + OPT_SPACE + CLOSE_CURLY, builder.buildString());
}
Also used : SelectBuilder(org.apache.jena.arq.querybuilder.SelectBuilder) 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