TestSuite suite = new TestSuite(factory.getClass().getName());
// Read manifest and create declared test cases
Repository manifestRep = new SailRepository(new MemoryStore());
manifestRep.initialize();
RepositoryConnection con = manifestRep.getConnection();
ManifestTest.addTurtle(con, new URL(manifestFileURL), manifestFileURL);
suite.setName(getManifestName(manifestRep, con, manifestFileURL));
// Extract test case information from the manifest file. Note that we only
// select those test cases that are mentioned in the list.
StringBuilder query = new StringBuilder(512);
query.append(" SELECT DISTINCT testURI, testName, resultFile, action, queryFile, defaultGraph ");
query.append(" FROM {} rdf:first {testURI} dawgt:approval {dawgt:Approved}; ");
query.append(" mf:name {testName}; ");
query.append(" mf:result {resultFile}; ");
query.append(" mf:action {action} qt:query {queryFile}; ");
query.append(" [qt:data {defaultGraph}] ");
query.append(" USING NAMESPACE ");
query.append(" mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, ");
query.append(" dawgt = <http://www.w3.org/2001/sw/DataAccess/tests/test-dawg#>, ");
query.append(" qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>");
TupleQuery testCaseQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());
query.setLength(0);
query.append(" SELECT graph ");
query.append(" FROM {action} qt:graphData {graph} ");
query.append(" USING NAMESPACE ");
query.append(" qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>");
TupleQuery namedGraphsQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());
query.setLength(0);
query.append("SELECT 1 ");
query.append(" FROM {testURI} mf:resultCardinality {mf:LaxCardinality}");
query.append(" USING NAMESPACE mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>");
TupleQuery laxCardinalityQuery = con.prepareTupleQuery(QueryLanguage.SERQL, query.toString());
logger.debug("evaluating query..");
TupleResult testCases = testCaseQuery.evaluate();
while (testCases.hasNext()) {
BindingSet bindingSet = testCases.next();
URI testURI = (URI)bindingSet.getValue("testURI");
String testName = bindingSet.getValue("testName").toString();
String resultFile = bindingSet.getValue("resultFile").toString();
String queryFile = bindingSet.getValue("queryFile").toString();
URI defaultGraphURI = (URI)bindingSet.getValue("defaultGraph");
Value action = bindingSet.getValue("action");
logger.debug("found test case : {}", testName);
// Query named graphs
namedGraphsQuery.setBinding("action", action);
TupleResult namedGraphs = namedGraphsQuery.evaluate();
DatasetImpl dataset = null;
if (defaultGraphURI != null || namedGraphs.hasNext()) {
dataset = new DatasetImpl();
if (defaultGraphURI != null) {
dataset.addDefaultGraph(defaultGraphURI);
}
while (namedGraphs.hasNext()) {
BindingSet graphBindings = namedGraphs.next();
URI namedGraphURI = (URI)graphBindings.getValue("graph");
dataset.addNamedGraph(namedGraphURI);
}
}
// Check for lax-cardinality conditions
boolean laxCardinality = false;
laxCardinalityQuery.setBinding("testURI", testURI);
TupleResult laxCardinalityResult = laxCardinalityQuery.evaluate();
try {
laxCardinality = laxCardinalityResult.hasNext();
}
finally {
laxCardinalityResult.close();
}
SPARQLQueryTest test = factory.createSPARQLQueryTest(testURI.toString(), testName, queryFile,
resultFile, dataset, laxCardinality);
if (test != null) {
suite.addTest(test);
}
}
testCases.close();
con.close();
manifestRep.shutDown();
logger.info("Created test suite with " + suite.countTestCases() + " test cases.");
return suite;
}