incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fmesc...@apache.org
Subject svn commit: r618395 - in /incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest: ./ helpers/ ujax/
Date Mon, 04 Feb 2008 19:41:45 GMT
Author: fmeschbe
Date: Mon Feb  4 11:41:44 2008
New Revision: 618395

URL: http://svn.apache.org/viewvc?rev=618395&view=rev
Log:
SLING-213 Adapt integration tests:
  - UslingIntegrationTestClient:
       * use default ujax: parameters, but do not overwrite test-provided values
       * default status is 200 (ok) now, was 302 (temp redirect)
  - HttpTestBase: Gather messages while waiting for Sling startup in a list
       instead of a Set to keep the order of the messages
  - PostRedirectTest: Adapt to new ujax:redirect semantics
  - PostServletDeleteTest: Adapt to default status 200 (OK)
  - PostServletOrderTest: minor message format

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/PostRedirectTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/helpers/UslingIntegrationTestClient.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java
    incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.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=618395&r1=618394&r2=618395&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
Mon Feb  4 11:41:44 2008
@@ -27,6 +27,7 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
+import java.util.LinkedList;
 
 import junit.framework.TestCase;
 
@@ -104,7 +105,7 @@
         System.err.println("Checking if the required Sling services are started...");
         
         // Try creating a node on server, every 500msec, until ok, with timeout
