[exo-jcr-commits] exo-jcr SVN: r3907 - in jcr/trunk/exo.jcr.component.webdav/src: main/java/org/exoplatform/services/jcr/webdav/command and 1 other directories.

do-not-reply at jboss.org do-not-reply at jboss.org
Tue Feb 1 05:23:17 EST 2011


Author: dkuleshov
Date: 2011-02-01 05:23:16 -0500 (Tue, 01 Feb 2011)
New Revision: 3907

Modified:
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java
   jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
   jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java
   jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java
   jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java
   jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java
Log:
EXOJCR-1122: location header added to CREATED response

Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/WebDavServiceImpl.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -73,6 +73,7 @@
 import java.io.InputStream;
 import java.lang.annotation.Annotation;
 import java.lang.reflect.Method;
+import java.net.URI;
 import java.net.URLEncoder;
 import java.util.ArrayList;
 import java.util.HashMap;
@@ -478,6 +479,8 @@
       {
          String serverURI = uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).build().toString();
 
+         URI destinationUri = uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).path(repoPath).build();
+
          destinationHeader = TextUtil.unescape(destinationHeader, '%');
 
          if (!destinationHeader.startsWith(serverURI))
@@ -519,11 +522,11 @@
             if (srcWorkspace.equals(destWorkspace))
             {
                Session session = session(repoName, destWorkspace, lockTokens);
-               return new CopyCommand().copy(session, srcNodePath, destNodePath);
+               return new CopyCommand(destinationHeader).copy(session, srcNodePath, destNodePath);
             }
 
             Session destSession = session(repoName, destWorkspace, lockTokens);
-            return new CopyCommand().copy(destSession, srcWorkspace, srcNodePath, destNodePath);
+            return new CopyCommand(destinationHeader).copy(destSession, srcWorkspace, srcNodePath, destNodePath);
 
          }
          else if (depth.getIntValue() == 0)
@@ -534,7 +537,8 @@
 
             Session session = session(repoName, destWorkspace, lockTokens);
 
-            return new MkColCommand(nullResourceLocks).mkCol(session, destNodePath + "/" + nodeName,
+            return new MkColCommand(nullResourceLocks, destinationUri).mkCol(session, destNodePath + "/"
+               + nodeName,
                defaultFolderNodeType, null, lockTokens);
 
          }
@@ -794,13 +798,26 @@
    /**
     * {@inheritDoc}
     */
