Skip to content

Commit 3d6cac9

Browse files
committed
Add unit test for issue #771
Signed-off-by:Jacek Grzebyta <grzebyta.dev@gmail.com>
1 parent 47aabd6 commit 3d6cac9

2 files changed

Lines changed: 59 additions & 8 deletions

File tree

testsuites/lucene/src/main/java/org/eclipse/rdf4j/sail/lucene/AbstractLuceneSailSpinTest.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -262,22 +262,20 @@ public void test235Issue()
262262

263263
@Test
264264
public void testDistanceFunction()
265-
throws Exception
265+
throws Exception
266266
{
267267
String queryStr = "prefix geo: <" + GEO.NAMESPACE + ">" + "prefix geof: <" + GEOF.NAMESPACE + ">"
268268
+ "prefix search: <" + LuceneSailSchema.NAMESPACE + ">"
269269
+ "select ?toUri ?fromUri ?dist where {(?from ?range ?units geo:asWKT search:distance)"
270270
+ "search:withinDistance (?toUri ?to ?dist) ."
271271
+ "?toUri a <urn:geo/Landmark>. ?fromUri geo:asWKT ?from; <urn:geo/maxDistance> ?range.}";
272-
try
273-
{
272+
try {
274273
connection.begin();
275274
TupleQuery query = connection.prepareTupleQuery(QueryLanguage.SPARQL, queryStr);
276275
query.setBinding("units", GEOF.UOM_METRE);
277-
276+
278277
printTupleResult(query);
279-
try(TupleQueryResult result = query.evaluate())
280-
{
278+
try (TupleQueryResult result = query.evaluate()) {
281279
int count = countTupleResults(result);
282280
Assert.assertThat(count, is(2));
283281
}
@@ -291,6 +289,42 @@ public void testDistanceFunction()
291289
}
292290
}
293291

292+
/**
293+
* Complex query: <code>
294+
*
295+
* </code>
296+
*
297+
* @throws Exception
298+
*/
299+
@Test
300+
public void complexQuery()
301+
throws Exception
302+
{
303+
StringBuilder sb = new StringBuilder();
304+
sb.append("prefix t: <urn:test.org/onto#> \n");
305+
sb.append("prefix kw: <urn:test.org/key-words/> \n\n");
306+
sb.append("select ?term_string ?sub ?score where { \n");
307+
sb.append(" ?pred_map rdfs:label \"keyWord\" ; \n");
308+
sb.append(" t:column ?pred . \n");
309+
sb.append(" [] ?pred ?term . \n");
310+
sb.append(" bind(str(?term) as ?term_string) . \n");
311+
sb.append(
312+
" (?term_string <" + ALL_MATCHES + "> <" + SCORE + ">) <" + SEARCH + "> (?sub ?score) . \n");
313+
sb.append(" ?sub a t:Data .");
314+
sb.append("}");
315+
316+
log.debug("SPARQL query:\n=======\n{}\n=======\n", sb.toString());
317+
318+
TupleQuery query = connection.prepareTupleQuery(sb.toString());
319+
try {
320+
printTupleResult(query);
321+
}
322+
catch (Exception e) {
323+
e.printStackTrace();
324+
throw new RuntimeException(e);
325+
}
326+
}
327+
294328
public int countStatements(RepositoryConnection con)
295329
throws Exception
296330
{
@@ -317,7 +351,9 @@ protected void printGraphResult(GraphQuery query) {
317351
log.info("\n=============\n" + new String(resultoutput.toByteArray()) + "\n=============");
318352
}
319353

320-
protected void printTupleResult(TupleQuery query) {
354+
protected void printTupleResult(TupleQuery query)
355+
throws Exception
356+
{
321357
ByteArrayOutputStream resultoutput = new ByteArrayOutputStream();
322358
query.evaluate(new SPARQLResultsCSVWriter(resultoutput));
323359
log.info("tuple result:");

testsuites/lucene/src/main/resources/org/eclipse/rdf4j/sail/220-example.ttl

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
@prefix rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> .
22
@prefix rdfs: <http://www.w3.org/2000/01/rdf-schema#> .
33
@prefix geo: <http://www.opengis.net/ont/geosparql#> .
4-
4+
@prefix xsd: <http://www.w3.org/2001/XMLSchema#> .
5+
56
@prefix t: <urn:test.org/onto#> .
7+
@prefix kw: <urn:test.org/key-words/> .
8+
@prefix kw-data: <urn:test.org/key-words/data/> .
9+
10+
11+
12+
<urn:test.org/mock-data/predicate16> rdfs:label "keyWord" ;
13+
t:column kw:keyWord .
14+
15+
kw-data:data1 kw:keyWord "Donec"^^xsd:string .
16+
kw-data:data2 kw:keyWord "viverra"^^xsd:string .
17+
kw-data:data3 kw:keyWord "ornare"^^xsd:string .
18+
19+
20+
621

722

823

0 commit comments

Comments
 (0)