use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddAllPopulatedEmpty.
@Test
public void testAddAllPopulatedEmpty() {
handler.addWhere(new TriplePath(Triple.ANY));
Query query2 = new Query();
WhereHandler handler2 = new WhereHandler(query2);
handler2.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
handler.addAll(handler2);
handler.build();
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(Triple.ANY);
ElementGroup eg = new ElementGroup();
eg.addElement(epb);
epb = new ElementPathBlock();
Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
epb.addTriple(t1);
eg.addElement(epb);
WhereValidator wv = new WhereValidator(eg);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddSubQueryWithoutVars.
@Test
public void testAddSubQueryWithoutVars() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", "three");
handler.addSubQuery(sb);
handler.build();
Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
TriplePath tp = new TriplePath(t1);
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
Query q = new Query();
q.setQuerySelectType();
q.setQueryResultStar(true);
q.setQueryPattern(epb);
ElementSubQuery esq = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromDescribe.
@Test
public void testMakeSubQueryFromDescribe() {
AbstractQueryBuilder<?> sb = new DescribeBuilder().addWhere("?x", RDF.type, RDF.Alt);
ElementSubQuery esq = handler.makeSubQuery(sb);
Triple t1 = new Triple(NodeFactory.createVariable("x"), RDF.type.asNode(), RDF.Alt.asNode());
TriplePath tp = new TriplePath(t1);
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
Query q = new Query();
q.setQuerySelectType();
q.setQueryResultStar(true);
q.setQueryPattern(epb);
ElementSubQuery esq2 = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq2);
esq.visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddOptionalAnonymous.
@Test
public void testAddOptionalAnonymous() {
handler.addOptional(new TriplePath(new Triple(Node.ANY, RDF.first.asNode(), Node.ANY)));
handler.build();
TriplePath tp = new TriplePath(new Triple(Node.ANY, RDF.first.asNode(), Node.ANY));
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
ElementOptional opt = new ElementOptional(epb);
WhereValidator wv = new WhereValidator(opt);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testSetVarsInSubQuery.
@Test
public void testSetVarsInSubQuery() {
Var v = Var.alloc("v");
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", v);
handler.addSubQuery(sb);
handler.build();
TriplePath tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), v));
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
WhereValidator wv = new WhereValidator(epb);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
Map<Var, Node> values = new HashMap<>();
values.put(v, NodeFactory.createURI("three"));
handler.setVars(values);
handler.build();
tp = new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three")));
epb = new ElementPathBlock();
epb.addTriple(tp);
wv = new WhereValidator(epb);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
Aggregations