+   @Deprecated
+   public Response mkcol(String repoName, String repoPath, String lockTokenHeader, String ifHeader,
+      String nodeTypeHeader, String mixinTypesHeader)
+   {
+      return mkcol(repoName, repoPath, lockTokenHeader, ifHeader, nodeTypeHeader, mixinTypesHeader, null);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
    @MKCOL
    @Path("/{repoName}/{repoPath:.*}/")
    public Response mkcol(@PathParam("repoName") String repoName, @PathParam("repoPath") String repoPath,
       @HeaderParam(ExtHttpHeaders.LOCKTOKEN) String lockTokenHeader, @HeaderParam(ExtHttpHeaders.IF) String ifHeader,
       @HeaderParam(ExtHttpHeaders.CONTENT_NODETYPE) String nodeTypeHeader,
-      @HeaderParam(ExtHttpHeaders.CONTENT_MIXINTYPES) String mixinTypesHeader)
+      @HeaderParam(ExtHttpHeaders.CONTENT_MIXINTYPES) String mixinTypesHeader, @Context UriInfo uriInfo)
    {
+
+
+
       if (log.isDebugEnabled())
       {
          log.debug("MKCOL " + repoName + "/" + repoPath);
@@ -818,8 +835,10 @@
             nodeType = defaultFolderNodeType;
          }
 
-         return new MkColCommand(nullResourceLocks).mkCol(session, path(repoPath), nodeType, NodeTypeUtil
-            .getMixinTypes(mixinTypesHeader), tokens);
+         URI destinationUri = uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).path(repoPath).build();
+
+         return new MkColCommand(nullResourceLocks, destinationUri).mkCol(session, path(repoPath), nodeType,
+            NodeTypeUtil.getMixinTypes(mixinTypesHeader), tokens);
       }
       catch (NoSuchWorkspaceException exc)
       {
@@ -898,12 +917,12 @@
             if (srcWorkspace.equals(destWorkspace))
             {
                Session session = session(repoName, srcWorkspace, lockTokens);
-               return new MoveCommand().move(session, srcNodePath, destNodePath);
+               return new MoveCommand(destinationHeader).move(session, srcNodePath, destNodePath);
             }
 
             Session srcSession = session(repoName, srcWorkspace, lockTokens);
             Session destSession = session(repoName, destWorkspace, lockTokens);
-            return new MoveCommand().move(srcSession, destSession, srcNodePath, destNodePath);
+            return new MoveCommand(destinationHeader).move(srcSession, destSession, srcNodePath, destNodePath);
          }
          else
          {
@@ -1053,6 +1072,18 @@
    /**
     * {@inheritDoc}
     */
+   @Deprecated
+   public Response put(String repoName, String repoPath, String lockTokenHeader, String ifHeader,
+      String fileNodeTypeHeader, String contentNodeTypeHeader, String mixinTypes, MediaType mediatype,
+      InputStream inputStream)
+   {
+      return put(repoName, repoPath, lockTokenHeader, ifHeader, fileNodeTypeHeader, contentNodeTypeHeader, mixinTypes,
+         mediatype, inputStream, null);
+   }
+
+   /**
+    * {@inheritDoc}
+    */
    @PUT
    @Path("/{repoName}/{repoPath:.*}/")
    public Response put(@PathParam("repoName") String repoName, @PathParam("repoPath") String repoPath,
@@ -1060,9 +1091,11 @@
       @HeaderParam(ExtHttpHeaders.FILE_NODETYPE) String fileNodeTypeHeader,
       @HeaderParam(ExtHttpHeaders.CONTENT_NODETYPE) String contentNodeTypeHeader,
       @HeaderParam(ExtHttpHeaders.CONTENT_MIXINTYPES) String mixinTypes,
-      @HeaderParam(ExtHttpHeaders.CONTENT_TYPE) MediaType mediatype, InputStream inputStream)
+      @HeaderParam(ExtHttpHeaders.CONTENT_TYPE) MediaType mediatype, InputStream inputStream, @Context UriInfo uriInfo)
    {
 
+      URI destinationUri = uriInfo.getBaseUriBuilder().path(getClass()).path(repoName).path(repoPath).build();
+
       if (log.isDebugEnabled())
       {
          log.debug("PUT " + repoName + "/" + repoPath);
@@ -1101,7 +1134,8 @@
          NodeType nodeType = ntm.getNodeType(contentNodeType);
          NodeTypeUtil.checkContentResourceType(nodeType);
 
-         return new PutCommand(nullResourceLocks).put(session, path(repoPath), inputStream, fileNodeType,
+         return new PutCommand(nullResourceLocks, destinationUri).put(session, path(repoPath), inputStream,
+            fileNodeType,
             contentNodeType, NodeTypeUtil.getMixinTypes(mixinTypes), mimeType, encoding, updatePolicyType,
             autoVersionType, tokens);
 

Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/CopyCommand.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -21,6 +21,7 @@
 import org.exoplatform.common.http.HTTPStatus;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ExtHttpHeaders;
 
 import javax.jcr.AccessDeniedException;
 import javax.jcr.ItemExistsException;
@@ -46,6 +47,29 @@
    private static Log log = ExoLogger.getLogger("exo.jcr.component.webdav.CopyCommand");
 
    /**
+     * Provides URI information needed for 'location' header in 'CREATED' response
+     */
+   private static String destination;
+
+   /**
+    * Empty constructor
+    */
+   public CopyCommand()
+   {
+      this.destination = null;
+   }
+
+   /**
+    * Constructor
+    * 
+    * @param destination - provide data used in 'location' header
+    */
+   public CopyCommand(String destination)
+   {
+      this.destination = destination;
+   }
+
+   /**
     * Webdav COPY method implementation for the same workspace.
     * 
     * @param destSession destination session
@@ -58,6 +82,12 @@
       try
       {
          destSession.getWorkspace().copy(sourcePath, destPath);
+         if (destination != null)
+         {
+            return Response.status(HTTPStatus.CREATED).header(ExtHttpHeaders.LOCATION, destination).build();
+         }
+
+         // to save compatibility for deprecated WebDavServiceImpl.put(..), which does not provide uriInfo
          return Response.status(HTTPStatus.CREATED).build();
       }
       catch (ItemExistsException e)
@@ -97,6 +127,12 @@
       try
       {
          destSession.getWorkspace().copy(sourceWorkspace, sourcePath, destPath);
+         if (destination != null)
+         {
+            return Response.status(HTTPStatus.CREATED).header(ExtHttpHeaders.LOCATION, destination).build();
+         }
+
+         // to save compatibility for deprecated WebDavServiceImpl.put(..), which does not provide uriInfo
          return Response.status(HTTPStatus.CREATED).build();
       }
       catch (ItemExistsException e)

Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MkColCommand.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -24,6 +24,7 @@
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
 
+import java.net.URI;
 import java.util.List;
 
 import javax.jcr.AccessDeniedException;
@@ -56,6 +57,11 @@
    private final NullResourceLocksHolder nullResourceLocks;
 
    /**
+    * Provides URI information needed for 'location' header in 'CREATED' response
+    */
+   private final URI destinationUri;
+
+   /**
     * Constructor. 
     * 
     * @param nullResourceLocks resource locks. 
@@ -63,9 +69,22 @@
    public MkColCommand(final NullResourceLocksHolder nullResourceLocks)
    {
       this.nullResourceLocks = nullResourceLocks;
+      this.destinationUri = null;
    }
 
    /**
+    * Constructor. 
+    * 
+    * @param nullResourceLocks resource locks. 
+    * @param uriInfo - provide data used in 'location' header
+    */
+   public MkColCommand(final NullResourceLocksHolder nullResourceLocks, URI serverUri)
+   {
+      this.nullResourceLocks = nullResourceLocks;
+      this.destinationUri = serverUri;
+   }
+
+   /**
     * Webdav Mkcol method implementation.
     * 
     * @param session current session
@@ -77,6 +96,7 @@
     */
    public Response mkCol(Session session, String path, String nodeType, List<String> mixinTypes, List<String> tokens)
    {
+
       Node node;
       try
       {
@@ -89,6 +109,7 @@
             addMixins(node, mixinTypes);
          }
          session.save();
+
       }
 
       catch (ItemExistsException exc)
@@ -117,6 +138,12 @@
          return Response.serverError().entity(exc.getMessage()).build();
       }
 
+      if (destinationUri != null)
+      {
+         return Response.created(destinationUri).build();
+      }
+
+      // to save compatibility for deprecated WebDavServiceImpl.put(..), which does not provide uriInfo
       return Response.status(HTTPStatus.CREATED).build();
    }
 

Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/MoveCommand.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -21,6 +21,7 @@
 import org.exoplatform.common.http.HTTPStatus;
 import org.exoplatform.services.log.ExoLogger;
 import org.exoplatform.services.log.Log;
+import org.exoplatform.services.rest.ExtHttpHeaders;
 
 import javax.jcr.PathNotFoundException;
 import javax.jcr.RepositoryException;
@@ -48,6 +49,11 @@
     */
    private static Log log = ExoLogger.getLogger("exo.jcr.component.webdav.MoveCommand");
 
+   /**
+    * Provides URI information needed for 'location' header in 'CREATED' response
+    */
+   private final String destination;
+
    // Fix problem with moving under Windows Explorer.
    static
    {
@@ -55,6 +61,23 @@
    }
 
    /**
+    * Empty constructor
+    */
+   public MoveCommand()
+   {
+      this.destination = null;
+   }
+
+   /**
+    * Constructor to receive URI Info
+    * @param destination - provide data used in 'location' header
+    */
+   public MoveCommand(String destination)
+   {
+      this.destination = destination;
+   }
+
+   /**
     * Webdav Move method implementation.
     * 
     * @param session current session.
@@ -82,6 +105,12 @@
          }
          else
          {
+            if (destination != null)
+            {
+               return Response.status(HTTPStatus.CREATED).header(ExtHttpHeaders.LOCATION, destination).build();
+            }
+
+            // to save compatibility for deprecated WebDavServiceImpl.move(..), which does not provide uriInfo
             return Response.status(HTTPStatus.CREATED).cacheControl(cacheControl).build();
          }
 

Modified: jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/main/java/org/exoplatform/services/jcr/webdav/command/PutCommand.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -23,6 +23,7 @@
 import org.exoplatform.services.jcr.webdav.util.TextUtil;
 
 import java.io.InputStream;
+import java.net.URI;
 import java.util.Calendar;
 import java.util.List;
 
@@ -50,6 +51,11 @@
    private final NullResourceLocksHolder nullResourceLocks;
 
    /**
+    * Provides URI information needed for 'location' header in 'CREATED' response
+    */
+   private final URI destinationUri;
+
+   /**
     * Constructor.
     * 
     * @param nullResourceLocks resource locks.
@@ -57,9 +63,22 @@
    public PutCommand(final NullResourceLocksHolder nullResourceLocks)
    {
       this.nullResourceLocks = nullResourceLocks;
+      this.destinationUri = null;
    }
 
    /**
+     * Constructor.
+     * 
+     * @param nullResourceLocks resource locks.
+     * @param uriInfo - provide data used in 'location' header
+     */
+   public PutCommand(final NullResourceLocksHolder nullResourceLocks, URI destinationUri)
+   {
+      this.nullResourceLocks = nullResourceLocks;
+      this.destinationUri = destinationUri;
+   }
+
+   /**
     * Webdav Put method implementation.
     * 
     * @param session current session
@@ -86,6 +105,7 @@
          {
             node = (Node)session.getItem(path);
          }
+
          catch (PathNotFoundException pexc)
          {
             nullResourceLocks.checkLock(session, path, tokens);
@@ -151,7 +171,14 @@
       {
          return Response.status(HTTPStatus.CONFLICT).entity(exc.getMessage()).build();
       }
+      if (destinationUri != null)
+      {
+         //         String destination = destinationUri + "/" + session.getWorkspace().getName() + path;
+         //         return Response.status(HTTPStatus.CREATED).header(ExtHttpHeaders.LOCATION, destination).build();
+         return Response.created(destinationUri).build();
+      }
 
+      // to save compatibility for deprecated WebDavServiceImpl.put(..), which does not provide uriInfo
       return Response.status(HTTPStatus.CREATED).build();
    }
 

Modified: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestCopy.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -21,6 +21,7 @@
 import org.exoplatform.common.http.HTTPStatus;
 import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
 import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
+import org.exoplatform.services.jcr.webdav.WebDavServiceImpl;
 import org.exoplatform.services.jcr.webdav.util.TextUtil;
 import org.exoplatform.services.jcr.webdav.utils.TestUtils;
 import org.exoplatform.services.rest.ExtHttpHeaders;
@@ -101,6 +102,34 @@
 
    }
 
+   /**
+    * Testing {@link WebDavServiceImpl} COPY method for correct response 
+    * building. According to 'RFC-2616' it is expected to contain 'location' header.
+    * More info is introduced <a href=http://tools.ietf.org/html/rfc2616#section-14.30>here</a>.
+    * @throws Exception
+    */
+   public void testLocationHeaderInCopyResponse() throws Exception
+   {
+      String content = TestUtils.getFileContent();
+      String filename = TestUtils.getFileName();
+      InputStream inputStream = new ByteArrayInputStream(content.getBytes());
+      TestUtils.addContent(session, filename, inputStream, defaultFileNodeType, "");
+      String destFilename = TestUtils.getFileName();
+
+      // prepare headers
+      MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+      headers.add(ExtHttpHeaders.DESTINATION, getPathWS() + destFilename);
+
+      // execute query
+      ContainerResponse response = service(WebDAVMethods.COPY, getPathWS() + filename, "", headers, null);
+      // check if operation completed successfully, we expect a new resource to be created
+      assertEquals(HTTPStatus.CREATED, response.getStatus());
+      // check if response 'CREATED' contains 'LOCATION' header
+      assertTrue(response.getHttpHeaders().containsKey(ExtHttpHeaders.LOCATION));
+      // check if 'CREATED' response 'LOCATION' header contains correct location path
+      assertTrue(response.getHttpHeaders().get(ExtHttpHeaders.LOCATION).toString().contains(getPathWS() + destFilename));
+   }
+
    @Override
    protected String getRepositoryName()
    {

Modified: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMkCol.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -21,8 +21,10 @@
 import org.exoplatform.common.http.HTTPStatus;
 import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
 import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
+import org.exoplatform.services.jcr.webdav.WebDavServiceImpl;
 import org.exoplatform.services.jcr.webdav.util.TextUtil;
 import org.exoplatform.services.jcr.webdav.utils.TestUtils;
+import org.exoplatform.services.rest.ExtHttpHeaders;
 import org.exoplatform.services.rest.impl.ContainerResponse;
 
 import java.io.ByteArrayInputStream;
@@ -58,6 +60,26 @@
       assertTrue(folderNode.hasNode(TextUtil.relativizePath(file)));
    }
 
+   /**
+    * Testing {@link WebDavServiceImpl} MKCOL method for correct response 
+    * building. According to 'RFC-2616' it is expected to contain 'location' header.
+    * More info is introduced <a href=http://tools.ietf.org/html/rfc2616#section-14.30>here</a>.
+    * @throws Exception
+    */
+   public void testLocationHeaderInMkColResponse() throws Exception
+   {
+      String folder = TestUtils.getFolderName();
+
+      // execute query
+      ContainerResponse response = service(WebDAVMethods.MKCOL, getPathWS() + folder, "", null, null);
+      // check if operation completed successfully, we expect a new resource to be created
+      assertEquals(HTTPStatus.CREATED, response.getStatus());
+      // here we check if response 'CREATED' contains 'LOCATION' header
+      assertTrue(response.getHttpHeaders().containsKey(ExtHttpHeaders.LOCATION));
+      // here we check if 'CREATED' response 'LOCATION' header contains correct location path
+      assertTrue(response.getHttpHeaders().get(ExtHttpHeaders.LOCATION).toString().contains(getPathWS() + folder));
+   }
+
    @Override
    protected String getRepositoryName()
    {

Modified: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestMove.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -21,6 +21,7 @@
 import org.exoplatform.common.http.HTTPStatus;
 import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
 import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
+import org.exoplatform.services.jcr.webdav.WebDavServiceImpl;
 import org.exoplatform.services.jcr.webdav.util.TextUtil;
 import org.exoplatform.services.jcr.webdav.utils.TestUtils;
 import org.exoplatform.services.rest.ExtHttpHeaders;
@@ -85,6 +86,35 @@
       assertFalse(session.getRootNode().hasNode(TextUtil.relativizePath(filename)));
    }
 
+   /**
+    * Testing {@link WebDavServiceImpl} MOVE method for correct response 
+    * building. According to 'RFC-2616' it is expected to contain 'location' header.
+    * More info is introduced <a href=http://tools.ietf.org/html/rfc2616#section-14.30>here</a>.
+    * @throws Exception
+    */
+   public void testLocationHeaderInMoveResponse() throws Exception
+   {
+      String content = TestUtils.getFileContent();
+      String filename = TestUtils.getFileName();
+      InputStream inputStream = new ByteArrayInputStream(content.getBytes());
+      TestUtils.addContent(session, filename, inputStream, defaultFileNodeType, "");
+      String destFilename = TestUtils.getFileName();
+
+      // prepare headers
+      MultivaluedMap<String, String> headers = new MultivaluedMapImpl();
+      headers.add(ExtHttpHeaders.DESTINATION, getPathWS() + destFilename);
+
+      // execute the query
+      ContainerResponse response = service(WebDAVMethods.MOVE, getPathWS() + filename, "", headers, null);
+      // check if operation completed successfully, we expect a new resource to be created
+      assertEquals(HTTPStatus.CREATED, response.getStatus());
+
+      // check if 'CREATED' response contains 'LOCATION' header
+      assertTrue(response.getHttpHeaders().containsKey(ExtHttpHeaders.LOCATION));
+      // check if 'CREATED' response 'LOCATION' header contains correct location path
+      assertTrue(response.getHttpHeaders().get(ExtHttpHeaders.LOCATION).toString().contains(getPathWS() + destFilename));
+   }
+
    @Override
    protected String getRepositoryName()
    {

Modified: jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java
===================================================================
--- jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java	2011-01-31 17:03:05 UTC (rev 3906)
+++ jcr/trunk/exo.jcr.component.webdav/src/test/java/org/exoplatform/services/jcr/webdav/command/TestPut.java	2011-02-01 10:23:16 UTC (rev 3907)
@@ -22,6 +22,7 @@
 import org.exoplatform.services.jcr.impl.core.PropertyImpl;
 import org.exoplatform.services.jcr.webdav.BaseStandaloneTest;
 import org.exoplatform.services.jcr.webdav.WebDavConstants.WebDAVMethods;
+import org.exoplatform.services.jcr.webdav.WebDavServiceImpl;
 import org.exoplatform.services.jcr.webdav.util.TextUtil;
 import org.exoplatform.services.jcr.webdav.utils.TestUtils;
 import org.exoplatform.services.rest.ExtHttpHeaders;
@@ -144,6 +145,29 @@
       assertEquals(headers.getFirst(HttpHeaders.CONTENT_TYPE), property.getString());
    }
 
+   /**
+    * Testing {@link WebDavServiceImpl} PUT method for correct response 
+    * building. According to 'RFC-2616' it is expected to contain 'location' header.
+    * More info is introduced <a href=http://tools.ietf.org/html/rfc2616#section-14.30>here</a>.
+    * @throws Exception
+    */
+   public void testLocationHeaderInPutResponse() throws Exception
+   {
+      String content = TestUtils.getFileContent();
+      String filename = TestUtils.getFileName();
+
+      // now we execute the query
+      ContainerResponse containerResponse =
+         service(WebDAVMethods.PUT, getPathWS() + filename, "", null, content.getBytes());
+      // check if operation completed successfully, we expect a new resource to be created
+      assertEquals(HTTPStatus.CREATED, containerResponse.getStatus());
+      // check if response 'CREATED' contains 'LOCATION' header
+      assertTrue(containerResponse.getHttpHeaders().containsKey(ExtHttpHeaders.LOCATION));
+      // check if 'CREATED' response 'LOCATION' header contains correct location path
+      assertTrue(containerResponse.getHttpHeaders().get(ExtHttpHeaders.LOCATION).toString()
+         .contains(getPathWS() + filename));
+   }
+
    @Override
    protected String getRepositoryName()
    {



More information about the exo-jcr-commits mailing list