Skip to content

Commit cd527fb

Browse files
author
agazzarini
committed
[ issue #10 ] first set of SPARQL integration tests from #learningSPARQL
1 parent fe4882b commit cd527fb

File tree

364 files changed

+8884
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

364 files changed

+8884
-25
lines changed

jena-nosql-binding/jena-nosql-binding-solr/src/main/java/org/gazzax/labs/jena/nosql/solr/dao/SolrDeepPagingIterator.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ public boolean hasNext() {
7070
if (iterator().hasNext()) {
7171
return true;
7272
} else {
73+
iterator = null;
7374
currentState = checkForConsumptionCompleteness;
7475
return currentState.hasNext();
7576
}

jena-nosql-integration-tests/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,11 @@
163163
<artifactId>jena-nosql-framework</artifactId>
164164
<version>1.0</version>
165165
</dependency>
166+
<dependency>
167+
<groupId>org.gazzax.labs</groupId>
168+
<artifactId>jena-nosql-binding-solr</artifactId>
169+
<version>1.0</version>
170+
</dependency>
166171
</dependencies>
167172
<name>Jena NoSQL Integration Tests</name>
168173
</project>

jena-nosql-integration-tests/src/test/java/org/gazzax/labs/jena/nosql/fwk/SparqlIntegrationTestCase.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package org.gazzax.labs.jena.nosql.fwk;
22

33
import static org.gazzax.labs.jena.nosql.fwk.TestUtility.DUMMY_BASE_URI;
4-
import static org.gazzax.labs.jena.nosql.fwk.TestUtility.waitForOneSecond;
4+
import static org.gazzax.labs.jena.nosql.fwk.TestUtility.eheh;
55
import static org.junit.Assert.assertFalse;
66
import static org.junit.Assert.assertTrue;
77

@@ -45,7 +45,7 @@ public final void setUp() {
4545

4646
load("data.ttl");
4747
}
48-
48+
4949
/**
5050
* Returns the chapter the test refers to (e.g. 2.1, 2.2, 3.2).
5151
*
@@ -128,7 +128,7 @@ protected void load(final String datafileName) {
128128
final Model model = dataset.getDefaultModel().read(dataURL, DUMMY_BASE_URI, "TTL");
129129
final Model memoryModel = memoryDataset.getDefaultModel().read(dataURL, DUMMY_BASE_URI, "TTL");
130130

131-
waitForOneSecond();
131+
eheh();
132132

133133
assertFalse(model.isEmpty());
134134
assertTrue(model.isIsomorphicWith(memoryModel));

jena-nosql-integration-tests/src/test/java/org/gazzax/labs/jena/nosql/fwk/TestUtility.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class TestUtility {
1212
/**
1313
* Waits for a second.
1414
*/
15-
public static void waitForOneSecond() {
15+
public static void eheh() {
1616
try {
1717
Thread.sleep(1000);
1818
} catch (final Exception ignore) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,218 @@
1+
/*
2+
* This Test case makes use of some examples from
3+
*
4+
* "Learning SPARQL - Querying and Updating with SPARQL 1.1" by Bob DuCharme
5+
*
6+
* Publisher: O'Reilly
7+
* Author: Bob DuCharme
8+
* ISBN: 978-1-449-37143-2
9+
* http://www.learningsparql.com/
10+
* http://shop.oreilly.com/product/0636920030829.do
11+
*
12+
* We warmly appreciate and thank the author and O'Reilly for such permission.
13+
*
14+
*/
15+
package org.gazzax.labs.jena.nosql.fwk.learningSPARQL;
16+
17+
import static org.gazzax.labs.jena.nosql.fwk.TestUtility.DUMMY_BASE_URI;
18+
import static org.gazzax.labs.jena.nosql.fwk.TestUtility.eheh;
19+
import static org.gazzax.labs.jena.nosql.fwk.learningSPARQL.MisteryGuest.misteryGuest;
20+
import static org.junit.Assert.assertFalse;
21+
import static org.junit.Assert.assertTrue;
22+
23+
import java.io.File;
24+
import java.io.IOException;
25+
import java.net.URI;
26+
import java.nio.file.Files;
27+
import java.nio.file.Paths;
28+
import java.util.ArrayList;
29+
import java.util.List;
30+
31+
import org.gazzax.labs.jena.nosql.fwk.factory.StorageLayerFactory;
32+
import org.gazzax.labs.jena.nosql.fwk.log.Log;
33+
import org.junit.After;
34+
import org.junit.Before;
35+
import org.junit.BeforeClass;
36+
import org.junit.Test;
37+
import org.slf4j.LoggerFactory;
38+
39+
import com.hp.hpl.jena.query.Dataset;
40+
import com.hp.hpl.jena.query.DatasetFactory;
41+
import com.hp.hpl.jena.query.Query;
42+
import com.hp.hpl.jena.query.QueryExecution;
43+
import com.hp.hpl.jena.query.QueryExecutionFactory;
44+
import com.hp.hpl.jena.query.QueryFactory;
45+
import com.hp.hpl.jena.query.ResultSetFormatter;
46+
import com.hp.hpl.jena.rdf.model.Model;
47+
import com.hp.hpl.jena.sparql.resultset.ResultSetCompare;
48+
49+
/**
50+
* SPARQL integration test.
51+
*
52+
* @author Andrea Gazzarini
53+
* @since 1.0
54+
*/
55+
public class LearningSparql_ITCase {
56+
protected final String examplesDir = "src/test/resources/LearningSPARQLExamples";
57+
58+
protected final Log log = new Log(LoggerFactory.getLogger(LearningSparql_ITCase.class));
59+
60+
protected Dataset dataset;
61+
protected Dataset memoryDataset;
62+
63+
protected StorageLayerFactory factory;
64+
65+
static final List<MisteryGuest> DATA = new ArrayList<MisteryGuest>();
66+
67+
/**
68+
* Fills the data and queries map.
69+
*/
70+
@BeforeClass
71+
public static void init() {
72+
DATA.add(misteryGuest("ex003.rq", "ex002.ttl"));
73+
DATA.add(misteryGuest("ex006.rq", "ex002.ttl"));
74+
DATA.add(misteryGuest("ex007.rq", "ex002.ttl"));
75+
DATA.add(misteryGuest("ex008.rq", "ex002.ttl"));
76+
DATA.add(misteryGuest("ex010.rq", "ex002.ttl"));
77+
78+
DATA.add(misteryGuest("ex013.rq", "ex012.ttl"));
79+
DATA.add(misteryGuest("ex015.rq", "ex012.ttl"));
80+
DATA.add(misteryGuest("ex017.rq", "ex012.ttl"));
81+
DATA.add(misteryGuest("ex019.rq", "ex012.ttl"));
82+
DATA.add(misteryGuest("ex021.rq", "ex012.ttl"));
83+
DATA.add(misteryGuest("ex047.rq", "ex012.ttl"));
84+
DATA.add(misteryGuest("ex052.rq", "ex050.ttl", "foaf.rdf"));
85+
DATA.add(misteryGuest("ex055.rq", "", "ex054.ttl"));
86+
DATA.add(misteryGuest("ex057.rq", "", "ex054.ttl"));
87+
DATA.add(misteryGuest("ex059.rq", "", "ex054.ttl"));
88+
DATA.add(misteryGuest("ex061.rq", "", "ex054.ttl"));
89+
DATA.add(misteryGuest("ex063.rq", "", "ex054.ttl"));
90+
DATA.add(misteryGuest("ex065.rq", "!BOUND", "ex054.ttl"));
91+
DATA.add(misteryGuest("ex067.rq", "FILTER NOT EXISTS", "ex054.ttl"));
92+
DATA.add(misteryGuest("ex068.rq", "MINUS", "ex054.ttl"));
93+
DATA.add(misteryGuest("ex070.rq", "Multiple tables", "ex069.ttl"));
94+
DATA.add(misteryGuest("ex070.rq", "Multiple tables with split datasets", "ex072.ttl", "ex073.ttl", "ex368.ttl"));
95+
DATA.add(misteryGuest("ex075.rq", "Bind either", "ex074.ttl"));
96+
DATA.add(misteryGuest("ex077.rq", "Bind either", "ex074.ttl"));
97+
DATA.add(misteryGuest("ex078.rq", "Property paths", "ex074.ttl"));
98+
DATA.add(misteryGuest("ex080.rq", "Property paths", "ex074.ttl"));
99+
DATA.add(misteryGuest("ex082.rq", "Property paths", "ex074.ttl"));
100+
DATA.add(misteryGuest("ex083.rq", "Property paths", "ex074.ttl"));
101+
DATA.add(misteryGuest("ex084.rq", "Property paths", "ex074.ttl"));
102+
DATA.add(misteryGuest("ex086.rq", "Querying blank nodes", "ex041.ttl"));
103+
DATA.add(misteryGuest("ex088.rq", "Querying blank nodes", "ex041.ttl"));
104+
}
105+
106+
/**
107+
* Setup fixture for this test.
108+
*/
109+
@Before
110+
public final void setUp() {
111+
factory = StorageLayerFactory.getFactory();
112+
dataset = DatasetFactory.create(factory.getDatasetGraph());
113+
memoryDataset = DatasetFactory.createMem();
114+
}
115+
116+
/**
117+
* Shutdown procedure for this test.
118+
*/
119+
@After
120+
public void tearDown() {
121+
clearDatasets();
122+
factory.getClientShutdownHook().close();
123+
}
124+
125+
@Test
126+
public void select() throws Exception {
127+
for (final MisteryGuest data : DATA) {
128+
log.info("Running " + data.description + " test...");
129+
130+
load(data);
131+
132+
final Query query = QueryFactory.create(queryString(data.query));
133+
QueryExecution execution = null;
134+
QueryExecution inMemoryExecution = null;
135+
136+
try {
137+
assertTrue(
138+
data.datasets + ", " + data.query,
139+
ResultSetCompare.isomorphic(
140+
(execution = QueryExecutionFactory.create(query, dataset)).execSelect(),
141+
(inMemoryExecution = QueryExecutionFactory.create(query, memoryDataset)).execSelect()));
142+
143+
if (log.isDebugEnabled()) {
144+
QueryExecution secondExecution = null;
145+
log.debug("\n" + ResultSetFormatter.asText(
146+
(secondExecution = (QueryExecutionFactory.create(query, dataset))).execSelect()));
147+
148+
secondExecution.close();
149+
}
150+
151+
} finally {
152+
clearDatasets();
153+
execution.close();
154+
inMemoryExecution.close();
155+
}
156+
}
157+
}
158+
159+
/**
160+
* Reads a query from the file associated with this test and builds a query string.
161+
*
162+
* @param filename the filename.
163+
* @return the query string associated with this test.
164+
* @throws IOException in case of I/O failure while reading the file.
165+
*/
166+
protected String queryString(final String filename) throws IOException {
167+
return readFile(filename);
168+
}
169+
170+
/**
171+
* Builds a string from a given file.
172+
*
173+
* @param filename the filename (without path).
174+
* @return a string with the file content.
175+
* @throws IOException in case of I/O failure while reading the file.
176+
*/
177+
protected String readFile(final String filename) throws IOException {
178+
return new String(Files.readAllBytes(Paths.get(source(filename))));
179+
}
180+
181+
/**
182+
* Loads all triples found in the datafile associated with the given name.
183+
*
184+
* @param datafileName the name of the datafile.
185+
*/
186+
protected void load(final MisteryGuest data) {
187+
final Model model = dataset.getDefaultModel();
188+
final Model memoryModel = memoryDataset.getDefaultModel();
189+
190+
for (final String datafileName : data.datasets) {
191+
final String dataURL = source(datafileName).toString();
192+
final String lang = datafileName.endsWith("ttl") ? "TTL" : null;
193+
model.read(dataURL, DUMMY_BASE_URI, lang);
194+
memoryModel.read(dataURL, DUMMY_BASE_URI, lang);
195+
}
196+
197+
eheh();
198+
199+
assertFalse(data.datasets + ", " + data.query, model.isEmpty());
200+
assertTrue(data.datasets + ", " + data.query, model.isIsomorphicWith(memoryModel));
201+
}
202+
203+
/**
204+
* Returns the URI of a given filename.
205+
*
206+
* @param filename the filename.
207+
* @return the URI (as string) of a given filename.
208+
*/
209+
URI source(final String filename) {
210+
return new File(examplesDir, filename).toURI();
211+
}
212+
213+
void clearDatasets() {
214+
dataset.getDefaultModel().removeAll();
215+
memoryDataset.getDefaultModel().removeAll();
216+
eheh();
217+
}
218+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package org.gazzax.labs.jena.nosql.fwk.learningSPARQL;
2+
3+
/**
4+
* A simple value object encapsulating data (i.e. filenames) for a given test.
5+
*
6+
* @author Andrea Gazzarini
7+
* @since 1.0
8+
*/
9+
class MisteryGuest {
10+
final String [] datasets;
11+
final String query;
12+
final String description;
13+
14+
/**
15+
* Builds a new test bundle with the given data.
16+
*
17+
* @param datasetsFilenames one or more datafile that contains data.
18+
* @param description a brief description about the data / query.
19+
* @param queryFilename the name of the file containing the SPARQL query for a given test.
20+
*/
21+
private MisteryGuest(final String queryFilename, final String description, final String ... datasetsFilenames) {
22+
this.datasets = datasetsFilenames;
23+
this.description = description;
24+
this.query = queryFilename;
25+
}
26+
27+
/**
28+
* Factory method.
29+
*
30+
* @param datasetsFilenames one or more datafile that contains data.
31+
* @param description a brief description about the data / query.
32+
* @param queryFilename the name of the file containing the SPARQL query for a given test.
33+
* @return new {@link MisteryGuest} instance.
34+
*/
35+
static MisteryGuest misteryGuest(final String queryFilename, final String description, final String ... datasetsFilenames) {
36+
return new MisteryGuest(queryFilename, description, datasetsFilenames);
37+
}
38+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
All files in this directory are examples from
2+
3+
"Learning SPARQL - Querying and Updating with SPARQL 1.1" by Bob DuCharme
4+
5+
Publisher: O'Reilly
6+
Author: Bob DuCharme
7+
ISBN: 978-1-449-37143-2
8+
http://www.learningsparql.com/
9+
http://shop.oreilly.com/product/0636920030829.do
10+
11+
We warmly appreciate and thank the author and O'Reilly for such permission.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# filename: ex001.rq
2+
3+
PREFIX d: <http://learningsparql.com/ns/demo#>
4+
SELECT ?person
5+
WHERE
6+
{ ?person d:homeTel "(229) 276-5135" . }
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# filename: ex002.ttl
2+
3+
@prefix ab: <http://learningsparql.com/ns/addressbook#> .
4+
5+
ab:richard ab:homeTel "(229) 276-5135" .
6+
ab:richard ab:email "[email protected]" .
7+
8+
ab:cindy ab:homeTel "(245) 646-5488" .
9+
ab:cindy ab:email "[email protected]" .
10+
11+
ab:craig ab:homeTel "(194) 966-1505" .
12+
ab:craig ab:email "[email protected]" .
13+
ab:craig ab:email "[email protected]" .
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# filename: ex003.rq
2+
3+
PREFIX ab: <http://learningsparql.com/ns/addressbook#>
4+
5+
SELECT ?craigEmail
6+
WHERE
7+
{ ab:craig ab:email ?craigEmail . }

0 commit comments

Comments
 (0)