use of org.apache.jena.sparql.syntax.ElementPathBlock 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.sparql.syntax.ElementPathBlock in project jena by apache.
the class UpdateBuilderTest method testInsertAndDelete.
@Test
public void testInsertAndDelete() {
UpdateBuilder builder = new UpdateBuilder();
builder.addInsert(new Quad(g, s, p, o));
builder.addDelete(new Triple(s, p, o));
builder.addWhere(null, p, "foo");
Update update = builder.build();
assertTrue(update instanceof UpdateModify);
UpdateModify um = (UpdateModify) update;
List<Quad> quads = um.getInsertQuads();
assertEquals(1, quads.size());
Quad q = quads.get(0);
assertEquals(g, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
quads = um.getDeleteQuads();
assertEquals(1, quads.size());
q = quads.get(0);
assertEquals(Quad.defaultGraphNodeGenerated, q.getGraph());
assertEquals(s, q.getSubject());
assertEquals(p, q.getPredicate());
assertEquals(o, q.getObject());
Element e = um.getWherePattern();
assertTrue(e instanceof ElementGroup);
ElementGroup eg = (ElementGroup) e;
assertEquals(1, eg.getElements().size());
ElementPathBlock epb = (ElementPathBlock) eg.getElements().get(0);
Triple t = epb.getPattern().get(0).asTriple();
assertEquals(Node.ANY, t.getSubject());
assertEquals(p, t.getPredicate());
assertEquals(builder.makeNode("foo"), t.getObject());
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class ElementRewriter method visit.
@Override
public void visit(ElementPathBlock el) {
ElementPathBlock newBlock = new ElementPathBlock();
Iterator<TriplePath> tIter = el.patternElts();
while (tIter.hasNext()) {
newBlock.addTriplePath(rewrite(tIter.next()));
}
push(newBlock);
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class TestBlankNodeBinary method bNodeSPARQL_Query_1.
// Check SPARQL parsing.
@Test
public void bNodeSPARQL_Query_1() {
String qs = "SELECT * { ?s ?p <_:ABC>}";
Query query = QueryFactory.create(qs);
Element el = ((ElementGroup) query.getQueryPattern()).get(0);
ElementPathBlock epb = (ElementPathBlock) el;
TriplePath tp = epb.getPattern().get(0);
Triple t = tp.asTriple();
assertEquals("ABC", t.getObject().getBlankNodeLabel());
}
use of org.apache.jena.sparql.syntax.ElementPathBlock in project jena by apache.
the class TestBlankNodeBinary method bNodeSPARQL_Query_1.
// Check SPARQL parsing.
@Test
public void bNodeSPARQL_Query_1() {
String qs = "SELECT * { ?s ?p <_:ABC>}";
Query query = QueryFactory.create(qs);
Element el = ((ElementGroup) query.getQueryPattern()).get(0);
ElementPathBlock epb = (ElementPathBlock) el;
TriplePath tp = epb.getPattern().get(0);
Triple t = tp.asTriple();
assertEquals("ABC", t.getObject().getBlankNodeLabel());
}
Aggregations