use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testSetVarsInTriple.
@ContractTest
public void testSetVarsInTriple() {
Var v = Var.alloc("v");
Node one = NodeFactory.createURI("one");
Node two = NodeFactory.createURI("two");
Node three = NodeFactory.createURI("three");
Node four = NodeFactory.createURI("four");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhere(new Triple(one, two, v));
TriplePath tp = new TriplePath(new Triple(one, two, v));
ElementPathBlock epb = new ElementPathBlock();
epb.addTriple(tp);
WhereValidator visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, three);
tp = new TriplePath(new Triple(one, two, three));
epb = new ElementPathBlock();
epb.addTriple(tp);
visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, four);
tp = new TriplePath(new Triple(one, two, four));
epb = new ElementPathBlock();
epb.addTriple(tp);
visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, null);
tp = new TriplePath(new Triple(one, two, v));
epb = new ElementPathBlock();
epb.addTriple(tp);
visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator 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);
Query query = builder.build();
WhereValidator visitor = new WhereValidator(new ElementBind(Var.alloc("foo"), new E_Random()));
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
builder.setVar(v, NodeFactory.createURI("three"));
query = builder.build();
visitor = new WhereValidator(new ElementTriplesBlock());
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testAddGraph_triplePath.
@ContractTest
public void testAddGraph_triplePath() {
final Node s = NodeFactory.createURI("s");
final Node p = NodeFactory.createURI("p");
final Node o = NodeFactory.createURI("o");
TriplePath tp = new TriplePath(new Triple(s, p, o));
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addGraph("<g>", tp);
Query query = builder.build();
ElementPathBlock epb = new ElementPathBlock();
ElementNamedGraph eng = new ElementNamedGraph(NodeFactory.createURI("g"), epb);
epb.addTriplePath(new TriplePath(new Triple(s, p, o)));
WhereValidator visitor = new WhereValidator(eng);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereClauseTest method testSetVarsInFilter.
@ContractTest
public void testSetVarsInFilter() throws ParseException {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addFilter("?one < ?v");
ExprVar one = new ExprVar(NodeFactory.createVariable("one"));
ExprVar v = new ExprVar(NodeFactory.createVariable("v"));
Expr expr = new E_LessThan(one, v);
ElementFilter filter = new ElementFilter(expr);
WhereValidator visitor = new WhereValidator(filter);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
Node literal = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(10));
builder.setVar(Var.alloc("v"), literal);
NodeValueInteger lit = new NodeValueInteger(10);
expr = new E_LessThan(one, lit);
filter = new ElementFilter(expr);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.arq.querybuilder.WhereValidator in project jena by apache.
the class WhereHandlerTest method testAddMinus.
@Test
public void testAddMinus() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addWhere("<one>", "<two>", "three");
handler.addMinus(sb);
handler.build();
ElementPathBlock epb = new ElementPathBlock();
ElementMinus minus = new ElementMinus(epb);
epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
WhereValidator visitor = new WhereValidator(minus);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations