use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddFilter.
@Test
public void testAddFilter() throws ParseException {
handler.addFilter("?one < 10");
handler.build();
BigInteger bi = new BigInteger(Integer.toString(10));
E_LessThan expr = new ExprFactory().lt(NodeFactory.createVariable("one"), bi);
WhereValidator visitor = new WhereValidator(new ElementFilter(expr));
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddUnionWithVar.
@Test
public void testAddUnionWithVar() {
Triple t1 = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"));
Triple t2 = new Triple(NodeFactory.createURI("uno"), NodeFactory.createURI("dos"), NodeFactory.createURI("tres"));
SelectBuilder sb = new SelectBuilder().addVar("x").addWhere(t1);
handler.addUnion(sb);
SelectBuilder sb2 = new SelectBuilder().addWhere(t2);
handler.addUnion(sb2);
handler.build();
ElementUnion union = new ElementUnion();
Query q = new Query();
q.setQuerySelectType();
ElementPathBlock epb1 = new ElementPathBlock();
epb1.addTriple(t1);
q.setQueryPattern(epb1);
q.addProjectVars(Arrays.asList(Var.alloc("x")));
ElementSubQuery sq = new ElementSubQuery(q);
union.addElement(sq);
ElementPathBlock epb2 = new ElementPathBlock();
epb2.addTriple(t2);
union.addElement(epb2);
WhereValidator visitor = new WhereValidator(union);
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testList.
@Test
public void testList() {
Node n = handler.list("<one>", "?var", "'three'");
Node one = NodeFactory.createURI("one");
Node two = Var.alloc("var").asNode();
Node three = NodeFactory.createLiteral("three");
ElementPathBlock epb = new ElementPathBlock();
Node firstObject = NodeFactory.createBlankNode();
Node secondObject = NodeFactory.createBlankNode();
Node thirdObject = NodeFactory.createBlankNode();
epb.addTriplePath(new TriplePath(new Triple(firstObject, RDF.first.asNode(), one)));
epb.addTriplePath(new TriplePath(new Triple(firstObject, RDF.rest.asNode(), secondObject)));
epb.addTriplePath(new TriplePath(new Triple(secondObject, RDF.first.asNode(), two)));
epb.addTriplePath(new TriplePath(new Triple(secondObject, RDF.rest.asNode(), thirdObject)));
epb.addTriplePath(new TriplePath(new Triple(thirdObject, RDF.first.asNode(), three)));
epb.addTriplePath(new TriplePath(new Triple(thirdObject, RDF.rest.asNode(), RDF.nil.asNode())));
WhereValidator visitor = new WhereValidator(epb);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
assertTrue(n.isBlank());
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddFilterWithNamespace.
@Test
public void testAddFilterWithNamespace() throws ParseException {
query.setPrefix("afn", "http://jena.apache.org/ARQ/function#");
handler.addFilter("afn:namespace(?one) = 'foo'");
handler.build();
ExprFactory fact = new ExprFactory();
E_Function func = new E_Function("http://jena.apache.org/ARQ/function#namespace", fact.asList("?one"));
E_Equals expr = fact.eq(func, "foo");
WhereValidator visitor = new WhereValidator(new ElementFilter(expr));
handler.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddSubQueryWithVars.
@Test
public void testAddSubQueryWithVars() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addVar("?x").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.addResultVar("x");
q.setQuerySelectType();
q.setQueryPattern(epb);
ElementSubQuery esq = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq);
query.getQueryPattern().visit(wv);
assertTrue(wv.matching);
}
Aggregations