Author: fmeschbe
Date: Fri Mar 11 12:32:23 2011
New Revision: 1080550

URL: http://svn.apache.org/viewvc?rev=1080550&view=rev
Log:
SLING-1983 Apply patch by Alex Klimetscheck (slightly modified, mostly 
JavaDoc). Thanks alot.

Added:
    
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPatchTest.java
   (with props)
Modified:
    
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDateValuesTest.java

Added: 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPatchTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPatchTest.java?rev=1080550&view=auto
==============================================================================
--- 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPatchTest.java
 (added)
+++ 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPatchTest.java
 Fri Mar 11 12:32:23 2011
@@ -0,0 +1,97 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with this
+ * work for additional information regarding copyright ownership. The ASF
+ * licenses this file to You under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations 
under
+ * the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.servlets.post;
+
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.commons.testing.integration.NameValuePairList;
+import org.apache.sling.servlets.post.SlingPostConstants;
+
+/**
+ * Integration test of the @Patch method in the post servlet.
+ */
+public class PostServletPatchTest extends HttpTestBase {
+    public static final String TEST_BASE_PATH = "/sling-tests";
+    private String postUrl;
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + 
System.currentTimeMillis();
+    }
+
+    public void testPatch() throws Exception {
+        final NameValuePairList props = new NameValuePairList();
+        
+        // 1. create multi-value property
+        props.add("prop@TypeHint", "String[]");
+        props.add("prop", "alpha");
+        props.add("prop", "beta");
+        props.add("prop", "beta");
+        props.add("prop", "gamma");
+        props.add("prop", "epsilon"); // make sure both epsilons are kept, as 
they are not touched
+        props.add("prop", "epsilon"); // by the patch operations below
+        
+        String location = testClient.createNode(postUrl + 
SlingPostConstants.DEFAULT_CREATE_SUFFIX,
+                props, null, false);
+        props.clear();
+        
+        // 2. update mv prop through Patch method
+        props.add("prop@Patch", "true");
+        //props.add("prop@TypeHint", "String[]");
+        props.add("prop", "-beta");  // remove all betas
+        props.add("prop", "+delta"); // add one delta
+        props.add("prop", "+alpha"); // already exists, do not add a second 
alpha
+        
+        testClient.createNode(location, props, null, false);
+        String content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("true", content, "out.println(data.prop.length == 
5)");
+        assertJavascript("alpha", content, "out.println(data.prop[0])");
+        assertJavascript("gamma", content, "out.println(data.prop[1])");
+        assertJavascript("epsilon", content, "out.println(data.prop[2])");
+        assertJavascript("epsilon", content, "out.println(data.prop[3])");
+        assertJavascript("delta", content, "out.println(data.prop[4])");
+    }
+
+    public void testInvalidPatch() throws Exception {
+        final NameValuePairList props = new NameValuePairList();
+        
+        // 1. create multi-value property
+        props.add("prop@TypeHint", "String[]");
+        props.add("prop", "alpha");
+        props.add("prop", "beta");
+        props.add("prop", "gamma");
+        props.add("prop", "delta");
+        
+        String location = testClient.createNode(postUrl + 
SlingPostConstants.DEFAULT_CREATE_SUFFIX,
+                props, null, false);
+        props.clear();
+        
+        // 2. update mv prop through Patch method
+        // but use only invalid values
+        props.add("prop@Patch", "true");
+        props.add("prop", "wrong");
+        props.add("prop", "#noop");
+        
+        testClient.createNode(location, props, null, false);
+        String content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("true", content, "out.println(data.prop.length == 
4)");
+        assertJavascript("alpha", content, "out.println(data.prop[0])");
+        assertJavascript("beta", content, "out.println(data.prop[1])");
+        assertJavascript("gamma", content, "out.println(data.prop[2])");
+        assertJavascript("delta", content, "out.println(data.prop[3])");
+    }
+}

Propchange: 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPatchTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/PostServletPatchTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev Url

Modified: 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDateValuesTest.java
URL: 
http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDateValuesTest.java?rev=1080550&r1=1080549&r2=1080550&view=diff
==============================================================================
--- 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDateValuesTest.java
 (original)
+++ 
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/post/SlingDateValuesTest.java
 Fri Mar 11 12:32:23 2011
@@ -24,6 +24,7 @@ import java.util.Locale;
 import java.util.Map;
 
 import org.apache.sling.commons.testing.integration.HttpTestBase;
+import org.apache.sling.commons.testing.integration.NameValuePairList;
 import org.apache.sling.servlets.post.SlingPostConstants;
 
 /**
@@ -52,26 +53,35 @@ public class SlingDateValuesTest extends
         postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + 
System.currentTimeMillis();
     }
 
-    private void doDateTest(String expected, String input)
+    private void doDateTest(String expected, String input, String expected2, 
String input2)
             throws IOException {
-        final Map<String, String> props = new HashMap<String, String>();
-        props.put("someDate", input);
-        props.put("someDate@TypeHint", "Date");
-
-        final String createdNodeUrl = testClient.createNode(postUrl + 
SlingPostConstants.DEFAULT_CREATE_SUFFIX, props);
+        final NameValuePairList props = new NameValuePairList();
+        props.add("someDate", input);
+        props.add("someDate@TypeHint", "Date");
+
+        props.add("manyDates", input);
+        props.add("manyDates", input2);
+        props.add("manyDates@TypeHint", "Date[]");
+        
+        final String createdNodeUrl = testClient.createNode(postUrl + 
SlingPostConstants.DEFAULT_CREATE_SUFFIX, props, null, false);
         String content = getContent(createdNodeUrl + ".json", 
CONTENT_TYPE_JSON);
 
         // default behaviour writes empty string
         assertJavascript(expected, content, "out.println(data.someDate)");
+        assertJavascript(expected, content, "out.println(data.manyDates[0])");
+        assertJavascript(expected2, content, "out.println(data.manyDates[1])");
     }
 
     public void testDateValues() throws IOException {
         SimpleDateFormat ecmaFmt = new SimpleDateFormat("EEE MMM dd yyyy 
HH:mm:ss 'GMT'Z", Locale.US);
         Date now = new Date();
+        Date date2 = new Date(1000);
         String nowStr = ecmaFmt.format(now);
+        String date2Str = ecmaFmt.format(date2);
         for (SimpleDateFormat fmt: testFormats) {
             String testStr = fmt.format(now);
-            doDateTest(nowStr, testStr);
+            String test2Str = fmt.format(date2);
+            doDateTest(nowStr, testStr, date2Str, test2Str);
         }
     }
 


Reply via email to