You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by ja...@apache.org on 2014/04/09 13:04:25 UTC
[22/50] [abbrv] git commit: MARMOTTA-438: ported to junit4 runners
MARMOTTA-438: ported to junit4 runners
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/9150ef74
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/9150ef74
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/9150ef74
Branch: refs/heads/master
Commit: 9150ef744105d61d177f633ffbdd02a4a50c5958
Parents: e36815b
Author: Sergio Fernández <wi...@apache.org>
Authored: Wed Apr 2 17:17:27 2014 +0200
Committer: Sergio Fernández <wi...@apache.org>
Committed: Wed Apr 2 17:17:27 2014 +0200
----------------------------------------------------------------------
.../platform/ldp/testsuite/LdpManifestTest.java | 3 +-
.../platform/ldp/testsuite/LdpTestCase.java | 12 +-
.../ldp/testsuite/LdpTestCaseRunner.java | 61 ++++++++++
.../platform/ldp/testsuite/LdpTestCases.java | 56 ++++++++-
.../ldp/testsuite/LdpTestCasesExecutor.java | 114 -------------------
.../ldp/testsuite/LdpTestCasesRunner.java | 99 ++++++++++++++++
.../ldp/testsuite/LdpTestCasesUtils.java | 46 +++++++-
7 files changed, 263 insertions(+), 128 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/9150ef74/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpManifestTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpManifestTest.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpManifestTest.java
index 50fb767..9d7afbd 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpManifestTest.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpManifestTest.java
@@ -19,6 +19,7 @@ package org.apache.marmotta.platform.ldp.testsuite;
import org.junit.*;
import org.openrdf.model.Statement;
+import org.openrdf.model.vocabulary.RDF;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
@@ -57,7 +58,7 @@ public class LdpManifestTest {
conn.begin();
//ValueFactory vf = conn.getValueFactory();
Assert.assertFalse(conn.isEmpty());
- RepositoryResult<Statement> statements = conn.getStatements(null, null, null, false);
+ RepositoryResult<Statement> statements = conn.getStatements(null, RDF.TYPE, conn.getValueFactory().createURI("http://www.w3.org/2006/03/test-description#", "TestCase"), false);
Assert.assertTrue(statements.hasNext());
statements.close();
//TODO: check test cases are actually there
http://git-wip-us.apache.org/repos/asf/marmotta/blob/9150ef74/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
index 33ec7e9..176494b 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCase.java
@@ -17,18 +17,19 @@
package org.apache.marmotta.platform.ldp.testsuite;
-import junit.framework.TestCase;
import org.openrdf.model.URI;
import java.util.List;
+import static org.junit.Assert.assertEquals;
+
/**
* LDP Test Case
*
* @author Sergio Fernández
* @see <a href="http://www.w3.org/TR/ldp-test-cases/#test-case-description">LDP Tests Cases</a>
*/
-public class LdpTestCase extends TestCase {
+public class LdpTestCase /* extends TestCase */ {
/**
* Test Case Uniform Resource Identifier
@@ -88,7 +89,7 @@ public class LdpTestCase extends TestCase {
private URI testAssertion;
public LdpTestCase(URI uri, String label) {
- super(label);
+ //super(label);
this.uri = uri;
this.label = label;
}
@@ -181,9 +182,4 @@ public class LdpTestCase extends TestCase {
this.testAssertion = testAssertion;
}
- @Override
- protected void runTest() throws Throwable {
- assertEquals(label.substring(3), uri.getLocalName().substring(2));
- }
-
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/9150ef74/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java
new file mode 100644
index 0000000..051952b
--- /dev/null
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCaseRunner.java
@@ -0,0 +1,61 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.platform.ldp.testsuite;
+
+import org.junit.runner.Description;
+import org.junit.runner.Runner;
+import org.junit.runner.notification.RunNotifier;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * LDP Test Case JUnit Runner
+ *
+ * @author Sergio Fernández
+ */
+public class LdpTestCaseRunner extends Runner {
+
+ private LdpTestCase testCase;
+
+ public LdpTestCaseRunner(LdpTestCase testCase) {
+ this.testCase = testCase;
+ }
+
+ @Override
+ public Description getDescription() {
+ return Description.createSuiteDescription(testCase.getLabel());
+ }
+
+ @Override
+ public void run(RunNotifier notifier) {
+ notifier.fireTestRunStarted(getDescription());
+ try {
+ run();
+ } catch (Exception e) {
+ //TODO
+ //notifier.fireTestFailure(e);
+ }
+ notifier.fireTestFinished(getDescription());
+ }
+
+ private void run() {
+ assertEquals(testCase.getLabel().substring(3), testCase.getUri().getLocalName().substring(2));
+ //TODO: actual execution
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/9150ef74/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
index 247c21d..9091c00 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCases.java
@@ -17,11 +17,28 @@
package org.apache.marmotta.platform.ldp.testsuite;
+import com.jayway.restassured.RestAssured;
+import org.apache.commons.io.IOUtils;
+import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
+import org.apache.marmotta.platform.core.test.base.JettyMarmotta;
+import org.apache.marmotta.platform.ldp.webservices.LdpWebService;
+import org.junit.*;
+import org.junit.runner.RunWith;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.ws.rs.core.UriBuilder;
+import java.io.IOException;
+import java.net.URISyntaxException;
+
/**
- * LDP Test Cases metadata (updated on April 2, 2014)
+ * LDP Test Cases
*
* @author Sergio Fernández
+ *
+ * @see <a href="https://dvcs.w3.org/hg/ldpwg/raw-file/default/Test%20Cases/LDP%20Test%20Cases.html">LDP Test Cases</a>
*/
+@RunWith(LdpTestCasesRunner.class)
public class LdpTestCases {
public final static String FILES_PATH = "/testsuite/";
@@ -30,4 +47,41 @@ public class LdpTestCases {
public final static String MANIFEST_CACHE = "LDP-Test-Cases-WD-20140402";
+ private static Logger log = LoggerFactory.getLogger(LdpTestCases.class);
+
+ private static JettyMarmotta marmotta;
+
+ private static String baseUrl;
+
+ private static String testResourceTTL;
+
+ @BeforeClass
+ public static void setup() throws MarmottaImportException, URISyntaxException, IOException {
+ marmotta = new JettyMarmotta("/marmotta", LdpWebService.class);
+ RestAssured.baseURI = "http://localhost";
+ RestAssured.port = marmotta.getPort();
+ RestAssured.basePath = marmotta.getContext();
+ baseUrl = UriBuilder.fromUri("http://localhost").port(marmotta.getPort()).path(marmotta.getContext()).build().toString();
+
+ //initialization
+ testResourceTTL = IOUtils.toString(LdpTestCases.class.getResourceAsStream("/test.ttl"), "utf8");
+ }
+
+ @Before
+ public void before() {
+ log.warn("before");
+ }
+
+ @After
+ public void after() {
+ log.warn("after");
+ }
+
+ @AfterClass
+ public static void shutdown() {
+ //marmotta.shutdown();
+ marmotta = null;
+ testResourceTTL = null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/9150ef74/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesExecutor.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesExecutor.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesExecutor.java
deleted file mode 100644
index 1dd0900..0000000
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesExecutor.java
+++ /dev/null
@@ -1,114 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package org.apache.marmotta.platform.ldp.testsuite;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.junit.runner.RunWith;
-import org.junit.runners.AllTests;
-import org.openrdf.model.URI;
-import org.openrdf.query.*;
-import org.openrdf.repository.Repository;
-import org.openrdf.repository.RepositoryConnection;
-import org.openrdf.repository.RepositoryException;
-import org.openrdf.rio.RDFParseException;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-
-/**
- * LDP Test Cases Executor
- *
- * @author Sergio Fernández
- */
-@RunWith(AllTests.class)
-public final class LdpTestCasesExecutor {
-
- private static Logger log = LoggerFactory.getLogger(LdpTestCasesExecutor.class);
-
- public static TestSuite suite() {
- TestSuite suite = new TestSuite();
- for (Test test : buildTestCasesFromManifest()) {
- suite.addTest(test);
- }
- return suite;
- }
-
- private static Collection<Test> buildTestCasesFromManifest() {
- Collection<Test> tests = new ArrayList<>();
-
- try {
- Repository repo = LdpTestCasesUtils.loadData();
- RepositoryConnection conn = repo.getConnection();
- try {
- conn.begin();
-
- //TODO: this query is not final, it needs to evolve in parallel with the test cases
- String testCasesQuery =
- "PREFIX dc: <http://purl.org/dc/terms/> \n" +
- "PREFIX foaf: <http://xmlns.com/foaf/0.1/> \n" +
- "PREFIX ht: <http://www.w3.org/2011/http#> \n" +
- "PREFIX owl: <http://www.w3.org/2002/07/owl#> \n" +
- "PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#> \n" +
- "PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#> \n" +
- "PREFIX td: <http://www.w3.org/2006/03/test-description#> \n" +
- "PREFIX tn: <http://ldp.example.org/NewTestDefinitions#> \n\n" +
- "SELECT ?tc ?label \n" +
- "WHERE { \n" +
- " ?tc a td:TestCase ; \n" +
- " rdfs:label ?label . \n" +
- "}";
- TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, testCasesQuery);
- TupleQueryResult results = tupleQuery.evaluate();
- try {
- while (results.hasNext()) {
- BindingSet bindings = results.next();
- LdpTestCase testCase = new LdpTestCase((URI)bindings.getValue("tc"), bindings.getValue("label").stringValue());
-
- //TODO
-
- tests.add(testCase);
- }
- } finally {
- results.close();
- }
- } catch (RepositoryException e) {
- log.error("Error loading test cases: {}", e.getMessage(), e);
- return tests;
- } catch (QueryEvaluationException | MalformedQueryException e) {
- log.error("Error performing test cases' query: {}", e.getMessage(), e);
- return tests;
- } finally {
- conn.commit();
- conn.close();
- }
- } catch (RDFParseException | IOException e) {
- log.error("Error loading test cases: {}", e.getMessage(), e);
- return tests;
- } catch (RepositoryException e) {
- log.error("Error connecting with the repository: {}", e.getMessage(), e);
- return tests;
- }
-
- return tests;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/9150ef74/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java
new file mode 100644
index 0000000..c54cacb
--- /dev/null
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesRunner.java
@@ -0,0 +1,99 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.marmotta.platform.ldp.testsuite;
+
+import org.junit.runner.Runner;
+import org.junit.runners.Suite;
+import org.openrdf.model.URI;
+import org.openrdf.query.*;
+import org.openrdf.repository.Repository;
+import org.openrdf.repository.RepositoryConnection;
+import org.openrdf.repository.RepositoryException;
+import org.openrdf.rio.RDFParseException;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * LDP Test Cases JUnit Runner
+ *
+ * @author Sergio Fernández
+ */
+public class LdpTestCasesRunner extends Suite {
+
+ private static Logger log = LoggerFactory.getLogger(LdpTestCasesRunner.class);
+
+ public LdpTestCasesRunner(Class<?> klass) throws Throwable {
+ super(klass, buildTestCasesFromManifest());
+ }
+
+ private static List<Runner> buildTestCasesFromManifest() {
+ List<Runner> runners = new ArrayList<>();
+
+ try {
+ Repository repo = LdpTestCasesUtils.loadData();
+ RepositoryConnection conn = repo.getConnection();
+ try {
+ conn.begin();
+
+ //TODO: this query is not final, it needs to evolve in parallel with the test cases
+ String testCasesQuery = LdpTestCasesUtils.getNormativeNamespacesSparql() + "\n" +
+ "SELECT ?tc ?label \n" +
+ "WHERE { \n" +
+ " ?tc a td:TestCase ; \n" +
+ " rdfs:label ?label . \n" +
+ "}";
+ TupleQuery tupleQuery = conn.prepareTupleQuery(QueryLanguage.SPARQL, testCasesQuery);
+ TupleQueryResult results = tupleQuery.evaluate();
+ try {
+ while (results.hasNext()) {
+ BindingSet bindings = results.next();
+ LdpTestCase testCase = new LdpTestCase((URI)bindings.getValue("tc"), bindings.getValue("label").stringValue());
+ //TODO: set more data to the test case
+ runners.add(new LdpTestCaseRunner(testCase));
+ }
+ } finally {
+ results.close();
+ }
+ conn.commit();
+ } catch (RepositoryException e) {
+ log.error("Error loading test cases: {}", e.getMessage(), e);
+ return runners;
+ } catch (QueryEvaluationException | MalformedQueryException e) {
+ log.error("Error performing test cases' query: {}", e.getMessage(), e);
+ return runners;
+ } finally {
+ conn.close();
+ }
+ } catch (RDFParseException | IOException e) {
+ log.error("Error loading test cases: {}", e.getMessage(), e);
+ return runners;
+ } catch (RepositoryException e) {
+ log.error("Error connecting with the repository: {}", e.getMessage(), e);
+ return runners;
+ }
+
+ log.info("Initialized LDP test suite with {} test cases", runners.size());
+ return runners;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/9150ef74/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesUtils.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesUtils.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesUtils.java
index 7ff982e..66eead6 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesUtils.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/testsuite/LdpTestCasesUtils.java
@@ -27,6 +27,9 @@ import org.openrdf.sail.memory.MemoryStore;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
import java.util.Properties;
/**
@@ -71,21 +74,56 @@ public class LdpTestCasesUtils {
}
/**
- * Add some normative namespaces
+ * Get normative namespaces
*
- * @param conn target connection
* @throws IOException
* @throws RepositoryException
*
* @see <a href="https://dvcs.w3.org/hg/ldpwg/raw-file/default/Test%20Cases/LDP%20Test%20Cases.html#h3_namespaces-used">Sec. 4.1 Namespaces used</a>
*/
- public static void addNormativeNamespaces(RepositoryConnection conn) throws IOException, RepositoryException {
+ public static Map<String,String> getNormativeNamespaces() throws IOException {
String path = LdpTestCases.FILES_PATH + "namespaces.properties";
+ Map<String,String> prefixes = new HashMap<>();
Properties properties = new Properties();
properties.load(LdpTestCasesUtils.class.getResourceAsStream(path));
for(String key : properties.stringPropertyNames()) {
String value = properties.getProperty(key);
- conn.setNamespace(value, key);
+ prefixes.put(key, value);
+ }
+ return Collections.unmodifiableMap(prefixes);
+ }
+
+ /**
+ * Get normative namespaces with SPARQL syntax
+ *
+ * @throws IOException
+ */
+ public static String getNormativeNamespacesSparql() throws IOException {
+ StringBuffer sb = new StringBuffer();
+ Map<String, String> normativeNamespaces = getNormativeNamespaces();
+ for (Map.Entry<String, String> entry : normativeNamespaces.entrySet()) {
+ //PREFIX dc: <http://purl.org/dc/terms/>
+ sb.append("PREFIX ");
+ sb.append(entry.getKey());
+ sb.append(": <");
+ sb.append(entry.getValue());
+ sb.append("> \n");
+ }
+ return sb.toString();
+ }
+
+ /**
+ * Add normative namespaces
+ *
+ * @param conn target connection
+ * @throws IOException
+ * @throws RepositoryException
+ */
+ public static void addNormativeNamespaces(RepositoryConnection conn) throws IOException, RepositoryException {
+ Map<String, String> normativeNamespaces = getNormativeNamespaces();
+ for (Map.Entry<String, String> entry : normativeNamespaces.entrySet()) {
+ conn.setNamespace(entry.getValue(), entry.getKey());
}
}
+
}