-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ issue #10 ] first set of SPARQL integration tests from #learningSPARQL
- Loading branch information
agazzarini
committed
Oct 23, 2014
1 parent
fe4882b
commit cd527fb
Showing
364 changed files
with
8,884 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
218 changes: 218 additions & 0 deletions
218
...ts/src/test/java/org/gazzax/labs/jena/nosql/fwk/learningSPARQL/LearningSparql_ITCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,218 @@ | ||
/* | ||
* This Test case makes use of some examples from | ||
* | ||
* "Learning SPARQL - Querying and Updating with SPARQL 1.1" by Bob DuCharme | ||
* | ||
* Publisher: O'Reilly | ||
* Author: Bob DuCharme | ||
* ISBN: 978-1-449-37143-2 | ||
* http://www.learningsparql.com/ | ||
* http://shop.oreilly.com/product/0636920030829.do | ||
* | ||
* We warmly appreciate and thank the author and O'Reilly for such permission. | ||
* | ||
*/ | ||
package org.gazzax.labs.jena.nosql.fwk.learningSPARQL; | ||
|
||
import static org.gazzax.labs.jena.nosql.fwk.TestUtility.DUMMY_BASE_URI; | ||
import static org.gazzax.labs.jena.nosql.fwk.TestUtility.eheh; | ||
import static org.gazzax.labs.jena.nosql.fwk.learningSPARQL.MisteryGuest.misteryGuest; | ||
import static org.junit.Assert.assertFalse; | ||
import static org.junit.Assert.assertTrue; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.net.URI; | ||
import java.nio.file.Files; | ||
import java.nio.file.Paths; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.gazzax.labs.jena.nosql.fwk.factory.StorageLayerFactory; | ||
import org.gazzax.labs.jena.nosql.fwk.log.Log; | ||
import org.junit.After; | ||
import org.junit.Before; | ||
import org.junit.BeforeClass; | ||
import org.junit.Test; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.hp.hpl.jena.query.Dataset; | ||
import com.hp.hpl.jena.query.DatasetFactory; | ||
import com.hp.hpl.jena.query.Query; | ||
import com.hp.hpl.jena.query.QueryExecution; | ||
import com.hp.hpl.jena.query.QueryExecutionFactory; | ||
import com.hp.hpl.jena.query.QueryFactory; | ||
import com.hp.hpl.jena.query.ResultSetFormatter; | ||
import com.hp.hpl.jena.rdf.model.Model; | ||
import com.hp.hpl.jena.sparql.resultset.ResultSetCompare; | ||
|
||
/** | ||
* SPARQL integration test. | ||
* | ||
* @author Andrea Gazzarini | ||
* @since 1.0 | ||
*/ | ||
public class LearningSparql_ITCase { | ||
protected final String examplesDir = "src/test/resources/LearningSPARQLExamples"; | ||
|
||
protected final Log log = new Log(LoggerFactory.getLogger(LearningSparql_ITCase.class)); | ||
|
||
protected Dataset dataset; | ||
protected Dataset memoryDataset; | ||
|
||
protected StorageLayerFactory factory; | ||
|
||
static final List<MisteryGuest> DATA = new ArrayList<MisteryGuest>(); | ||
|
||
/** | ||
* Fills the data and queries map. | ||
*/ | ||
@BeforeClass | ||
public static void init() { | ||
DATA.add(misteryGuest("ex003.rq", "ex002.ttl")); | ||
DATA.add(misteryGuest("ex006.rq", "ex002.ttl")); | ||
DATA.add(misteryGuest("ex007.rq", "ex002.ttl")); | ||
DATA.add(misteryGuest("ex008.rq", "ex002.ttl")); | ||
DATA.add(misteryGuest("ex010.rq", "ex002.ttl")); | ||
|
||
DATA.add(misteryGuest("ex013.rq", "ex012.ttl")); | ||
DATA.add(misteryGuest("ex015.rq", "ex012.ttl")); | ||
DATA.add(misteryGuest("ex017.rq", "ex012.ttl")); | ||
DATA.add(misteryGuest("ex019.rq", "ex012.ttl")); | ||
DATA.add(misteryGuest("ex021.rq", "ex012.ttl")); | ||
DATA.add(misteryGuest("ex047.rq", "ex012.ttl")); | ||
DATA.add(misteryGuest("ex052.rq", "ex050.ttl", "foaf.rdf")); | ||
DATA.add(misteryGuest("ex055.rq", "", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex057.rq", "", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex059.rq", "", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex061.rq", "", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex063.rq", "", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex065.rq", "!BOUND", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex067.rq", "FILTER NOT EXISTS", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex068.rq", "MINUS", "ex054.ttl")); | ||
DATA.add(misteryGuest("ex070.rq", "Multiple tables", "ex069.ttl")); | ||
DATA.add(misteryGuest("ex070.rq", "Multiple tables with split datasets", "ex072.ttl", "ex073.ttl", "ex368.ttl")); | ||
DATA.add(misteryGuest("ex075.rq", "Bind either", "ex074.ttl")); | ||
DATA.add(misteryGuest("ex077.rq", "Bind either", "ex074.ttl")); | ||
DATA.add(misteryGuest("ex078.rq", "Property paths", "ex074.ttl")); | ||
DATA.add(misteryGuest("ex080.rq", "Property paths", "ex074.ttl")); | ||
DATA.add(misteryGuest("ex082.rq", "Property paths", "ex074.ttl")); | ||
DATA.add(misteryGuest("ex083.rq", "Property paths", "ex074.ttl")); | ||
DATA.add(misteryGuest("ex084.rq", "Property paths", "ex074.ttl")); | ||
DATA.add(misteryGuest("ex086.rq", "Querying blank nodes", "ex041.ttl")); | ||
DATA.add(misteryGuest("ex088.rq", "Querying blank nodes", "ex041.ttl")); | ||
} | ||
|
||
/** | ||
* Setup fixture for this test. | ||
*/ | ||
@Before | ||
public final void setUp() { | ||
factory = StorageLayerFactory.getFactory(); | ||
dataset = DatasetFactory.create(factory.getDatasetGraph()); | ||
memoryDataset = DatasetFactory.createMem(); | ||
} | ||
|
||
/** | ||
* Shutdown procedure for this test. | ||
*/ | ||
@After | ||
public void tearDown() { | ||
clearDatasets(); | ||
factory.getClientShutdownHook().close(); | ||
} | ||
|
||
@Test | ||
public void select() throws Exception { | ||
for (final MisteryGuest data : DATA) { | ||
log.info("Running " + data.description + " test..."); | ||
|
||
load(data); | ||
|
||
final Query query = QueryFactory.create(queryString(data.query)); | ||
QueryExecution execution = null; | ||
QueryExecution inMemoryExecution = null; | ||
|
||
try { | ||
assertTrue( | ||
data.datasets + ", " + data.query, | ||
ResultSetCompare.isomorphic( | ||
(execution = QueryExecutionFactory.create(query, dataset)).execSelect(), | ||
(inMemoryExecution = QueryExecutionFactory.create(query, memoryDataset)).execSelect())); | ||
|
||
if (log.isDebugEnabled()) { | ||
QueryExecution secondExecution = null; | ||
log.debug("\n" + ResultSetFormatter.asText( | ||
(secondExecution = (QueryExecutionFactory.create(query, dataset))).execSelect())); | ||
|
||
secondExecution.close(); | ||
} | ||
|
||
} finally { | ||
clearDatasets(); | ||
execution.close(); | ||
inMemoryExecution.close(); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Reads a query from the file associated with this test and builds a query string. | ||
* | ||
* @param filename the filename. | ||
* @return the query string associated with this test. | ||
* @throws IOException in case of I/O failure while reading the file. | ||
*/ | ||
protected String queryString(final String filename) throws IOException { | ||
return readFile(filename); | ||
} | ||
|
||
/** | ||
* Builds a string from a given file. | ||
* | ||
* @param filename the filename (without path). | ||
* @return a string with the file content. | ||
* @throws IOException in case of I/O failure while reading the file. | ||
*/ | ||
protected String readFile(final String filename) throws IOException { | ||
return new String(Files.readAllBytes(Paths.get(source(filename)))); | ||
} | ||
|
||
/** | ||
* Loads all triples found in the datafile associated with the given name. | ||
* | ||
* @param datafileName the name of the datafile. | ||
*/ | ||
protected void load(final MisteryGuest data) { | ||
final Model model = dataset.getDefaultModel(); | ||
final Model memoryModel = memoryDataset.getDefaultModel(); | ||
|
||
for (final String datafileName : data.datasets) { | ||
final String dataURL = source(datafileName).toString(); | ||
final String lang = datafileName.endsWith("ttl") ? "TTL" : null; | ||
model.read(dataURL, DUMMY_BASE_URI, lang); | ||
memoryModel.read(dataURL, DUMMY_BASE_URI, lang); | ||
} | ||
|
||
eheh(); | ||
|
||
assertFalse(data.datasets + ", " + data.query, model.isEmpty()); | ||
assertTrue(data.datasets + ", " + data.query, model.isIsomorphicWith(memoryModel)); | ||
} | ||
|
||
/** | ||
* Returns the URI of a given filename. | ||
* | ||
* @param filename the filename. | ||
* @return the URI (as string) of a given filename. | ||
*/ | ||
URI source(final String filename) { | ||
return new File(examplesDir, filename).toURI(); | ||
} | ||
|
||
void clearDatasets() { | ||
dataset.getDefaultModel().removeAll(); | ||
memoryDataset.getDefaultModel().removeAll(); | ||
eheh(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
...ation-tests/src/test/java/org/gazzax/labs/jena/nosql/fwk/learningSPARQL/MisteryGuest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.gazzax.labs.jena.nosql.fwk.learningSPARQL; | ||
|
||
/** | ||
* A simple value object encapsulating data (i.e. filenames) for a given test. | ||
* | ||
* @author Andrea Gazzarini | ||
* @since 1.0 | ||
*/ | ||
class MisteryGuest { | ||
final String [] datasets; | ||
final String query; | ||
final String description; | ||
|
||
/** | ||
* Builds a new test bundle with the given data. | ||
* | ||
* @param datasetsFilenames one or more datafile that contains data. | ||
* @param description a brief description about the data / query. | ||
* @param queryFilename the name of the file containing the SPARQL query for a given test. | ||
*/ | ||
private MisteryGuest(final String queryFilename, final String description, final String ... datasetsFilenames) { | ||
this.datasets = datasetsFilenames; | ||
this.description = description; | ||
this.query = queryFilename; | ||
} | ||
|
||
/** | ||
* Factory method. | ||
* | ||
* @param datasetsFilenames one or more datafile that contains data. | ||
* @param description a brief description about the data / query. | ||
* @param queryFilename the name of the file containing the SPARQL query for a given test. | ||
* @return new {@link MisteryGuest} instance. | ||
*/ | ||
static MisteryGuest misteryGuest(final String queryFilename, final String description, final String ... datasetsFilenames) { | ||
return new MisteryGuest(queryFilename, description, datasetsFilenames); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/README
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
All files in this directory are examples from | ||
|
||
"Learning SPARQL - Querying and Updating with SPARQL 1.1" by Bob DuCharme | ||
|
||
Publisher: O'Reilly | ||
Author: Bob DuCharme | ||
ISBN: 978-1-449-37143-2 | ||
http://www.learningsparql.com/ | ||
http://shop.oreilly.com/product/0636920030829.do | ||
|
||
We warmly appreciate and thank the author and O'Reilly for such permission. |
6 changes: 6 additions & 0 deletions
6
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/ex001.rq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# filename: ex001.rq | ||
|
||
PREFIX d: <http://learningsparql.com/ns/demo#> | ||
SELECT ?person | ||
WHERE | ||
{ ?person d:homeTel "(229) 276-5135" . } |
13 changes: 13 additions & 0 deletions
13
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/ex002.ttl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# filename: ex002.ttl | ||
|
||
@prefix ab: <http://learningsparql.com/ns/addressbook#> . | ||
|
||
ab:richard ab:homeTel "(229) 276-5135" . | ||
ab:richard ab:email "[email protected]" . | ||
|
||
ab:cindy ab:homeTel "(245) 646-5488" . | ||
ab:cindy ab:email "[email protected]" . | ||
|
||
ab:craig ab:homeTel "(194) 966-1505" . | ||
ab:craig ab:email "[email protected]" . | ||
ab:craig ab:email "[email protected]" . |
7 changes: 7 additions & 0 deletions
7
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/ex003.rq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# filename: ex003.rq | ||
|
||
PREFIX ab: <http://learningsparql.com/ns/addressbook#> | ||
|
||
SELECT ?craigEmail | ||
WHERE | ||
{ ab:craig ab:email ?craigEmail . } |
9 changes: 9 additions & 0 deletions
9
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/ex006.rq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# filename: ex006.rq | ||
|
||
SELECT ?craigEmail | ||
WHERE | ||
{ | ||
<http://learningsparql.com/ns/addressbook#craig> | ||
<http://learningsparql.com/ns/addressbook#email> | ||
?craigEmail . | ||
} |
7 changes: 7 additions & 0 deletions
7
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/ex007.rq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# filename: ex007.rq | ||
|
||
PREFIX ab: <http://learningsparql.com/ns/addressbook#> | ||
|
||
SELECT ?craigEmail FROM <ex002.ttl> | ||
WHERE | ||
{ ab:craig ab:email ?craigEmail . } |
7 changes: 7 additions & 0 deletions
7
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/ex008.rq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# filename: ex008.rq | ||
|
||
PREFIX ab: <http://learningsparql.com/ns/addressbook#> | ||
|
||
SELECT ?person | ||
WHERE | ||
{ ?person ab:homeTel "(229) 276-5135" . } |
7 changes: 7 additions & 0 deletions
7
jena-nosql-integration-tests/src/test/resources/LearningSPARQLExamples/ex010.rq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# filename: ex010.rq | ||
|
||
PREFIX ab: <http://learningsparql.com/ns/addressbook#> | ||
|
||
SELECT ?propertyName ?propertyValue | ||
WHERE | ||
{ ab:cindy ?propertyName ?propertyValue . } |
Oops, something went wrong.