Revision: 967
          http://stripes.svn.sourceforge.net/stripes/?rev=967&view=rev
Author:   bengunter
Date:     2008-10-08 02:10:47 +0000 (Wed, 08 Oct 2008)

Log Message:
-----------
Fix for STS-592 from trunk (revision 961)

Revision Links:
--------------
    http://stripes.svn.sourceforge.net/stripes/?rev=961&view=rev

Modified Paths:
--------------
    branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java

Modified: 
branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java
===================================================================
--- branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java  
2008-10-08 02:08:27 UTC (rev 966)
+++ branches/1.5.x/stripes/src/net/sourceforge/stripes/mock/MockRoundtrip.java  
2008-10-08 02:10:47 UTC (rev 967)
@@ -14,15 +14,20 @@
  */
 package net.sourceforge.stripes.mock;
 
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.SortedMap;
+import java.util.TreeMap;
+
+import javax.servlet.Filter;
+
 import net.sourceforge.stripes.action.ActionBean;
 import net.sourceforge.stripes.controller.StripesConstants;
 import net.sourceforge.stripes.controller.StripesFilter;
 import net.sourceforge.stripes.util.CryptoUtil;
 import net.sourceforge.stripes.validation.ValidationErrors;
 
-import javax.servlet.Filter;
-import java.util.List;
-
 /**
  * <p>Mock object that attempts to make it easier to use the other Mock 
objects in this package
  * to interact with Stripes and to interrogate the results.  Everything that 
is done in this class
@@ -111,12 +116,57 @@
      * @param session an instance of MockHttpSession to use for the request
      */
     public MockRoundtrip(MockServletContext context, String actionBeanUrl, 
MockHttpSession session) {
+        // Look for a query string and parse out the parameters if one is 
present
+        String path = actionBeanUrl;
+        SortedMap<String, List<String>> parameters = null;
+        int qmark = actionBeanUrl.indexOf("?");
+        if (qmark > 0) {
+            path = actionBeanUrl.substring(0, qmark);
+            if (qmark < actionBeanUrl.length()) {
+                String query = actionBeanUrl.substring(qmark + 1);
+                if (query != null && query.length() > 0) {
+                    parameters = new TreeMap<String, List<String>>();
+                    for (String kv : query.split("&")) {
+                        String[] parts = kv.split("=");
+                        String key, value;
+                        if (parts.length == 1) {
+                            key = parts[0];
+                            value = null;
+                        }
+                        else if (parts.length == 2) {
+                            key = parts[0];
+                            value = parts[1];
+                        }
+                        else {
+                            key = value = null;
+                        }
+
+                        if (key != null) {
+                            List<String> values = parameters.get(key);
+                            if (values == null)
+                                values = new ArrayList<String>();
+                            values.add(value);
+                            parameters.put(key, values);
+                        }
+                    }
+                }
+            }
+        }
+
         this.context = context;
-        this.request = new MockHttpServletRequest("/" + 
context.getServletContextName(),
-                                                  actionBeanUrl);
+        this.request = new MockHttpServletRequest("/" + 
context.getServletContextName(), path);
         this.request.setSession(session);
         this.response = new MockHttpServletResponse();
         setSourcePage(DEFAULT_SOURCE_PAGE);
+
+        // Add any parameters that were embedded in the given URL
+        if (parameters != null) {
+            for (Map.Entry<String, List<String>> entry : 
parameters.entrySet()) {
+                for (String value : entry.getValue()) {
+                    addParameter(entry.getKey(), value);
+                }
+            }
+        }
     }
 
     /** Get the servlet request object to be used by this round trip */


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/
_______________________________________________
Stripes-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/stripes-development

Reply via email to