Search in sources :

Example 1 with WhereHandler

use of org.apache.jena.arq.querybuilder.handlers.WhereHandler in project jena by apache.

the class WhereHandlerTest method testAddAllPopulatedEmpty.

@Test
public void testAddAllPopulatedEmpty() {
    handler.addWhere(new TriplePath(Triple.ANY));
    Query query2 = new Query();
    WhereHandler handler2 = new WhereHandler(query2);
    handler2.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
    handler.addAll(handler2);
    assertContainsRegex(WHERE + OPEN_CURLY + "ANY" + SPACE + "ANY" + SPACE + "ANY" + DOT + SPACE + uri("one") + SPACE + uri("two") + SPACE + quote("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) WhereHandler(org.apache.jena.arq.querybuilder.handlers.WhereHandler) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Example 2 with WhereHandler

use of org.apache.jena.arq.querybuilder.handlers.WhereHandler in project jena by apache.

the class WhereHandlerTest method testAddAllOnEmpty.

@Test
public void testAddAllOnEmpty() {
    Query query2 = new Query();
    WhereHandler handler2 = new WhereHandler(query2);
    handler2.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createLiteral("three"))));
    handler.addAll(handler2);
    assertContainsRegex(WHERE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + quote("three") + OPT_SPACE + CLOSE_CURLY, query.toString());
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) WhereHandler(org.apache.jena.arq.querybuilder.handlers.WhereHandler) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Example 3 with WhereHandler

use of org.apache.jena.arq.querybuilder.handlers.WhereHandler in project jena by apache.

the class WhereHandlerTest method addGraph.

@Test
public void addGraph() {
    WhereHandler handler2 = new WhereHandler(new Query());
    handler2.addWhere(new TriplePath(new Triple(NodeFactory.createURI("one"), NodeFactory.createURI("two"), NodeFactory.createURI("three"))));
    handler.addGraph(NodeFactory.createURI("graph"), handler2);
    assertContainsRegex(WHERE + OPEN_CURLY + "GRAPH" + SPACE + uri("graph") + SPACE + OPEN_CURLY + uri("one") + SPACE + uri("two") + SPACE + uri("three") + OPT_SPACE + CLOSE_CURLY + CLOSE_CURLY, query.toString());
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) WhereHandler(org.apache.jena.arq.querybuilder.handlers.WhereHandler) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Example 4 with WhereHandler

use of org.apache.jena.arq.querybuilder.handlers.WhereHandler in project jena by apache.

the class WhereHandlerTest method setup.

@Before
public void setup() {
    query = new Query();
    handler = new WhereHandler(query);
}
Also used : Query(org.apache.jena.query.Query) WhereHandler(org.apache.jena.arq.querybuilder.handlers.WhereHandler) Before(org.junit.Before)

Example 5 with WhereHandler

use of org.apache.jena.arq.querybuilder.handlers.WhereHandler in project jena by apache.

the class WhereHandlerTest method testAddOptionalWhereHandler.

@Test
public void testAddOptionalWhereHandler() throws ParseException {
    WhereHandler pattern = new WhereHandler(new Query());
    Var s = Var.alloc("s");
    Node q = NodeFactory.createURI("urn:q");
    Node v = NodeFactory.createURI("urn:v");
    Var x = Var.alloc("x");
    Node n123 = NodeFactory.createLiteral(LiteralLabelFactory.createTypedLiteral(123));
    pattern.addWhere(new TriplePath(new Triple(s, q, n123)));
    pattern.addWhere(new TriplePath(new Triple(s, v, x)));
    pattern.addFilter("?x>56");
    handler.addOptional(pattern);
    Query expected = QueryFactory.create("SELECT * WHERE { OPTIONAL { ?s <urn:q> '123'^^<http://www.w3.org/2001/XMLSchema#int> . ?s <urn:v> ?x . FILTER(?x>56) }}");
    Assert.assertEquals(expected.getQueryPattern(), query.getQueryPattern());
}
Also used : Triple(org.apache.jena.graph.Triple) Query(org.apache.jena.query.Query) WhereHandler(org.apache.jena.arq.querybuilder.handlers.WhereHandler) Var(org.apache.jena.sparql.core.Var) Node(org.apache.jena.graph.Node) TriplePath(org.apache.jena.sparql.core.TriplePath) Test(org.junit.Test)

Aggregations

WhereHandler (org.apache.jena.arq.querybuilder.handlers.WhereHandler)7 Query (org.apache.jena.query.Query)7 Test (org.junit.Test)6 Triple (org.apache.jena.graph.Triple)4 TriplePath (org.apache.jena.sparql.core.TriplePath)4 Node (org.apache.jena.graph.Node)1 Var (org.apache.jena.sparql.core.Var)1 Before (org.junit.Before)1