incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jus...@apache.org
Subject svn commit: r1136139 - in /sling/trunk: bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/
Date Wed, 15 Jun 2011 18:20:59 GMT
Author: justin
Date: Wed Jun 15 18:20:58 2011
New Revision: 1136139

URL: http://svn.apache.org/viewvc?rev=1136139&view=rev
Log:
SLING-1741 - only strip off the extension in the case of a non-synthetic resource

Modified:
    sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
    sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCreateTest.java

Modified: sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java?rev=1136139&r1=1136138&r2=1136139&view=diff
==============================================================================
--- sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
(original)
+++ sling/trunk/bundles/servlets/post/src/main/java/org/apache/sling/servlets/post/impl/operations/ModifyOperation.java
Wed Jun 15 18:20:58 2011
@@ -118,6 +118,14 @@ public class ModifyOperation extends Abs
             // resource for part of the path, use request suffix
             suffix = request.getRequestPathInfo().getSuffix();
 
+            if (suffix != null) {
+                // cut off any selectors/extension from the suffix
+                int dotPos = suffix.indexOf('.');
+                if (dotPos > 0) {
+                    suffix = suffix.substring(0, dotPos);
+                }
+            }
+
             // and preset the path buffer with the resource path
             rootPathBuf.append(currentResource.getPath());
 
@@ -127,14 +135,7 @@ public class ModifyOperation extends Abs
         boolean doGenerateName = false;
         if (suffix != null) {
 
-            // cut off any selectors/extension from the suffix
-            int dotPos = suffix.indexOf('.');
-            if ((dotPos > 0)
-                && (!(currentResource instanceof NonExistingResource))) {
-                suffix = suffix.substring(0, dotPos);
-            }
-
-            // and check whether it is a create request (trailing /)
+            // check whether it is a create request (trailing /)
             if (suffix.endsWith(SlingPostConstants.DEFAULT_CREATE_SUFFIX)) {
                 suffix = suffix.substring(0, suffix.length()
                     - SlingPostConstants.DEFAULT_CREATE_SUFFIX.length());

Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCreateTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCreateTest.java?rev=1136139&r1=1136138&r2=1136139&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCreateTest.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletCreateTest.java
Wed Jun 15 18:20:58 2011
@@ -17,6 +17,7 @@
 package org.apache.sling.launchpad.webapp.integrationtest.servlets.post;
 
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
@@ -24,6 +25,7 @@ import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.commons.httpclient.HttpMethod;
 import org.apache.commons.httpclient.NameValuePair;
 import org.apache.sling.commons.testing.integration.HttpTestBase;
 import org.apache.sling.servlets.post.SlingPostConstants;
@@ -195,4 +197,40 @@ public class PostServletCreateTest exten
 		assertPostStatus(postUrl + SlingPostConstants.DEFAULT_CREATE_SUFFIX, HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
postParams, null);
     }
 
+    public void testCreatingNodeUnderFile() throws IOException {
+        final String baseWebDavUrl = WEBDAV_BASE_URL + "/CreateFileTest";
+        testClient.mkdir(baseWebDavUrl);
+
+        final String testFile = "/integration-test/testfile.txt";
+        final InputStream data = getClass().getResourceAsStream(testFile);
+
+        final String webdavUrl = baseWebDavUrl + "/" + System.currentTimeMillis() + ".txt";
+        try {
+            assertNotNull("Local test file " + testFile + " must be found", data);
+
+            // Upload a file via WebDAV, verify, delete and verify
+            assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist before
test");
+            int status = testClient.upload(webdavUrl, data);
+            assertEquals("upload must return status code 201", 201, status);
+            assertHttpStatus(webdavUrl, 200, "Resource " + webdavUrl + " must exist after
upload");
+        } finally {
+            if (data != null) {
+                data.close();
+            }
+        }
+
+        final String childUrl = webdavUrl + "/*";
+
+        List<NameValuePair> list = new ArrayList<NameValuePair>();
+        list.add(new NameValuePair(":nameHint", "child"));
+        list.add(new NameValuePair("prop", "value"));
+        list.add(new NameValuePair("jcr:primaryType", "nt:unstructured"));
+
+        final HttpMethod method = assertPostStatus(childUrl, 500, list,
+                "Response to creating a child under nt:file should fail.");
+        final String body = method.getResponseBodyAsString();
+        assertTrue("Failure should result from a ConstraintViolationException",
+                body.contains("javax.jcr.nodetype.ConstraintViolationException"));
+    }
+
 }
\ No newline at end of file



Mime
View raw message