use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereClauseTest method testAddOptionalTriple.
@ContractTest
public void testAddOptionalTriple() {
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);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereClauseTest method testAddMinus.
@ContractTest
public void testAddMinus() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "uri").addVar("?x").addWhere("<one>", "<two>", "three");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addMinus(sb);
Query query = builder.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);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereClauseTest method testAddOptionalString.
@ContractTest
public void testAddOptionalString() {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addOptional("<one>", "<two>", "three");
ElementPathBlock epb = new ElementPathBlock();
ElementOptional optional = new ElementOptional(epb);
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
epb.addTriple(t);
WhereValidator visitor = new WhereValidator(optional);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereClauseTest method testAddWhereStrings.
@ContractTest
public void testAddWhereStrings() {
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addWhere("<one>", "<two>", "three");
ElementPathBlock epb = new ElementPathBlock();
Triple t = new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"));
epb.addTriple(t);
WhereValidator visitor = new WhereValidator(epb);
builder.build().getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class WhereClauseTest method testAddSubQuery.
@ContractTest
public void testAddSubQuery() {
SelectBuilder sb = new SelectBuilder();
sb.addPrefix("pfx", "urn:uri:").addVar("?x").addWhere("pfx:one", "pfx:two", "pfx:three");
WhereClause<?> whereClause = getProducer().newInstance();
AbstractQueryBuilder<?> builder = whereClause.addSubQuery(sb);
Query query = builder.build();
Query q2 = new Query();
q2.setQuerySelectType();
q2.addProjectVars(Arrays.asList(Var.alloc("x")));
ElementPathBlock epb = new ElementPathBlock();
q2.setQueryPattern(epb);
epb.addTriplePath(new TriplePath(new Triple(NodeFactory.createURI("urn:uri:one"), NodeFactory.createURI("urn:uri:two"), NodeFactory.createURI("urn:uri:three"))));
ElementSubQuery esq = new ElementSubQuery(q2);
WhereValidator visitor = new WhereValidator(esq);
query.getQueryPattern().visit(visitor);
assertTrue(visitor.matching);
}
Aggregations