marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject [3/3] git commit: MARMOTTA-530: checking presence of anchor in the describedby-Link header.
Date Tue, 16 Sep 2014 15:45:27 GMT
MARMOTTA-530: checking presence of anchor in the describedby-Link header.


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

Branch: refs/heads/ldp
Commit: 4061e343adb07c090d06af247e5a8fd12685b73b
Parents: b5a90a9
Author: Jakob Frank <jakob@apache.org>
Authored: Mon Sep 15 10:52:29 2014 +0200
Committer: Jakob Frank <jakob@apache.org>
Committed: Tue Sep 16 17:45:07 2014 +0200

----------------------------------------------------------------------
 .../ldp/webservices/LdpWebServiceTest.java      | 35 ++++++++++++++------
 1 file changed, 24 insertions(+), 11 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/4061e343/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
index 7bfd7b3..d98cab1 100644
--- a/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
+++ b/platform/marmotta-ldp/src/test/java/org/apache/marmotta/platform/ldp/webservices/LdpWebServiceTest.java
@@ -18,7 +18,10 @@
 package org.apache.marmotta.platform.ldp.webservices;
 
 import com.jayway.restassured.RestAssured;
+import com.jayway.restassured.response.Header;
+import com.jayway.restassured.response.Headers;
 import org.apache.commons.io.IOUtils;
+import org.apache.commons.lang3.StringUtils;
 import org.apache.marmotta.commons.sesame.test.SesameMatchers;
 import org.apache.marmotta.commons.util.HashUtils;
 import org.apache.marmotta.commons.vocabulary.LDP;
@@ -31,6 +34,7 @@ import org.hamcrest.CoreMatchers;
 import org.hamcrest.Description;
 import org.hamcrest.TypeSafeMatcher;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.BeforeClass;
 import org.junit.Test;
 import org.openrdf.model.URI;
@@ -116,8 +120,8 @@ public class LdpWebServiceTest {
             .expect()
                 .statusCode(200)
                 .header(HttpHeaders.LINK, CoreMatchers.anyOf( //TODO: RestAssured only checks
the FIRST header...
-                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, LdpWebService.LINK_REL_CONSTRAINEDBY),
-                        HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), LdpWebService.LINK_REL_TYPE))
+                                HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS,
LdpWebService.LINK_REL_CONSTRAINEDBY),
+                                HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
                 .header(HttpHeaders.ETAG, HeaderMatchers.hasEntityTag(true)) // FIXME: be
more specific here
                 .contentType(mimeType)
@@ -173,7 +177,7 @@ public class LdpWebServiceTest {
         final String mimeType = "image/png";
 
         // Create
-        final String binaryResource = RestAssured
+        final Headers headers = RestAssured
             .given()
                 .header(LdpWebService.HTTP_HEADER_SLUG, resourceName)
                 .body(IOUtils.toByteArray(LdpWebServiceTest.class.getResourceAsStream("/test.png")))
@@ -181,16 +185,25 @@ public class LdpWebServiceTest {
             .expect()
                 .statusCode(201)
                 .header(HttpHeaders.LINK, CoreMatchers.anyOf( //TODO: RestAssured only checks
the FIRST header...
-                        //  HeaderMatchers.isLink(metaResource, "describedby"),
-                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, LdpWebService.LINK_REL_CONSTRAINEDBY),
-                        HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), LdpWebService.LINK_REL_TYPE))
+                                //  HeaderMatchers.isLink(metaResource, "describedby"),
+                                HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS,
LdpWebService.LINK_REL_CONSTRAINEDBY),
+                                HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
             .post(container)
-                .getHeader("Location");
-
-
-
-        final String metaResource = binaryResource.replaceFirst("\\.png$", "");
+                .headers();
+
+
+        final String binaryResource = headers.getValue(HttpHeaders.LOCATION);
+        String metaResource = null;
+        for (Header lh: headers.getList(HttpHeaders.LINK)) {
+            final Link link = Link.valueOf(lh.getValue());
+            if (StringUtils.equals(LdpWebService.LINK_REL_DESCRIBEDBY, link.getRel())) {
+                Assert.assertEquals("Link-Header with describedby not anchored", binaryResource,
link.getParams().get(LdpWebService.LINK_PARAM_ANCHOR));
+                metaResource = link.getUri().toASCIIString();
+                break;
+            }
+        }
+        Assert.assertNotNull("Link header with describedby missing", metaResource);
 
         // now the container hasType
         RestAssured


Mime
View raw message