marmotta-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ja...@apache.org
Subject [2/2] git commit: Cleaning up in marmotta-ldp: remove inlined String constants.
Date Fri, 12 Sep 2014 11:17:05 GMT
Cleaning up in marmotta-ldp: remove inlined String constants.


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

Branch: refs/heads/ldp
Commit: 5c3fab13e9771737b4d6fa28558cbeb88edcc7d7
Parents: f0b9944
Author: Jakob Frank <jakob@apache.org>
Authored: Fri Sep 12 09:40:25 2014 +0200
Committer: Jakob Frank <jakob@apache.org>
Committed: Fri Sep 12 13:16:51 2014 +0200

----------------------------------------------------------------------
 .../platform/ldp/webservices/LdpWebService.java | 34 ++++++----
 .../ldp/webservices/LdpWebServiceTest.java      | 70 ++++++++++----------
 2 files changed, 57 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/marmotta/blob/5c3fab13/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
----------------------------------------------------------------------
diff --git a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
index bec9b89..3b23d75 100644
--- a/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
+++ b/platform/marmotta-ldp/src/main/java/org/apache/marmotta/platform/ldp/webservices/LdpWebService.java
@@ -72,6 +72,16 @@ public class LdpWebService {
     public static final String PATH = "/ldp"; //TODO: at some point this will be root ('/')
in marmotta
     public static final String LDP_SERVER_CONSTRAINTS = "http://wiki.apache.org/marmotta/LDPImplementationReport/2014-03-11";
 
+    static final String LINK_REL_DESCRIBEDBY = "describedby";
+    static final String LINK_REL_CONSTRAINEDBY = LINK_REL_DESCRIBEDBY;
+    static final String LINK_REL_CONTENT = "content";
+    static final String LINK_REL_META = "meta";
+    static final String LINK_REL_TYPE = "type";
+    static final String HTTP_HEADER_SLUG = "Slug";
+    static final String HTTP_HEADER_ACCEPT_POST = "Accept-Post";
+    static final String HTTP_HEADER_ACCEPT_PATCH = "Accept-Patch";
+    static final String HTTP_METHOD_PATCH = "PATCH";
+
     private Logger log = org.slf4j.LoggerFactory.getLogger(this.getClass());
 
     @Inject
@@ -320,7 +330,7 @@ public class LdpWebService {
      * @see <a href="https://dvcs.w3.org/hg/ldpwg/raw-file/default/ldp.html#ldpc-HTTP_POST">6.4
LDP-C POST</a>
      */
     @POST
-    public Response POST(@Context UriInfo uriInfo, @HeaderParam("Slug") String slug,
+    public Response POST(@Context UriInfo uriInfo, @HeaderParam(HTTP_HEADER_SLUG) String
slug,
                          @HeaderParam(HttpHeaders.LINK) List<Link> linkHeaders,
                          InputStream postBody, @HeaderParam(HttpHeaders.CONTENT_TYPE) MediaType
type)
             throws RepositoryException {
@@ -419,7 +429,7 @@ public class LdpWebService {
             String location = ldpService.addResource(connection, container, newResource,
interactionModel, mimeType, requestBody);
             final Response.ResponseBuilder response = createResponse(connection, Response.Status.CREATED,
container).location(java.net.URI.create(location));
             if (newResource.compareTo(location) != 0) {
-                response.link(newResource, "describedby"); //FIXME: Sec. 5.2.3.12, see also
http://www.w3.org/2012/ldp/track/issues/15
+                response.link(newResource, LINK_REL_DESCRIBEDBY); //FIXME: Sec. 5.2.3.12,
see also http://www.w3.org/2012/ldp/track/issues/15
             }
             connection.commit();
             return response.build();
@@ -671,21 +681,21 @@ public class LdpWebService {
         if (ldpService.isNonRdfSourceResource(connection, resource)) {
             // Sec. 4.2.8.2
             log.trace("<{}> is an LDP-NR: GET, HEAD, PUT and OPTIONS allowed", resource);
-            builder.allow("GET", "HEAD", "PUT", "OPTIONS");
+            builder.allow(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.PUT, HttpMethod.OPTIONS);
         } else if (ldpService.isRdfSourceResource(connection, resource)) {
             if (ldpService.getInteractionModel(connection, resource) == LdpService.InteractionModel.LDPR)
{
                 log.trace("<{}> is a LDP-RS (LDPR interaction model): GET, HEAD, PUT,
PATCH and OPTIONS allowed", resource);
                 // Sec. 4.2.8.2
-                builder.allow("GET", "HEAD", "PUT", "PATCH", "OPTIONS");
+                builder.allow(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.PUT, HTTP_METHOD_PATCH,
HttpMethod.OPTIONS);
             } else {
                 // Sec. 4.2.8.2
                 log.trace("<{}> is a LDP-RS (LDPC interaction model): GET, HEAD, POST,
PUT, PATCH and OPTIONS allowed", resource);
-                builder.allow("GET", "HEAD", "POST", "PUT", "PATCH", "OPTIONS");
+                builder.allow(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.POST, HttpMethod.PUT,
HTTP_METHOD_PATCH, HttpMethod.OPTIONS);
                 // Sec. 4.2.3 / Sec. 5.2.3
-                builder.header("Accept-Post", LdpUtils.getAcceptPostHeader("*/*"));
+                builder.header(HTTP_HEADER_ACCEPT_POST, LdpUtils.getAcceptPostHeader("*/*"));
             }
             // Sec. 4.2.7.1
-            builder.header("Accept-Patch", RdfPatchParser.MIME_TYPE);
+            builder.header(HTTP_HEADER_ACCEPT_PATCH, RdfPatchParser.MIME_TYPE);
         }
 
         return builder;
@@ -732,7 +742,7 @@ public class LdpWebService {
             for (Statement stmt : statements) {
                 Value o = stmt.getObject();
                 if (o instanceof URI && o.stringValue().startsWith(LDP.NAMESPACE))
{
-                    rb.link(o.stringValue(), "type");
+                    rb.link(o.stringValue(), LINK_REL_TYPE);
                 }
             }
 
@@ -740,14 +750,14 @@ public class LdpWebService {
             if (rdfSource != null) {
                 // Sec. 5.2.8.1 and 5.2.3.12
                 // FIXME: Sec. 5.2.3.12, see also http://www.w3.org/2012/ldp/track/issues/15
-                rb.link(rdfSource.stringValue(), "describedby");
+                rb.link(rdfSource.stringValue(), LINK_REL_DESCRIBEDBY);
                 // TODO: Propose to LDP-WG?
-                rb.link(rdfSource.stringValue(), "meta");
+                rb.link(rdfSource.stringValue(), LINK_REL_META);
             }
             final URI nonRdfSource = ldpService.getNonRdfSourceForRdfSource(connection, resource);
             if (nonRdfSource != null) {
                 // TODO: Propose to LDP-WG?
-                rb.link(nonRdfSource.stringValue(), "content");
+                rb.link(nonRdfSource.stringValue(), LINK_REL_CONTENT);
             }
 
             // ETag (Sec. 4.2.1.3)
@@ -767,7 +777,7 @@ public class LdpWebService {
      */
     protected Response.ResponseBuilder createResponse(Response.ResponseBuilder rb) {
         // Link rel='describedby' (Sec. 4.2.1.6)
-        rb.link(LDP_SERVER_CONSTRAINTS, "describedby");
+        rb.link(LDP_SERVER_CONSTRAINTS, LINK_REL_CONSTRAINEDBY);
 
         return rb;
     }

http://git-wip-us.apache.org/repos/asf/marmotta/blob/5c3fab13/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 e8e4e6e..7bfd7b3 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
@@ -100,7 +100,7 @@ public class LdpWebServiceTest {
         // Create
         final String newResource = RestAssured
             .given()
-                .header("Slug", resourceName)
+                .header(LdpWebService.HTTP_HEADER_SLUG, resourceName)
                 .body(testResourceTTL.getBytes())
                 .contentType(mimeType)
             .expect()
@@ -116,8 +116,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, "describedby"),
-                        HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), "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)
@@ -134,8 +134,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, "describedby"),
-                        HeaderMatchers.isLink(LDP.Resource.stringValue(), "type"))
+                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, LdpWebService.LINK_REL_CONSTRAINEDBY),
+                        HeaderMatchers.isLink(LDP.Resource.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
                 .header(HttpHeaders.ETAG, HeaderMatchers.hasEntityTag(true)) // FIXME: be
more specific here
                 .contentType(mimeType)
@@ -149,7 +149,7 @@ public class LdpWebServiceTest {
         RestAssured
             .expect()
                 .statusCode(204)
-                .header(HttpHeaders.LINK, HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS,
"describedby"))
+                .header(HttpHeaders.LINK, HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS,
LdpWebService.LINK_REL_CONSTRAINEDBY))
                 .header(HttpHeaders.ETAG, HeaderMatchers.headerNotPresent())
                 .header(HttpHeaders.LAST_MODIFIED, HeaderMatchers.headerNotPresent())
             .delete(newResource);
@@ -175,15 +175,15 @@ public class LdpWebServiceTest {
         // Create
         final String binaryResource = RestAssured
             .given()
-                .header("Slug", resourceName)
+                .header(LdpWebService.HTTP_HEADER_SLUG, resourceName)
                 .body(IOUtils.toByteArray(LdpWebServiceTest.class.getResourceAsStream("/test.png")))
                 .contentType(mimeType)
             .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, "describedby"),
-                        HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), "type"))
+                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, LdpWebService.LINK_REL_CONSTRAINEDBY),
+                        HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
             .post(container)
                 .getHeader("Location");
@@ -199,8 +199,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, "describedby"),
-                        HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), "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(RDFFormat.TURTLE.getDefaultMIMEType())
@@ -222,9 +222,9 @@ public class LdpWebServiceTest {
             .expect()
                 .statusCode(200)
                 .header(HttpHeaders.LINK, CoreMatchers.anyOf( //TODO: RestAssured only checks
the FIRST header...
-                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, "describedby"),
-                        HeaderMatchers.isLink(LDP.Resource.stringValue(), "type"),
-                        HeaderMatchers.isLink(LDP.RDFSource.stringValue(), "type"))
+                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, LdpWebService.LINK_REL_CONSTRAINEDBY),
+                        HeaderMatchers.isLink(LDP.Resource.stringValue(), LdpWebService.LINK_REL_TYPE),
+                        HeaderMatchers.isLink(LDP.RDFSource.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
                 .header(HttpHeaders.ETAG, HeaderMatchers.hasEntityTag(true)) // FIXME: be
more specific here
                 .contentType(RDFFormat.TURTLE.getDefaultMIMEType())
@@ -243,9 +243,9 @@ public class LdpWebServiceTest {
             .expect()
                 .statusCode(200)
                 .header(HttpHeaders.LINK, CoreMatchers.anyOf( //TODO: RestAssured only checks
the FIRST header...
-                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, "describedby"),
-                        HeaderMatchers.isLink(LDP.Resource.stringValue(), "type"),
-                        HeaderMatchers.isLink(LDP.NonRDFSource.stringValue(), "type"))
+                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, LdpWebService.LINK_REL_CONSTRAINEDBY),
+                        HeaderMatchers.isLink(LDP.Resource.stringValue(), LdpWebService.LINK_REL_TYPE),
+                        HeaderMatchers.isLink(LDP.NonRDFSource.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
                 .header(HttpHeaders.ETAG, HeaderMatchers.hasEntityTag(false)) // FIXME: be
more specific here
                 .contentType(RDFFormat.TURTLE.getDefaultMIMEType())
@@ -266,9 +266,9 @@ public class LdpWebServiceTest {
             .expect()
                 .statusCode(200)
                 .header(HttpHeaders.LINK, CoreMatchers.anyOf( //TODO: RestAssured only checks
the FIRST header...
-                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, "describedby"),
-                        HeaderMatchers.isLink(LDP.Resource.stringValue(), "type"),
-                        HeaderMatchers.isLink(LDP.RDFSource.stringValue(), "type"))
+                        HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS, LdpWebService.LINK_REL_CONSTRAINEDBY),
+                        HeaderMatchers.isLink(LDP.Resource.stringValue(), LdpWebService.LINK_REL_TYPE),
+                        HeaderMatchers.isLink(LDP.RDFSource.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
                 .header(HttpHeaders.ETAG, HeaderMatchers.hasEntityTag(false)) // FIXME: be
more specific here
                 .contentType(mimeType)
@@ -285,7 +285,7 @@ public class LdpWebServiceTest {
         // Try LDPR
         final String ldpr = RestAssured
             .given()
-                .header(HttpHeaders.LINK, Link.fromUri(LDP.Resource.stringValue()).rel("type").build().toString())
+                .header(HttpHeaders.LINK, Link.fromUri(LDP.Resource.stringValue()).rel(LdpWebService.LINK_REL_TYPE).build().toString())
                 .body(testResourceTTL.getBytes())
                 .contentType(RDFFormat.TURTLE.getDefaultMIMEType())
             .expect()
@@ -305,7 +305,7 @@ public class LdpWebServiceTest {
         // Try an invalid interaction model
         RestAssured
             .given()
-                .header(HttpHeaders.LINK, Link.fromUri(container).rel("type").build().toString())
+                .header(HttpHeaders.LINK, Link.fromUri(container).rel(LdpWebService.LINK_REL_TYPE).build().toString())
                 .body(testResourceTTL.getBytes())
                 .contentType(RDFFormat.TURTLE.getDefaultMIMEType())
             .expect()
@@ -324,13 +324,13 @@ public class LdpWebServiceTest {
         // Create a resource
         final String resource = RestAssured
             .given()
-                .header("Slug", "PUT")
+                .header(LdpWebService.HTTP_HEADER_SLUG, "PUT")
                 .contentType(RDFFormat.TURTLE.getDefaultMIMEType())
                 .body(testResourceTTL.getBytes())
             .expect()
                 .statusCode(201)
             .post(container)
-                .getHeader("Location");
+                .getHeader(HttpHeaders.LOCATION);
         final URI uri = new URIImpl(resource);
 
         // Check the data is there
@@ -345,7 +345,7 @@ public class LdpWebServiceTest {
                         CoreMatchers.not(SesameMatchers.hasStatement(uri, LDP.contains, uri))
                 ))
             .get(resource)
-                .getHeader("ETag"));
+                .getHeader(HttpHeaders.ETAG));
         log.debug("ETag for <{}>: {}", resource, etag);
 
         // Try a Put without if-match header
@@ -424,7 +424,7 @@ public class LdpWebServiceTest {
     private String createTestContainer(String slug) {
         return RestAssured
             .given()
-                .header("Slug", String.valueOf(slug))
+                .header(LdpWebService.HTTP_HEADER_SLUG, String.valueOf(slug))
                 .header(HttpHeaders.CONTENT_TYPE, RDFFormat.TURTLE.getDefaultMIMEType())
                 .body("<> a <http://example.com/unit-test> .".getBytes())
             .expect()
@@ -448,7 +448,7 @@ public class LdpWebServiceTest {
         // Create
         final String newResource = RestAssured
             .given()
-                .header("Slug", resourceName)
+                .header(LdpWebService.HTTP_HEADER_SLUG, resourceName)
                 .body(testResourceTTL.getBytes())
                 .contentType(mimeType)
             .expect()
@@ -462,8 +462,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,
"describedby"),
-                                HeaderMatchers.isLink(LDP.BasicContainer.stringValue(), "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)
@@ -478,8 +478,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,
"describedby"),
-                                HeaderMatchers.isLink(LDP.Resource.stringValue(), "type"))
+                                HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS,
LdpWebService.LINK_REL_CONSTRAINEDBY),
+                                HeaderMatchers.isLink(LDP.Resource.stringValue(), LdpWebService.LINK_REL_TYPE))
                 )
                 .header(HttpHeaders.ETAG, HeaderMatchers.hasEntityTag(true)) // FIXME: be
more specific here
                 .contentType(mimeType)
@@ -493,7 +493,7 @@ public class LdpWebServiceTest {
         RestAssured
             .expect()
                 .statusCode(204)
-                .header(HttpHeaders.LINK, HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS,
"describedby"))
+                .header(HttpHeaders.LINK, HeaderMatchers.isLink(LdpWebService.LDP_SERVER_CONSTRAINTS,
LdpWebService.LINK_REL_CONSTRAINEDBY))
                 .header(HttpHeaders.ETAG, HeaderMatchers.headerNotPresent())
                 .header(HttpHeaders.LAST_MODIFIED, HeaderMatchers.headerNotPresent())
             .delete(newResource);
@@ -515,7 +515,7 @@ public class LdpWebServiceTest {
         // This one is easy:
         RestAssured
             .given()
-                .header("Slug", slug1)
+                .header(LdpWebService.HTTP_HEADER_SLUG, slug1)
                 .header(HttpHeaders.CONTENT_TYPE, RDFFormat.TURTLE.getDefaultMIMEType())
                 .body(testResourceTTL.getBytes())
             .expect()
@@ -526,7 +526,7 @@ public class LdpWebServiceTest {
         // Trying again with the same SLUG
         RestAssured
             .given()
-                .header("Slug", slug1)
+                .header(LdpWebService.HTTP_HEADER_SLUG, slug1)
                 .header(HttpHeaders.CONTENT_TYPE, RDFFormat.TURTLE.getDefaultMIMEType())
                 .body(testResourceTTL.getBytes())
             .expect()
@@ -548,7 +548,7 @@ public class LdpWebServiceTest {
         // This one does some magic on the slug
         RestAssured
             .given()
-                .header("Slug", slug2)
+                .header(LdpWebService.HTTP_HEADER_SLUG, slug2)
                 .header(HttpHeaders.CONTENT_TYPE, RDFFormat.TURTLE.getDefaultMIMEType())
                 .body(testResourceTTL.getBytes())
             .expect()


Mime
View raw message