use of org.apache.jena.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromSelectWithVar.
@Test
public void testMakeSubQueryFromSelectWithVar() {
SelectBuilder sb = new SelectBuilder().addVar("?x").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.addResultVar(NodeFactory.createVariable("x"));
q.setQueryPattern(epb);
ElementSubQuery esq2 = new ElementSubQuery(q);
WhereValidator wv = new WhereValidator(esq2);
esq.visit(wv);
assertTrue(wv.matching);
}
use of org.apache.jena.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromWhere.
@Test
public void testMakeSubQueryFromWhere() {
AbstractQueryBuilder<?> sb = new WhereBuilder().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.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereHandlerTest method testMakeSubQueryFromAsk.
@Test
public void testMakeSubQueryFromAsk() {
AbstractQueryBuilder<?> sb = new AskBuilder().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.sparql.syntax.ElementSubQuery in project jena by apache.
the class WhereHandlerTest method testAddSubQueryWithVarExpressions.
@Test
public void testAddSubQueryWithVarExpressions() throws ParseException {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addVar("count(*)", "?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.allocAggregate(new AggCount()));
q.setQuerySelectType();
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.sparql.syntax.ElementSubQuery 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);
}
Aggregations