-        final Set exceptionMessages = new HashSet();
+        final List<String> exceptionMessages = new LinkedList<String>();
         final long maxMsecToWait = 10000L;
         while(!slingStartupOk && (System.currentTimeMillis() < startupTime + maxMsecToWait)
) {
             try {
@@ -116,10 +117,12 @@
         }
         
         if(!slingStartupOk) {
-            fail(
-                    "Server does not seem to be ready, after " + maxMsecToWait + " msec"
-                    + ", got the following Exceptions: " + exceptionMessages
-            );
+            StringBuffer msg = new StringBuffer("Server does not seem to be ready, after
");
+            msg.append(maxMsecToWait).append(" msec, got the following Exceptions:");
+            for (String e: exceptionMessages) {
+                msg.append(e).append("\n");
+            }
+            fail(msg.toString());
         }
         
         System.err.println("Sling services seem to be started, continuing with integration
tests.");

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java?rev=618395&r1=618394&r2=618395&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/PostRedirectTest.java
Mon Feb  4 11:41:44 2008
@@ -22,47 +22,84 @@
 import java.util.HashMap;
 import java.util.Map;
 
-
 /** Test the various redirect options for POST, SLING-126 */
 public class PostRedirectTest extends HttpTestBase {
 
     private String postPath = "CreateNodeTest/" + System.currentTimeMillis();
-    private String postUrl = HTTP_BASE_URL + "/" + postPath + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
-    
+
+    private String postUrl = HTTP_BASE_URL + "/" + postPath
+        + UjaxPostServlet.DEFAULT_CREATE_SUFFIX;
+
     public void testForcedRedirect() throws IOException {
-        final Map<String,String> params = new HashMap<String,String>();
-        params.put("ujax:redirect","http://forced/");
-        final Map<String,String> headers = new HashMap<String,String>();
+        final Map<String, String> params = new HashMap<String, String>();
+        params.put("ujax:redirect", "http://forced/");
+        final Map<String, String> headers = new HashMap<String, String>();
         headers.put("Referer", "http://referer/");
-        
-        final String location = testClient.createNode(postUrl, params, headers, false);
-        assertEquals("With forced redirect and Referer, redirect must be forced","http://forced/",location);
+
+        final String location = testClient.createNode(postUrl, params, headers,
+            false);
+        assertEquals(
+            "With forced redirect and Referer, redirect must be forced",
+            "http://forced/", location);
     }
-    
+
     public void testDefaultRedirect() throws IOException {
-        final String location = testClient.createNode(postUrl, null, null, false);
-        assertTrue(
-                "With no headers or parameters, redirect (" + location 
-                + ") must point to created node (path=" + postPath + ")",
-                location.contains(postPath));
+        final Map<String, String> params = new HashMap<String, String>();
+        params.put("ujax:redirect", null);
+        final String location = testClient.createNode(postUrl, null, null,
+            false);
+        assertTrue("With no headers or parameters, redirect (" + location
+            + ") must point to created node (path=" + postPath + ")",
+            location.contains(postPath));
     }
-    
-    public void testRefererRedirect() throws IOException {
-        final Map<String,String> headers = new HashMap<String,String>();
+
+    public void testMagicStarRedirect() throws IOException {
+        final Map<String, String> params = new HashMap<String, String>();
+        params.put("ujax:redirect", "*");
+        final Map<String, String> headers = new HashMap<String, String>();
         headers.put("Referer", "http://referer/");
-        final String location = testClient.createNode(postUrl, null, headers, true);
-        assertEquals("With Referer, redirect must point to referer","http://referer/",location);
+        final String location = testClient.createNode(postUrl, params, headers,
+            false);
+        assertTrue("With magic star, redirect (" + location
+            + ") must point to created node (path=" + postPath + ")",
+            location.contains(postPath));
     }
-    
-    public void testMagicStarRedirect() throws IOException {
-        final Map<String,String> params = new HashMap<String,String>();
-        params.put("ujax:redirect","*");
-        final Map<String,String> headers = new HashMap<String,String>();
+
+    public void testMagicStarRedirectPrefix() throws IOException {
+        String prefix = "xyz/";
+        final Map<String, String> params = new HashMap<String, String>();
+        params.put("ujax:redirect", prefix + "*");
+        final Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Referer", "http://referer/");
+        final String location = testClient.createNode(postUrl, params, headers,
+            false);
+        assertTrue("With magic star, redirect (" + location
+            + ") must start with prefix " + prefix, location.contains(prefix));
+    }
+
+    public void testMagicStarRedirectSuffix() throws IOException {
+        String suffix = "/xyz.html";
+        final Map<String, String> params = new HashMap<String, String>();
+        params.put("ujax:redirect", "*" + suffix);
+        final Map<String, String> headers = new HashMap<String, String>();
+        headers.put("Referer", "http://referer/");
+        final String location = testClient.createNode(postUrl, params, headers,
+            false);
+        assertTrue("With magic star, redirect (" + location
+            + ") must end with suffix " + suffix, location.endsWith(suffix));
+    }
+
+    public void testMagicStarRedirectPrefixSuffix() throws IOException {
+        String prefix = "xyz/";
+        String suffix = "/xyz.html";
+        final Map<String, String> params = new HashMap<String, String>();
+        params.put("ujax:redirect", prefix + "*" + suffix);
+        final Map<String, String> headers = new HashMap<String, String>();
         headers.put("Referer", "http://referer/");
-        final String location = testClient.createNode(postUrl, params, headers, false);
-        assertTrue(
-                "With magic star, redirect (" + location 
-                + ") must point to created node (path=" + postPath + ")",
-                location.contains(postPath));
+        final String location = testClient.createNode(postUrl, params, headers,
+            false);
+        assertTrue("With magic star, redirect (" + location
+            + ") must start with prefix " + prefix + " and end with suffix "
+            + suffix, location.contains(prefix) && location.endsWith(suffix));
     }
 }

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=618395&r1=618394&r2=618395&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
Mon Feb  4 11:41:44 2008
@@ -19,7 +19,10 @@
 import java.io.File;
 import java.io.IOException;
 import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
 import java.util.Map;
+import java.util.HashMap;
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.DeleteMethod;
@@ -103,18 +106,34 @@
      *  @param multiPart if true, does a multipart POST 
      *  @return the URL that microsling provides to display the node 
      */
-    public String createNode(String url, Map<String,String> nodeProperties, Map<String,String>
requestHeaders,boolean multiPart) 
+    public String createNode(String url, Map<String,String> clientNodeProperties, Map<String,String>
requestHeaders,boolean multiPart) 
     throws IOException {
         final PostMethod post = new PostMethod(url);
         post.setFollowRedirects(false);
+
+        // create a private copy of the properties to not tamper with
+        // the properties of the client
+        Map<String, String> nodeProperties = new HashMap<String, String>();
+
+        // add ujax specific properties
+        nodeProperties.put("ujax:redirect", url);
+        nodeProperties.put("ujax:displayExtension", "");
+        
+        // take over any client provided properties
+        if (clientNodeProperties != null) {
+            nodeProperties.putAll(clientNodeProperties);
+        }
+        
         
         if(nodeProperties != null && nodeProperties.size() > 0) {
             if(multiPart) {
-                final Part [] parts = new Part[nodeProperties.size()];
-                int index = 0;
+                final List<Part> partList = new ArrayList<Part>();
                 for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
-                    parts[index++] = new StringPart(e.getKey().toString(), e.getValue().toString());
+                    if (e.getValue() != null) {
+                        partList.add(new StringPart(e.getKey().toString(), e.getValue().toString()));
+                    }
                 }
+                final Part [] parts = partList.toArray(new Part[partList.size()]);
                 post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
             } else {
                 for(Map.Entry<String,String> e : nodeProperties.entrySet()) {
@@ -161,9 +180,8 @@
         post.setRequestEntity(new MultipartRequestEntity(parts, post.getParams()));
 
         final int status = httpClient.executeMethod(post);
-        if(status!=302) {
-            throw new IOException("Expected status code 302 for POST, got " + status + ",
URL=" + url);
+        if(status!=200) { // fmeschbe: The default ujax status is 200, not 302 
+            throw new IOException("Expected status code 200 for POST, got " + status + ",
URL=" + url);
         }
     }
-
 }

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java?rev=618395&r1=618394&r2=618395&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletDeleteTest.java
Mon Feb  4 11:41:44 2008
@@ -56,7 +56,7 @@
         final List <NameValuePair> params = new LinkedList<NameValuePair> ();
         final String deleteCmd = "ujax:delete";
         params.add(new NameValuePair(deleteCmd,urlToNodePath(urlA)));
-        assertPostStatus(postUrl,HttpServletResponse.SC_MOVED_TEMPORARILY,params,"Delete
must return expected status (3)");
+        assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Delete must return expected
status (3)");
         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");
@@ -67,14 +67,14 @@
         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_MOVED_TEMPORARILY,params,"Delete
must return expected status (2)");
+        assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Delete must return expected
status (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_MOVED_TEMPORARILY,params,"Delete
must return expected status (2)");
+        assertPostStatus(postUrl,HttpServletResponse.SC_OK,params,"Delete must return expected
status (2)");
     }
     
     private String urlToNodePath(String url) {

Modified: incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java?rev=618395&r1=618394&r2=618395&view=diff
==============================================================================
--- incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java
(original)
+++ incubator/sling/trunk/launchpad/launchpad-webapp/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ujax/PostServletOrderTest.java
Mon Feb  4 11:41:44 2008
@@ -60,7 +60,7 @@
             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 + "'");
+                fail("Expected '" + nodeName[i] + "' to come before '" + nodeName[i + 1]
+ "' in JSON data '" + json + "'");
             }
         }
     }



Mime
View raw message