You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by wi...@apache.org on 2014/03/18 16:37:14 UTC
[2/6] git commit: MARMOTTA-438: improving the generic infrastructure
MARMOTTA-438: improving the generic infrastructure
Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/70978623
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/70978623
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/70978623
Branch: refs/heads/ldp
Commit: 709786234b1efa0dc1c09de88ddf034eff046d01
Parents: b76ed21
Author: Sergio Fernández <wi...@apache.org>
Authored: Mon Mar 17 16:49:24 2014 +0100
Committer: Sergio Fernández <wi...@apache.org>
Committed: Mon Mar 17 16:49:24 2014 +0100
----------------------------------------------------------------------
.../testsuite/LdpAbstractTestSuite.java | 100 ++++++++++++++++---
.../testsuite/LdpResourcesTestSuite.java | 22 ++++
.../resources/testsuite/namespaces.properties | 26 +++++
3 files changed, 136 insertions(+), 12 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/marmotta/blob/70978623/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpAbstractTestSuite.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpAbstractTestSuite.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpAbstractTestSuite.java
index e2453c3..3d091f0 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpAbstractTestSuite.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpAbstractTestSuite.java
@@ -1,18 +1,41 @@
+/*
+ * 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.webservices.testsuite;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.rules.TestName;
import org.openrdf.repository.Repository;
import org.openrdf.repository.RepositoryConnection;
import org.openrdf.repository.RepositoryException;
import org.openrdf.repository.sail.SailRepository;
import org.openrdf.rio.RDFFormat;
import org.openrdf.rio.RDFParseException;
-import org.openrdf.rio.Rio;
import org.openrdf.sail.memory.MemoryStore;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.util.Properties;
/**
* LDP Abstract Test Suite
@@ -24,6 +47,28 @@ public abstract class LdpAbstractTestSuite {
protected static Logger log = LoggerFactory.getLogger(LdpAbstractTestSuite.class);
+ public final static String FILES_PATH = "/testsuite/";
+
+ protected Repository repo;
+
+ @Rule
+ public TestName name = new TestName();
+
+ @Before
+ public final void before() throws RepositoryException, RDFParseException, IOException {
+ log.info("initializing test case {}...", name.getMethodName());
+ repo = loadData(name.getMethodName());
+ Assume.assumeNotNull(repo);
+ }
+
+ @After
+ public final void after() throws RepositoryException {
+ if (repo != null) {
+ repo.shutDown();
+ repo = null;
+ }
+ }
+
/**
* Load a dataset into a new in-memory repository
*
@@ -33,7 +78,7 @@ public abstract class LdpAbstractTestSuite {
* @throws RepositoryException
* @throws IOException
*/
- protected Repository loadDataset(String file) throws RDFParseException, RepositoryException, IOException {
+ protected Repository loadData(String file) throws RDFParseException, RepositoryException, IOException {
log.debug("creating new in-memory repository...");
Repository repo = new SailRepository(new MemoryStore());
repo.initialize();
@@ -41,7 +86,9 @@ public abstract class LdpAbstractTestSuite {
try {
conn.begin();
conn.clear();
- loadDataset(conn, file);
+ conn.clearNamespaces();
+ addNormativeNamespaces(conn);
+ loadData(conn, file);
conn.commit();
} finally {
conn.close();
@@ -53,21 +100,50 @@ public abstract class LdpAbstractTestSuite {
* Load a dataset to the connection passed
*
* @param conn connection
- * @param file file name
+ * @param tc test case identifier
* @throws RDFParseException
* @throws RepositoryException
* @throws IOException
*/
- protected void loadDataset(RepositoryConnection conn, String file) throws RDFParseException, RepositoryException, IOException {
- log.debug("loading dataset from {}...", file);
- InputStream dataset = getClass().getResourceAsStream(file);
- try {
- conn.add(dataset, "", Rio.getParserFormatForFileName(file));
+ protected void loadData(RepositoryConnection conn, String tc) throws RDFParseException, RepositoryException, IOException {
+ log.debug("loading test case {}...", tc);
+ String path = FILES_PATH + "TC-" + tc + ".ttl";
+ InputStream is = getClass().getResourceAsStream(path);
+ if (is == null) {
+ log.error("Data for test case {} not found where expected ({})", tc, path);
+ } else {
+ try {
+ conn.add(is, "", RDFFormat.TURTLE);
+ } finally {
+ is.close();
+ }
+ log.debug("data for test case {} successfully loaded", tc);
}
- finally {
- dataset.close();
+ }
+
+ /**
+ * Add some normative namespaces
+ *
+ * @param conn target connection
+ * @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>
+ */
+ private void addNormativeNamespaces(RepositoryConnection conn) {
+ Properties properties = new Properties();
+ String path = FILES_PATH + "namespaces.properties";
+ try {
+ properties.load(getClass().getResourceAsStream(path));
+ for(String key : properties.stringPropertyNames()) {
+ String value = properties.getProperty(key);
+ try {
+ conn.setNamespace(value, key);
+ } catch (RepositoryException e) {
+ log.error("Error adding namespace {}: {}", key, e.getMessage());
+ }
+ }
+ } catch (IOException | NullPointerException e) {
+ log.error("Error loading normative namespaces at {}: {}", path, e.getMessage());
}
- log.debug("dataset successfully loaded");
+
}
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/70978623/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpResourcesTestSuite.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpResourcesTestSuite.java b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpResourcesTestSuite.java
index 6861189..6c7ed93 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpResourcesTestSuite.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/testsuite/LdpResourcesTestSuite.java
@@ -1,5 +1,24 @@
+/*
+ * 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.webservices.testsuite;
+import org.junit.Test;
+
/**
* LDPRs Test Suite
*
@@ -7,6 +26,9 @@ package org.apache.marmotta.platform.ldp.webservices.testsuite;
*/
public class LdpResourcesTestSuite extends LdpAbstractTestSuite {
+ @Test
+ public void R1() {
+ }
}
http://git-wip-us.apache.org/repos/asf/marmotta/blob/70978623/platform/marmotta-ldp/src/test/resources/testsuite/namespaces.properties
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/resources/testsuite/namespaces.properties b/platform/marmotta-ldp/src/test/resources/testsuite/namespaces.properties
new file mode 100644
index 0000000..3d4f2f6
--- /dev/null
+++ b/platform/marmotta-ldp/src/test/resources/testsuite/namespaces.properties
@@ -0,0 +1,26 @@
+# 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.
+
+cnt=http://www.w3.org/2011/content#
+dc=http://purl.org/dc/terms/
+doap=http://usefulinc.com/ns/doap#
+earl=http://www.w3.org/ns/earl#
+foaf=http://xmlns.com/foaf/0.1/
+ht=http://www.w3.org/2011/http#
+httph=http://www.w3.org/2011/http-headers#
+ldptc=http://www.w3.org/TR/ldp/TestCases#
+td=http://www.w3.org/2006/03/test-description#
+tn=http://ldp.example.org/NewTestDefinitions#