01: /*
02: * Copyright Aduna (http://www.aduna-software.com/) (c) 1997-2006.
03: *
04: * Licensed under the Aduna BSD-style license.
05: */
06: package org.openrdf.query.parser.sparql;
07:
08: import java.net.URL;
09:
10: import junit.framework.TestCase;
11: import junit.framework.TestSuite;
12:
13: import org.slf4j.Logger;
14: import org.slf4j.LoggerFactory;
15:
16: import org.openrdf.query.BindingSet;
17: import org.openrdf.query.QueryLanguage;
18: import org.openrdf.query.TupleQueryResult;
19: import org.openrdf.repository.Repository;
20: import org.openrdf.repository.RepositoryConnection;
21: import org.openrdf.repository.sail.SailRepository;
22: import org.openrdf.rio.RDFFormat;
23: import org.openrdf.sail.memory.MemoryStore;
24:
25: public class ManifestTest extends TestCase {
26:
27: static final Logger logger = LoggerFactory
28: .getLogger(ManifestTest.class);
29:
30: private static final boolean REMOTE = false;
31:
32: public static final String MANIFEST_FILE;
33:
34: static {
35: if (REMOTE) {
36: MANIFEST_FILE = "http://www.w3.org/2001/sw/DataAccess/tests/data-r2/manifest-evaluation.ttl";
37: } else {
38: MANIFEST_FILE = ManifestTest.class.getResource(
39: "/testcases-dawg/data-r2/manifest-evaluation.ttl")
40: .toString();
41: }
42: }
43:
44: public ManifestTest(String name) {
45: super (name);
46: }
47:
48: public static TestSuite suite() throws Exception {
49: return suite(new SPARQLQueryTest.Factory());
50: }
51:
52: public static TestSuite suite(SPARQLQueryTest.Factory factory)
53: throws Exception {
54: TestSuite suite = new TestSuite();
55:
56: Repository manifestRep = new SailRepository(new MemoryStore());
57: manifestRep.initialize();
58: RepositoryConnection con = manifestRep.getConnection();
59:
60: con
61: .add(new URL(MANIFEST_FILE), MANIFEST_FILE,
62: RDFFormat.TURTLE);
63:
64: String query = "SELECT DISTINCT manifestFile "
65: + "FROM {x} rdf:first {manifestFile} "
66: + "USING NAMESPACE "
67: + " mf = <http://www.w3.org/2001/sw/DataAccess/tests/test-manifest#>, "
68: + " qt = <http://www.w3.org/2001/sw/DataAccess/tests/test-query#>";
69:
70: TupleQueryResult manifestResults = con.prepareTupleQuery(
71: QueryLanguage.SERQL, query, MANIFEST_FILE).evaluate();
72:
73: while (manifestResults.hasNext()) {
74: BindingSet bindingSet = manifestResults.next();
75: String manifestFile = bindingSet.getValue("manifestFile")
76: .toString();
77: suite.addTest(SPARQLQueryTest.suite(manifestFile, factory));
78: }
79:
80: manifestResults.close();
81: con.close();
82: manifestRep.shutDown();
83:
84: logger.info("Created aggregated test suite with "
85: + suite.countTestCases() + " test cases.");
86: return suite;
87: }
88: }
|