use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class WhereHandlerTest method testSetVarsInTriple.
@Test
public void testSetVarsInTriple() {
Var v = Var.alloc("v");
handler.addWhere(new TriplePath(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, query.toString());
Map<Var, Node> values = new HashMap<>();
values.put(v, NodeFactory.createURI("three"));
handler.setVars(values);
assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
}
use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class ElementTransformSubst method transform.
@Override
public Element transform(ElementPathBlock el) {
ElementPathBlock epb = new ElementPathBlock();
boolean changed = false;
for (TriplePath p : el.getPattern()) {
TriplePath p2 = transform(p);
changed = changed || p != p2;
epb.addTriplePath(p2);
}
if (changed)
return epb;
return el;
}
use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class WhereHandlerTest method testAddOptionalObjects.
@Test
public void testAddOptionalObjects() {
handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode())));
assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + quote("three") + "@en-US" + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class WhereHandlerTest method testAddOptionalStrings.
@Test
public void testAddOptionalStrings() {
handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
use of org.apache.jena.sparql.core.TriplePath in project jena by apache.
the class WhereHandlerTest method testSetVarsInOptional.
@Test
public void testSetVarsInOptional() {
Var v = Var.alloc("v");
handler.addOptional(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v)));
assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + var("v") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
Map<Var, Node> values = new HashMap<>();
values.put(v, NodeFactory.createURI("three"));
handler.setVars(values);
assertContainsRegex(WHERE + OPEN_CURLY + "OPTIONAL" + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
Aggregations