You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by fm...@apache.org on 2008/02/22 11:31:15 UTC

svn commit: r630143 - in /incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest: HttpTestBase.java JsonRenderingTest.java helpers/UslingIntegrationTestClient.java

Author: fmeschbe
Date: Fri Feb 22 02:31:02 2008
New Revision: 630143

URL: http://svn.apache.org/viewvc?rev=630143&view=rev
Log:
SLING-263 Enhance tests to use UTF-8 as character encoding instead of
ISO-8859-1 which might break tests. Also enhance JsonRenderingTest for
accented characters with non-latin1 characters.

Modified:
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java?rev=630143&r1=630142&r2=630143&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/HttpTestBase.java Fri Feb 22 02:31:02 2008
@@ -46,8 +46,8 @@
 
 /** Base class for HTTP-based Sling Launchpad integration tests */
 public class HttpTestBase extends TestCase {
-    public static final String HTTP_BASE_URL = System.getProperty("launchpad.http.server.url");
-    public static final String WEBDAV_BASE_URL = System.getProperty("launchpad.webdav.server.url");
+    public static final String HTTP_BASE_URL = System.getProperty("launchpad.http.server.url", "http://localhost:8888");
+    public static final String WEBDAV_BASE_URL = System.getProperty("launchpad.webdav.server.url", "http://localhost:8888/dav/default");
 
     /** base path for test files */
     public static final String TEST_PATH = "/launchpad-integration-tests";
@@ -65,7 +65,7 @@
     protected HttpClient httpClient;
 
     private static Boolean slingStartupOk;
-
+    
     /** Class that creates a test node under the given parentPath, and
      *  stores useful values for testing. Created for JspScriptingTest,
      *  older test classes do not use it, but it might simplify them.

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java?rev=630143&r1=630142&r2=630143&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/JsonRenderingTest.java Fri Feb 22 02:31:02 2008
@@ -16,139 +16,161 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
-import org.apache.sling.ujax.UjaxPostServlet;
-
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.servlet.http.HttpServletResponse;
 
+import org.apache.sling.ujax.UjaxPostServlet;
+
 /** Test creating Nodes and rendering them in JSON */
 public class JsonRenderingTest extends HttpTestBase {
 
-    private String postUrl; 
+    private String postUrl;
+
     private String testText;
+
     private String jsonUrl;
+
     private String createdNodeUrl;
-    
+
     @Override
     protected void setUp() throws Exception {
         super.setUp();
-        
+
         // set test values
         testText = "This is a test " + System.currentTimeMillis();
-        
-        // create the test node, under a path that's specific to this class to allow collisions
-        postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "_" + System.currentTimeMillis() + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
-        final Map<String,String> props = new HashMap<String,String>();
+
+        // create the test node, under a path that's specific to this class to
+        // allow collisions
+        postUrl = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "_"
+            + System.currentTimeMillis()
+            + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
+        final Map<String, String> props = new HashMap<String, String>();
         props.put("text", testText);
         createdNodeUrl = testClient.createNode(postUrl, props);
         jsonUrl = createdNodeUrl + ".json";
     }
-    
-    /** test our assertJavascript method with static json */ 
+
+    /** test our assertJavascript method with static json */
     public void testAssertJavascript() throws IOException {
         final String json = "{ 'a' : '123', 'b' : '456' }";
-        assertJavascript("123456", json ,"out.println(data.a + data.b)");
+        assertJavascript("123456", json, "out.println(data.a + data.b)");
     }
-    
+
     public void testNonRecursive() throws IOException {
         final String json = getContent(jsonUrl, CONTENT_TYPE_JSON);
-        assertJavascript(testText, json ,"out.println(data.text)");
+        assertJavascript(testText, json, "out.println(data.text)");
     }
-    
-    /**  Create a node with children, verify that we get them back in JSON format */ 
+
+    /** Create a node with children, verify that we get them back in JSON format */
     public void testRecursiveOneLevel() throws IOException {
-        final Map<String,String> props = new HashMap<String,String>();
+        final Map<String, String> props = new HashMap<String, String>();
         props.put("text", testText);
-        
+
         final String parentNodeUrl = testClient.createNode(postUrl, props);
-        final String [] children = { "A", "B", "C" };
-        for(String child : children) {
+        final String[] children = { "A", "B", "C" };
+        for (String child : children) {
             props.put("child", child);
             testClient.createNode(parentNodeUrl + "/" + child, props);
         }
-        
-        final String json = getContent(parentNodeUrl + ".1.json", CONTENT_TYPE_JSON);
+
+        final String json = getContent(parentNodeUrl + ".1.json",
+            CONTENT_TYPE_JSON);
         assertJavascript(testText, json, "out.print(data.text)");
-        for(String child : children) {
-            assertJavascript(child, json, "out.print(data['" + child + "'].child)");
-            assertJavascript(testText, json, "out.print(data['" + child + "'].text)");
+        for (String child : children) {
+            assertJavascript(child, json, "out.print(data['" + child
+                + "'].child)");
+            assertJavascript(testText, json, "out.print(data['" + child
+                + "'].text)");
         }
     }
-    
-    /**  Create a node with children, verify that we do not get them back in 
-     *   JSON format if using recursion level=0 */ 
+
+    /**
+     * Create a node with children, verify that we do not get them back in JSON
+     * format if using recursion level=0
+     */
     public void testRecursiveZeroLevels() throws IOException {
-        final Map<String,String> props = new HashMap<String,String>();
+        final Map<String, String> props = new HashMap<String, String>();
         props.put("text", testText);
-        
+
         final String parentNodeUrl = testClient.createNode(postUrl, props);
-        final String [] children = { "A", "B", "C" };
-        for(String child : children) {
+        final String[] children = { "A", "B", "C" };
+        for (String child : children) {
             props.put("child", child);
             testClient.createNode(parentNodeUrl + "/" + child, props);
         }
-        
+
         // .json and .0.json must both return 0 levels
-        final String [] extensions = { ".json", ".0.json" };
-        for(String extension : extensions) {
-            final String json = getContent(parentNodeUrl + extension, CONTENT_TYPE_JSON);
+        final String[] extensions = { ".json", ".0.json" };
+        for (String extension : extensions) {
+            final String json = getContent(parentNodeUrl + extension,
+                CONTENT_TYPE_JSON);
             assertJavascript(testText, json, "out.print(data.text)");
-            for(String child : children) {
+            for (String child : children) {
                 final String testInfo = "extension: " + extension;
-                assertJavascript("undefined", json, "out.print(typeof data['" + child + "'])", testInfo);
+                assertJavascript("undefined", json, "out.print(typeof data['"
+                    + child + "'])", testInfo);
             }
         }
+
     }
-    
+
     /** Test the "infinity" recursion level */
     public void testRecursiveInfinity() throws IOException {
-        final Map<String,String> props = new HashMap<String,String>();
+        final Map<String, String> props = new HashMap<String, String>();
         props.put("text", testText);
         props.put("a/b/c/d/e/f/g/h/i/j/k/l/m/n/o/p/q/r/s/t/u/v/w/x/y", "yes");
         final String url = testClient.createNode(postUrl, props);
-        final String json = getContent(url + ".infinity.json", CONTENT_TYPE_JSON);
+        final String json = getContent(url + ".infinity.json",
+            CONTENT_TYPE_JSON);
         assertJavascript(testText, json, "out.print(data.text)");
-        assertJavascript("yes", json, "out.print(data.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y)");
+        assertJavascript("yes", json,
+            "out.print(data.a.b.c.d.e.f.g.h.i.j.k.l.m.n.o.p.q.r.s.t.u.v.w.x.y)");
     }
-    
+
     public void testInvalidLevel() throws IOException {
-        assertHttpStatus(createdNodeUrl + ".notAnIntegerOnPurpose.json", HttpServletResponse.SC_BAD_REQUEST);
+        assertHttpStatus(createdNodeUrl + ".notAnIntegerOnPurpose.json",
+            HttpServletResponse.SC_BAD_REQUEST);
     }
-    
+
     public void testEscapedStrings() throws IOException {
-        final Map<String,String> props = new HashMap<String,String>();
+        final Map<String, String> props = new HashMap<String, String>();
         props.put("dq", "Some text with \"double quotes\"");
         props.put("sq", "Some text with 'single quotes'");
         props.put("cb", "Some text with {curly brackets}");
         props.put("sb", "Some text with [square brackets]");
         props.put("eol", "Some text with end\nof\nlines\nand\ttabs");
-        props.put("html", "Some text with <body class=\"black\" mode=\'none yet\'/> html-like tags");
+        props.put("html",
+            "Some text with <body class=\"black\" mode=\'none yet\'/> html-like tags");
         props.put("bs", "Some text with \\backslashes \\here and \\\"there\"");
-        
+
         final String location = testClient.createNode(postUrl, props);
         final String json = getContent(location + ".json", CONTENT_TYPE_JSON);
-        
-        int counter=0;
-        for(String key : props.keySet()) {
+
+        int counter = 0;
+        for (String key : props.keySet()) {
             counter++;
-            assertJavascript(props.get(key),json,"out.println(data." + key + ")");
+            assertJavascript(props.get(key), json, "out.println(data." + key
+                + ")");
         }
-        assertEquals("All tests have been run",counter,props.size());
     }
-    
+
     public void testAccentedStrings() throws IOException {
-        final Map<String,String> props = new HashMap<String,String>();
-        props.put("a", "Les amis en \u000C9t\u000C9 au ch\u000Eteau");
-        props.put("b", "The \u000B0 degree sign and \u000F5 ntilde");
-        
-        final String location = testClient.createNode(postUrl, props);
+        final Map<String, String> props = new HashMap<String, String>();
+        props.put("a", "Les amis en \u00E9t\u00E9 au ch\u00E2teau");
+        props.put("b", "The \u00B0 degree sign and \u00F1 ntilde");
+        props.put("c", "The \u0429 cyrillic capital letter shcha");
+        props.put("d", "The \u13C8 cherokee letter qui");
+
+        final String location = testClient.createNode(postUrl, props, null,
+            true);
         final String json = getContent(location + ".json", CONTENT_TYPE_JSON);
-        
-        for(String key : props.keySet()) {
-            assertJavascript(props.get(key),json,"out.println(data." + key + ")");
+
+        for (String key : props.keySet()) {
+            assertJavascript(props.get(key), json, "out.println(data." + key
+                + ")");
         }
     }
- }
\ No newline at end of file
+}
\ No newline at end of file

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java?rev=630143&r1=630142&r2=630143&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java (original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java Fri Feb 22 02:31:02 2008
@@ -127,13 +127,16 @@
             nodeProperties.put("jcr:created", "");
         }
 
+        // force form encoding to UTF-8, which is what we use to convert the
+        // string parts into stream data
+        nodeProperties.put("FormEncoding", "UTF-8");
 
         if( nodeProperties.size() > 0) {
             if(multiPart) {
                 final List<Part> partList = new ArrayList<Part>();
                 for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
                     if (e.getValue() != null) {
-                        partList.add(new StringPart(e.getKey().toString(), e.getValue().toString()));
+                        partList.add(new StringPart(e.getKey().toString(), e.getValue().toString(), "UTF-8"));
                     }
                 }
                 final Part [] parts = partList.toArray(new Part[partList.size()]);