incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r598351 - in /incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration: ./ microjax/
Date Mon, 26 Nov 2007 17:16:05 GMT
Author: bdelacretaz
Date: Mon Nov 26 09:16:04 2007
New Revision: 598351

URL: http://svn.apache.org/viewvc?rev=598351&view=rev
Log:
SLING-92, integration tests for MicrojaxPostServlet

Added:
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletCreateTest.java
  (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletDeleteTest.java
  (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletOrderTest.java
  (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletUpdateTest.java
  (with props)
Modified:
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/JsonRenderingTest.java
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/JsonRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/JsonRenderingTest.java?rev=598351&r1=598350&r2=598351&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/JsonRenderingTest.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/JsonRenderingTest.java
Mon Nov 26 09:16:04 2007
@@ -17,14 +17,9 @@
 package org.apache.sling.microsling.integration;
 
 import java.io.IOException;
-import java.io.PrintWriter;
-import java.io.StringWriter;
 import java.util.HashMap;
 import java.util.Map;
 
-import org.mozilla.javascript.Context;
-import org.mozilla.javascript.ScriptableObject;
-
 /** Test creating Nodes and rendering them in JSON */
 public class JsonRenderingTest extends MicroslingHttpTestBase {
 
@@ -43,32 +38,6 @@
         final Map<String,String> props = new HashMap<String,String>();
         props.put("text", testText);
         jsonUrl = testClient.createNode(url, props) + ".json";
-    }
-    
-    /** Evaluate given code using given jsonData as the "data" object */ 
-    protected void assertJavascript(String expectedOutput, String jsonData, String code)
throws IOException {
-        // build the code, something like
-        //  data = <jsonData> ;
-        //  <code>
-        final String jsCode = "data=" + jsonData + ";\n" + code;
-        final Context rhinoContext = Context.enter();
-        final ScriptableObject scope = rhinoContext.initStandardObjects();
-
-        // execute the script, out script variable maps to sw 
-        final StringWriter sw = new StringWriter();
-        final PrintWriter pw = new PrintWriter(sw, true);
-        ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
-        final int lineNumber = 1;
-        final Object securityDomain = null;
-        rhinoContext.evaluateString(scope, jsCode, getClass().getSimpleName(), 
-                lineNumber, securityDomain);
-        
-        // check script output
-        pw.flush();
-        final String result = sw.toString().trim();
-        if(!result.equals(expectedOutput)) {
-            fail("Expected '" + expectedOutput + "' but got '" + result + "' for script='"
+ jsCode + "'");
-        }
     }
     
     /** test our assertJavascript method with static json */ 

Modified: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java?rev=598351&r1=598350&r2=598351&view=diff
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
(original)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/MicroslingHttpTestBase.java
Mon Nov 26 09:16:04 2007
@@ -18,21 +18,30 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.List;
+import java.util.Map;
 
 import junit.framework.TestCase;
 
 import org.apache.commons.httpclient.Credentials;
 import org.apache.commons.httpclient.Header;
 import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpException;
+import org.apache.commons.httpclient.NameValuePair;
 import org.apache.commons.httpclient.UsernamePasswordCredentials;
 import org.apache.commons.httpclient.auth.AuthScope;
 import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.commons.httpclient.methods.PostMethod;
 import org.apache.sling.microsling.integration.helpers.MicroslingIntegrationTestClient;
+import org.mozilla.javascript.Context;
+import org.mozilla.javascript.ScriptableObject;
 
 /** Base class for HTTP-based microsling integration tests */
-class MicroslingHttpTestBase extends TestCase {
+public class MicroslingHttpTestBase extends TestCase {
     public static final String HTTP_BASE_URL = System.getProperty("microsling.http.server.url");
     public static final String WEBDAV_BASE_URL = System.getProperty("microsling.webdav.server.url");
     
@@ -86,6 +95,25 @@
         assertHttpStatus(urlString, expectedStatusCode, null);
     }
     
+    /** Execute a POST request and check status */
+    protected void assertPostStatus(String url, int expectedStatusCode, List<NameValuePair>
postParams, String assertMessage)
+    throws IOException {
+        final PostMethod post = new PostMethod(url);
+        post.setFollowRedirects(false);
+        
+        if(postParams!=null) {
+            final NameValuePair [] nvp = {};
+            post.setRequestBody(postParams.toArray(nvp));
+        }
+        
+        final int status = httpClient.executeMethod(post);
+        if(assertMessage == null) {
+            assertEquals(expectedStatusCode, status);
+        } else {
+            assertEquals(assertMessage, expectedStatusCode, status);
+        }
+    }
+    
     /** retrieve the contents of given URL and assert its content type
      * @throws IOException
      * @throws HttpException */
@@ -122,4 +150,29 @@
         return url;
     }
 
+    /** Evaluate given code using given jsonData as the "data" object */ 
+    protected void assertJavascript(String expectedOutput, String jsonData, String code)
throws IOException {
+        // build the code, something like
+        //  data = <jsonData> ;
+        //  <code>
+        final String jsCode = "data=" + jsonData + ";\n" + code;
+        final Context rhinoContext = Context.enter();
+        final ScriptableObject scope = rhinoContext.initStandardObjects();
+
+        // execute the script, out script variable maps to sw 
+        final StringWriter sw = new StringWriter();
+        final PrintWriter pw = new PrintWriter(sw, true);
+        ScriptableObject.putProperty(scope, "out", Context.javaToJS(pw, scope));
+        final int lineNumber = 1;
+        final Object securityDomain = null;
+        rhinoContext.evaluateString(scope, jsCode, getClass().getSimpleName(), 
+                lineNumber, securityDomain);
+        
+        // check script output
+        pw.flush();
+        final String result = sw.toString().trim();
+        if(!result.equals(expectedOutput)) {
+            fail("Expected '" + expectedOutput + "' but got '" + result + "' for script='"
+ jsCode + "'");
+        }
+    }
 }

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletCreateTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletCreateTest.java?rev=598351&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletCreateTest.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletCreateTest.java
Mon Nov 26 09:16:04 2007
@@ -0,0 +1,100 @@
+/*
+ * 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.microsling.integration.microjax;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.microsling.integration.MicroslingHttpTestBase;
+
+/** Test node creation via the MicrojaxPostServlet */
+public class PostServletCreateTest extends MicroslingHttpTestBase {
+    public static final String TEST_BASE_PATH = "/microjax-tests";
+    private String postUrl;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
+    }
+    
+   public void testPostPathIsUnique() throws IOException {
+        assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND,
+                "Path must not exist before test: " + postUrl);
+    }
+
+    public void testCreateNode() throws IOException {
+        final String location = testClient.createNode(postUrl + "/*", null);
+        assertHttpStatus(location, HttpServletResponse.SC_OK,
+                "POST must redirect to created resource (" + location + ")");
+        assertTrue("Node (" + location + ") must have generated name",
+                !location.endsWith("/*"));
+        assertTrue("Node (" + location + ") must created be under POST URL (" + postUrl +
")",
+                location.contains(postUrl + "/"));
+    }
+    
+    public void testCreateNodeAtSpecificUrl() throws IOException {
+        final String specifiedLocation = postUrl + "/specified-location";
+        final String location = testClient.createNode(specifiedLocation, null);
+        assertHttpStatus(location, HttpServletResponse.SC_OK,
+                "POST must redirect to created resource (" + location + ")");
+        assertTrue("Node (" + location + ") must created at given URL (" + specifiedLocation
+ ")",
+                location.equals(specifiedLocation));
+    }
+    
+    /** Create a node with some data, and check that data */
+    public void testCreateWithData() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("a","123");
+        props.put("b","456");
+        final String createdNodeUrl = testClient.createNode(postUrl + "/*", props);
+        final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123456", content, "out.println(data.a + data.b)");
+    }
+    
+    /** Use the default "save prefix" on some parameters, and check that only those
+     *  who have the prefix are saved.
+     */
+    public void testDefaultSavePrefix() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("./a","123");
+        props.put("./b","456");
+        props.put("c","not saved");
+        final String createdNodeUrl = testClient.createNode(postUrl + "/*", props);
+        final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123456", content, "out.println(data.a + data.b)");
+        assertJavascript("undefined", content, "out.println(typeof data.c)");
+    }
+    
+    /** Use a custom "save prefix" on some parameters, and check that only those
+     *  who have the prefix are saved.
+     */
+    public void testCustomSavePrefix() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("++a","123");
+        props.put("++b","456");
+        props.put("c","not saved");
+        props.put("ujax_saveParamPrefix","++");
+        final String createdNodeUrl = testClient.createNode(postUrl + "/*", props);
+        final String content = getContent(createdNodeUrl + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123456", content, "out.println(data.a + data.b)");
+        assertJavascript("undefined", content, "out.println(typeof data.c)");
+    }
+ }
\ No newline at end of file

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletCreateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletCreateTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletDeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletDeleteTest.java?rev=598351&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletDeleteTest.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletDeleteTest.java
Mon Nov 26 09:16:04 2007
@@ -0,0 +1,84 @@
+/*
+ * 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.microsling.integration.microjax;
+
+import java.io.IOException;
+import java.util.LinkedList;
+import java.util.List;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.httpclient.NameValuePair;
+import org.apache.sling.microsling.integration.MicroslingHttpTestBase;
+
+/** Test node deletion via the MicrojaxPostServlet */
+public class PostServletDeleteTest extends MicroslingHttpTestBase {
+    public static final String TEST_BASE_PATH = "/microjax-tests";
+    private String postUrl;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
+    }
+    
+    public void testPostPathIsUnique() throws IOException {
+        assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND,
+                "Path must not exist before test: " + postUrl);
+    }
+
+    public void testDelete() throws IOException {
+        final String urlA = testClient.createNode(postUrl + "/*", null);
+        final String urlB = testClient.createNode(postUrl + "/*", null);
+        final String urlC = testClient.createNode(postUrl + "/*", null);
+        final String urlD = testClient.createNode(postUrl + "/specific-location/for-delete",
null);
+        
+        // initially all nodes must be found
+        assertHttpStatus(urlA, HttpServletResponse.SC_OK, "A must initially exist");
+        assertHttpStatus(urlB, HttpServletResponse.SC_OK, "B must initially exist");
+        assertHttpStatus(urlC, HttpServletResponse.SC_OK, "C must initially exist");
+        assertHttpStatus(urlD, HttpServletResponse.SC_OK, "D must initially exist");
+        
+        // delete one and check
+        final List <NameValuePair> params = new LinkedList<NameValuePair> ();
+        final String deleteCmd = "ujax_delete";
+        params.add(new NameValuePair(deleteCmd,urlToNodePath(urlA)));
+        assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Delete must return status
OK (1)");
+        assertHttpStatus(urlA, HttpServletResponse.SC_NOT_FOUND, "A must be deleted (1)");
+        assertHttpStatus(urlB, HttpServletResponse.SC_OK, "B must still exist");
+        assertHttpStatus(urlC, HttpServletResponse.SC_OK, "C must still exist");
+        assertHttpStatus(urlD, HttpServletResponse.SC_OK, "D must still exist");
+        
+        // delete the others with one request and check
+        params.clear();
+        params.add(new NameValuePair(deleteCmd,urlToNodePath(urlB)));
+        params.add(new NameValuePair(deleteCmd,urlToNodePath(urlC)));
+        params.add(new NameValuePair(deleteCmd,urlToNodePath(urlD)));
+        assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Delete must return status
OK (2)");
+        assertHttpStatus(urlA, HttpServletResponse.SC_NOT_FOUND, "A must be deleted (2)");
+        assertHttpStatus(urlB, HttpServletResponse.SC_NOT_FOUND, "B must be deleted (2)");
+        assertHttpStatus(urlC, HttpServletResponse.SC_NOT_FOUND, "C must be deleted (2)");
+        assertHttpStatus(urlD, HttpServletResponse.SC_NOT_FOUND, "D must be deleted (2)");
+        
+        // attempting to delete non-existing nodes is ok
+        assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Repeated delete must return
status OK (3)");
+    }
+    
+    private String urlToNodePath(String url) {
+        return url.substring(HTTP_BASE_URL.length());
+    }
+}
\ No newline at end of file

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletDeleteTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletDeleteTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletOrderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletOrderTest.java?rev=598351&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletOrderTest.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletOrderTest.java
Mon Nov 26 09:16:04 2007
@@ -0,0 +1,93 @@
+/*
+ * 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.microsling.integration.microjax;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.microsling.integration.MicroslingHttpTestBase;
+
+/** Test the order option for node creation via the MicrojaxPostServlet */
+public class PostServletOrderTest extends MicroslingHttpTestBase {
+    public static final String TEST_BASE_PATH = "/microjax-tests";
+    private String postUrl;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
+    }
+    
+   public void testPostPathIsUnique() throws IOException {
+        assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND,
+                "Path must not exist before test: " + postUrl);
+    }
+
+    /** Create several nodes without the order option, and check ordering */
+    public void testStandardOrder() throws IOException {
+        final String [] nodeUrl = new String[4];
+        nodeUrl[0] = testClient.createNode(postUrl + "/*", null);
+        nodeUrl[1] = testClient.createNode(postUrl + "/*", null);
+        nodeUrl[2] = testClient.createNode(postUrl + "/*", null);
+        nodeUrl[3] = testClient.createNode(postUrl + "/*", null);
+        
+        final String [] nodeName = new String[nodeUrl.length];
+        for(int i = 0;  i < nodeUrl.length; i++) {
+            nodeName[i] = nodeUrl[i].substring(nodeUrl[i].lastIndexOf('/') + 1);
+        }
+
+        // check that nodes appear in creation order in their parent's list of children
+        final String json = getContent(postUrl + ".json?slingItemDumpRecursionLevel=2", CONTENT_TYPE_JSON);
+        for(int i = 0;  i < nodeUrl.length - 1; i++) {
+            final int posA = json.indexOf(nodeName[i]);
+            final int posB = json.indexOf(nodeName[i + 1]);
+            if(posB <= posA) {
+                fail("Expected '" + nodeName[i] + " to come before " + nodeName[i + 1] +
" in JSON data '" + json + "'");
+            }
+        }
+    }
+    
+    /** Create several nodes with the order option, and check ordering */
+    public void testZeroOrder() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("ujax_order","0");
+        
+        final String [] nodeUrl = new String[4];
+        nodeUrl[0] = testClient.createNode(postUrl + "/*", props);
+        nodeUrl[1] = testClient.createNode(postUrl + "/*", props);
+        nodeUrl[2] = testClient.createNode(postUrl + "/*", props);
+        nodeUrl[3] = testClient.createNode(postUrl + "/*", props);
+        
+        final String [] nodeName = new String[nodeUrl.length];
+        for(int i = 0;  i < nodeUrl.length; i++) {
+            nodeName[i] = nodeUrl[i].substring(nodeUrl[i].lastIndexOf('/') + 1);
+        }
+
+        // check that nodes appear in reverse creation order in their parent's list of children
+        final String json = getContent(postUrl + ".json?slingItemDumpRecursionLevel=2", CONTENT_TYPE_JSON);
+        for(int i = 0;  i < nodeUrl.length - 1; i++) {
+            final int posA = json.indexOf(nodeName[i]);
+            final int posB = json.indexOf(nodeName[i + 1]);
+            if(posA <= posB) {
+                fail("Expected '" + nodeName[i] + " to come after " + nodeName[i + 1] + "
in JSON data '" + json + "'");
+            }
+        }
+    }
+ }
\ No newline at end of file

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletOrderTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletOrderTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletUpdateTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletUpdateTest.java?rev=598351&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletUpdateTest.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletUpdateTest.java
Mon Nov 26 09:16:04 2007
@@ -0,0 +1,101 @@
+/*
+ * 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.microsling.integration.microjax;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.sling.microsling.integration.MicroslingHttpTestBase;
+
+/** Test node updates via the MicrojaxPostServlet */
+public class PostServletUpdateTest extends MicroslingHttpTestBase {
+    public static final String TEST_BASE_PATH = "/microjax-tests";
+    private String postUrl;
+    
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+        postUrl = HTTP_BASE_URL + TEST_BASE_PATH + "/" + System.currentTimeMillis();
+    }
+    
+   public void testPostPathIsUnique() throws IOException {
+        assertHttpStatus(postUrl, HttpServletResponse.SC_NOT_FOUND,
+                "Path must not exist before test: " + postUrl);
+    }
+
+    public void testUpdateWithChanges() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("./a","123");
+        props.put("./b","456");
+        
+        final String location = testClient.createNode(postUrl + "/*", props);
+        String content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123456", content, "out.println(data.a + data.b)");
+        
+        props.put("./a","789");
+        // the testClient method is called createNode but all it does is a POST,
+        // so it can be used for updates as well
+        final String newLocation = testClient.createNode(location, props);
+        assertEquals("Location must not changed after POST to existing node",location,newLocation);
+        content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("789456", content, "out.println(data.a + data.b)");
+    }
+    
+    public void testUpdateNoChanges() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("./a","123");
+        props.put("./b","456");
+        
+        final String location = testClient.createNode(postUrl + "/*", props);
+        String content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123456", content, "out.println(data.a + data.b)");
+        
+        props.clear();
+        // the testClient method is called createNode but all it does is a POST,
+        // so it can be used for updates as well
+        final String newLocation = testClient.createNode(location, props);
+        assertEquals("Location must not changed after POST to existing node",location,newLocation);
+        content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123456", content, "out.println(data.a + data.b)");
+    }
+    
+    public void testUpdateSomeChanges() throws IOException {
+        final Map <String, String> props = new HashMap <String, String> ();
+        props.put("./a","123");
+        props.put("./b","456");
+        props.put("C","not stored");
+        
+        final String location = testClient.createNode(postUrl + "/*", props);
+        String content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123456", content, "out.println(data.a + data.b)");
+        
+        props.clear();
+        props.put("./b","457");
+        props.put("C","still not stored");
+        
+        // the testClient method is called createNode but all it does is a POST,
+        // so it can be used for updates as well
+        final String newLocation = testClient.createNode(location, props);
+        assertEquals("Location must not changed after POST to existing node",location,newLocation);
+        content = getContent(location + ".json", CONTENT_TYPE_JSON);
+        assertJavascript("123457", content, "out.println(data.a + data.b)");
+    }
+    
+ }
\ No newline at end of file

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletUpdateTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/microjax/PostServletUpdateTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message