|
17 | 17 | import org.eclipse.rdf4j.sparqlbuilder.core.SparqlBuilder; |
18 | 18 | import org.eclipse.rdf4j.sparqlbuilder.core.Variable; |
19 | 19 | import org.eclipse.rdf4j.sparqlbuilder.examples.BaseExamples; |
| 20 | +import org.eclipse.rdf4j.sparqlbuilder.graphpattern.GraphPatternNotTriples; |
20 | 21 | import org.eclipse.rdf4j.sparqlbuilder.graphpattern.GraphPatterns; |
21 | 22 | import org.eclipse.rdf4j.sparqlbuilder.graphpattern.TriplePattern; |
22 | 23 | import org.eclipse.rdf4j.sparqlbuilder.rdf.Iri; |
@@ -53,4 +54,68 @@ public void example_issue_1481() { |
53 | 54 | "WHERE { OPTIONAL { ?subject ?predicate <http://my-example.com/anyIRI/> . }\n" + |
54 | 55 | "OPTIONAL { ?subject <http://my-example.com/anyIRI/> ?object . } }"); |
55 | 56 | } |
| 57 | + |
| 58 | + @Test |
| 59 | + public void example_broken_filter_not_exists() { |
| 60 | + // given |
| 61 | + Iri subjectIri = iri("http://my-example.com/anyIRI/"); |
| 62 | + Iri classIri = iri("http://my-example.com/SomeClass/"); |
| 63 | + TriplePattern triple = subjectIri.isA(classIri); |
| 64 | + |
| 65 | + String queryString = Queries.MODIFY() |
| 66 | + .insert(triple) |
| 67 | + .where(GraphPatterns.filterNotExists(triple)) |
| 68 | + .getQueryString(); |
| 69 | + |
| 70 | + assertEquals("INSERT { <http://my-example.com/anyIRI/> a <http://my-example.com/SomeClass/> . }\n" + |
| 71 | + // the WHERE clause is incorrectly generated: |
| 72 | + // "WHERE { <http://my-example.com/anyIRI/> a <http://my-example.com/SomeClass/> . }", |
| 73 | + // should be: |
| 74 | + "WHERE { FILTER NOT EXISTS { <http://my-example.com/anyIRI/> a <http://my-example.com/SomeClass/> . } }", |
| 75 | + queryString |
| 76 | + ); |
| 77 | + } |
| 78 | + |
| 79 | + @Test |
| 80 | + public void test_GraphPatternNotTriples_getQueryString() { |
| 81 | + // given |
| 82 | + Iri subjectIri = iri("http://my-example.com/anyIRI/"); |
| 83 | + Iri classIri = iri("http://my-example.com/SomeClass/"); |
| 84 | + TriplePattern triple = subjectIri.isA(classIri); |
| 85 | + |
| 86 | + String queryString = GraphPatterns.filterNotExists(triple).getQueryString(); |
| 87 | + |
| 88 | + assertEquals( |
| 89 | + "FILTER NOT EXISTS { <http://my-example.com/anyIRI/> a <http://my-example.com/SomeClass/> . }", |
| 90 | + queryString |
| 91 | + ); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void test_GraphPatterns_and_getQueryString() { |
| 96 | + GraphPatternNotTriples actual = GraphPatterns.and(); |
| 97 | + assertEquals("{}", actual.getQueryString()); |
| 98 | + } |
| 99 | + |
| 100 | + @Test |
| 101 | + public void test_GraphPatterns_and_FilterExistsGraphPattern_getQueryString() { |
| 102 | + |
| 103 | + TriplePattern triple = iri("http://my-example.com/anyIRI/").isA(iri("http://my-example.com/SomeClass/")); |
| 104 | + |
| 105 | + // emptyGraphPattern by itself yields "{}", see test_GraphPatterns_and_getQueryString |
| 106 | + GraphPatternNotTriples emptyGraphPattern = GraphPatterns.and(); |
| 107 | + |
| 108 | + // filterNotExists by itself yields "FILTER NOT EXISTS { ... }", see test_GraphPatternNotTriples_getQueryString |
| 109 | + GraphPatternNotTriples filterNotExists = GraphPatterns.filterNotExists(triple); |
| 110 | + |
| 111 | + // this is the cause oft the failing example_broken_filter_not_exists test |
| 112 | + GraphPatternNotTriples withFilterNotExists = emptyGraphPattern.and(filterNotExists); |
| 113 | + |
| 114 | + String actual = withFilterNotExists.getQueryString(); |
| 115 | + |
| 116 | + assertEquals( |
| 117 | + "{ FILTER NOT EXISTS { <http://my-example.com/anyIRI/> a <http://my-example.com/SomeClass/> . } }", |
| 118 | + actual |
| 119 | + ); |
| 120 | + } |
56 | 121 | } |
0 commit comments