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());
}
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());
}
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());
}
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());
}
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());
}
Aggregations