use of org.apache.jena.sparql.syntax.ElementOptional 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())));
handler.build();
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), ResourceFactory.createResource("two").asNode(), ResourceFactory.createLangLiteral("three", "en-US").asNode()));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementOptional in project jena by apache.
the class WhereClauseTest method testAddOptionalGroupPattern.
@ContractTest
public void testAddOptionalGroupPattern() {
Var s = Var.alloc("s");
Node q = NodeFactory.createURI("urn:q");
Node v = NodeFactory.createURI("urn:v");
Var x = Var.alloc("x");
Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
SelectBuilder pattern = new SelectBuilder();
pattern.addWhere(new Triple(s, q, n123));
pattern.addWhere(new Triple(s, v, x));
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional(pattern);
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(new Triple(s, q, n123));
epb.addTriplePath(tp);
tp = new TriplePath(new Triple(s, v, x));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementOptional in project jena by apache.
the class WhereClauseTest method testSetVarsInOptional_Node_Variable.
@ContractTest
public void testSetVarsInOptional_Node_Variable() {
Node v = NodeFactory.createVariable("v");
Node one = NodeFactory.createURI("one");
Node two = NodeFactory.createURI("two");
Node three = NodeFactory.createURI("three");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional(new Triple(one, two, v));
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(new Triple(one, two, Var.alloc(v)));
epb.addTriplePath(tp);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, three);
epb = new ElementPathBlock();
optional = new ElementOptional(epb);
tp = new TriplePath(new Triple(one, two, three));
epb.addTriplePath(tp);
visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementOptional in project jena by apache.
the class WhereClauseTest method testSetVarsInOptional.
@ContractTest
public void testSetVarsInOptional() {
Var v = Var.alloc("v");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
TriplePath tp = new TriplePath(NodeFactory.createURI("one"), new P_Link(NodeFactory.createURI("two")), v);
epb.addTriple(tp);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, NodeFactory.createURI("three"));
epb = new ElementPathBlock();
optional = new ElementOptional(epb);
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
epb.addTriple(t);
visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementOptional in project jena by apache.
the class WhereClauseTest method testAddOptionalObjects.
@ContractTest
public void testAddOptionalObjects() {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
epb.addTriple(t);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations