You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@marmotta.apache.org by tk...@apache.org on 2016/10/19 14:04:44 UTC

[2/6] marmotta git commit: TimeGate now responds with the most recent Memento if date is not given. Tests are added.

TimeGate now responds with the most recent Memento if date is not given. Tests are added.


Project: http://git-wip-us.apache.org/repos/asf/marmotta/repo
Commit: http://git-wip-us.apache.org/repos/asf/marmotta/commit/d216030b
Tree: http://git-wip-us.apache.org/repos/asf/marmotta/tree/d216030b
Diff: http://git-wip-us.apache.org/repos/asf/marmotta/diff/d216030b

Branch: refs/heads/MARMOTTA-655_Memento_Compliance_Issues
Commit: d216030b01ad921b36e2aeb96aec1468590ffe51
Parents: cd789c9
Author: Thomas Kurz <th...@salzburgresearch.at>
Authored: Thu Oct 13 17:48:21 2016 +0200
Committer: Thomas Kurz <th...@salzburgresearch.at>
Committed: Thu Oct 13 17:48:21 2016 +0200

----------------------------------------------------------------------
 platform/marmotta-versioning-kiwi/pom.xml       | 55 ++++++++++++++++
 .../webservices/MementoWebService.java          | 11 +++-
 .../versioning/MementoWebServiceTest.java       | 69 ++++++++++++++++++++
 .../src/test/resources/data_v1.ttl              |  2 +
 .../src/test/resources/data_v2.ttl              |  1 +
 5 files changed, 136 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/d216030b/platform/marmotta-versioning-kiwi/pom.xml
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/pom.xml b/platform/marmotta-versioning-kiwi/pom.xml
index f49926d..53ba8b0 100644
--- a/platform/marmotta-versioning-kiwi/pom.xml
+++ b/platform/marmotta-versioning-kiwi/pom.xml
@@ -170,6 +170,61 @@
             <groupId>org.apache.marmotta</groupId>
             <artifactId>kiwi-versioning</artifactId>
         </dependency>
+        <!-- testing -->
+        <dependency>
+            <groupId>org.apache.marmotta</groupId>
+            <artifactId>marmotta-core</artifactId>
+            <version>${project.version}</version>
+            <type>test-jar</type>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-server</artifactId>
+            <version>${jetty.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.eclipse.jetty</groupId>
+            <artifactId>jetty-servlet</artifactId>
+            <version>${jetty.version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.jboss.weld.se</groupId>
+            <artifactId>weld-se-core</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>javax.el</groupId>
+            <artifactId>javax.el-api</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.h2database</groupId>
+            <artifactId>h2</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>com.jayway.restassured</groupId>
+            <artifactId>rest-assured</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-library</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.hamcrest</groupId>
+            <artifactId>hamcrest-core</artifactId>
+            <scope>test</scope>
+        </dependency>
 
         <!-- webjars -->
         <dependency>

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d216030b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
index e481801..2f7dec4 100644
--- a/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
+++ b/platform/marmotta-versioning-kiwi/src/main/java/org/apache/marmotta/platform/versioning/webservices/MementoWebService.java
@@ -106,11 +106,18 @@ public class MementoWebService {
         try {
             //check preconditions
             Preconditions.checkNotNull(resource_string,"Resource URI may not null");
-            Preconditions.checkNotNull(date_string, "Accept-Datetime Header may not be null");
 
             final RepositoryConnection conn = sesameService.getConnection();
             try {
-                Date date = DateUtils.parseDate(date_string);
+
+                //if date_string is not set, get NOW, else parse date_string
+                Date date = null;
+
+                if(date_string == null) {
+                    date = new Date();
+                } else {
+                    DateUtils.parseDate(date_string);
+                }
 
                 URI resource = conn.getValueFactory().createURI(resource_string);
 

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d216030b/platform/marmotta-versioning-kiwi/src/test/java/org/apache/marmotta/platform/versioning/MementoWebServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/src/test/java/org/apache/marmotta/platform/versioning/MementoWebServiceTest.java b/platform/marmotta-versioning-kiwi/src/test/java/org/apache/marmotta/platform/versioning/MementoWebServiceTest.java
new file mode 100644
index 0000000..1b165ff
--- /dev/null
+++ b/platform/marmotta-versioning-kiwi/src/test/java/org/apache/marmotta/platform/versioning/MementoWebServiceTest.java
@@ -0,0 +1,69 @@
+package org.apache.marmotta.platform.versioning;
+
+import com.jayway.restassured.RestAssured;
+import org.apache.marmotta.platform.core.api.importer.ImportService;
+import org.apache.marmotta.platform.core.api.triplestore.ContextService;
+import org.apache.marmotta.platform.core.api.user.UserService;
+import org.apache.marmotta.platform.core.exception.io.MarmottaImportException;
+import org.apache.marmotta.platform.core.test.base.JettyMarmotta;
+import org.apache.marmotta.platform.versioning.utils.MementoUtils;
+import org.apache.marmotta.platform.versioning.webservices.MementoWebService;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import java.io.InputStream;
+import java.net.URISyntaxException;
+
+import static com.jayway.restassured.RestAssured.expect;
+
+/**
+ * @author Thomas Kurz (tkurz@apache.org)
+ * @since 13.10.16.
+ */
+public class MementoWebServiceTest {
+
+    private static Logger log = LoggerFactory.getLogger(MementoWebServiceTest.class);
+
+    private static JettyMarmotta marmotta;
+
+    @BeforeClass
+    public static void setUp() throws MarmottaImportException, URISyntaxException {
+        marmotta = new JettyMarmotta("/marmotta", MementoWebService.class);
+
+        ImportService importService = marmotta.getService(ImportService.class);
+        UserService userService = marmotta.getService(UserService.class);
+        ContextService contextService = marmotta.getService(ContextService.class);
+
+        //import some data
+        InputStream is_v1 = Thread.currentThread().getContextClassLoader().getResourceAsStream("data_v1.ttl");
+        int n_v1 = importService.importData(is_v1, "text/turtle", userService.getAnonymousUser(), contextService.getDefaultContext());
+        log.info("Imported RDF data_v1 with {} triples", n_v1);
+
+        //import some data including updates
+        InputStream is_v2 = Thread.currentThread().getContextClassLoader().getResourceAsStream("data_v2.ttl");
+        int n_v2 = importService.importData(is_v2, "text/turtle", userService.getAnonymousUser(), contextService.getDefaultContext());
+        log.info("Imported RDF data_v2 with {} triples", n_v2);
+
+        RestAssured.baseURI = "http://localhost";
+        RestAssured.port = marmotta.getPort();
+        RestAssured.basePath = marmotta.getContext();
+    }
+
+    @AfterClass
+    public static void tearDown() {
+        marmotta.shutdown();
+    }
+
+    @Test
+    public void testNegotiationResponse() {
+        expect().
+                log().ifError().
+                statusCode(302).
+                when().request().redirects().follow(false).
+                get(MementoUtils.MEMENTO_WEBSERVICE + "/" + MementoUtils.MEMENTO_TIMEGATE + "/http://example.org/resource1");
+    }
+
+}

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d216030b/platform/marmotta-versioning-kiwi/src/test/resources/data_v1.ttl
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/src/test/resources/data_v1.ttl b/platform/marmotta-versioning-kiwi/src/test/resources/data_v1.ttl
new file mode 100644
index 0000000..1cae348
--- /dev/null
+++ b/platform/marmotta-versioning-kiwi/src/test/resources/data_v1.ttl
@@ -0,0 +1,2 @@
+<http://example.org/resource1> <http://test.org/p1> "v1".
+<http://example.org/resource2> <http://test.org/p1> "v1".
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/marmotta/blob/d216030b/platform/marmotta-versioning-kiwi/src/test/resources/data_v2.ttl
----------------------------------------------------------------------
diff --git a/platform/marmotta-versioning-kiwi/src/test/resources/data_v2.ttl b/platform/marmotta-versioning-kiwi/src/test/resources/data_v2.ttl
new file mode 100644
index 0000000..c80a86d
--- /dev/null
+++ b/platform/marmotta-versioning-kiwi/src/test/resources/data_v2.ttl
@@ -0,0 +1 @@
+<http://example.org/resource1> <http://test.org/p1> "v2".
\ No newline at end of file