struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lukaszlen...@apache.org
Subject [18/50] [abbrv] git commit: Uses the possibility to parse parameters as collection
Date Sun, 06 Apr 2014 14:03:31 GMT
Uses the possibility to parse parameters as collection


Project: http://git-wip-us.apache.org/repos/asf/struts/repo
Commit: http://git-wip-us.apache.org/repos/asf/struts/commit/01255fa2
Tree: http://git-wip-us.apache.org/repos/asf/struts/tree/01255fa2
Diff: http://git-wip-us.apache.org/repos/asf/struts/diff/01255fa2

Branch: refs/heads/master
Commit: 01255fa2f836b836e4868668c7be80b68854f951
Parents: a4a7edd
Author: Lukasz Lenart <lukaszlenart@apache.org>
Authored: Sat Mar 22 09:43:22 2014 +0100
Committer: Lukasz Lenart <lukaszlenart@apache.org>
Committed: Sat Mar 22 09:43:22 2014 +0100

----------------------------------------------------------------------
 .../dispatcher/ServletRedirectResult.java       |   6 +-
 .../dispatcher/ServletRedirectResultTest.java   | 109 +++++++++++++++----
 2 files changed, 91 insertions(+), 24 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/struts/blob/01255fa2/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java b/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
index e4347b0..ae25463 100644
--- a/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
+++ b/core/src/main/java/org/apache/struts2/dispatcher/ServletRedirectResult.java
@@ -204,9 +204,9 @@ public class ServletRedirectResult extends StrutsResultSupport implements
Reflec
                 List<String> prohibitedResultParams = getProhibitedResultParams();
                 for (Map.Entry<String, String> e : resultConfigParams.entrySet()) {
                     if (!prohibitedResultParams.contains(e.getKey())) {
-                        String potentialValue = e.getValue() == null ? "" : conditionalParse(e.getValue(),
invocation);
-                        if (!suppressEmptyParameters || ((potentialValue != null) &&
(potentialValue.length() > 0))) {
-                            requestParameters.put(e.getKey(), potentialValue);
+                        Collection<String> values = conditionalParseCollection(e.getValue(),
invocation, suppressEmptyParameters);
+                        if (!suppressEmptyParameters || !values.isEmpty()) {
+                            requestParameters.put(e.getKey(), values);
                         }
                     }
                 }

http://git-wip-us.apache.org/repos/asf/struts/blob/01255fa2/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
----------------------------------------------------------------------
diff --git a/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
b/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
index 5d9bf93..6a9e871 100644
--- a/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
+++ b/core/src/test/java/org/apache/struts2/dispatcher/ServletRedirectResultTest.java
@@ -21,16 +21,24 @@
 
 package org.apache.struts2.dispatcher;
 
-import com.mockobjects.dynamic.C;
-import com.mockobjects.dynamic.Mock;
-import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.ActionProxy;
-import com.opensymphony.xwork2.config.entities.ActionConfig;
-import com.opensymphony.xwork2.config.entities.PackageConfig;
-import com.opensymphony.xwork2.config.entities.ResultConfig;
-import com.opensymphony.xwork2.mock.MockActionInvocation;
+import static javax.servlet.http.HttpServletResponse.SC_SEE_OTHER;
+import static org.easymock.EasyMock.createControl;
+import static org.easymock.EasyMock.createNiceMock;
+import static org.easymock.EasyMock.expect;
+import static org.easymock.EasyMock.replay;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
 import ognl.Ognl;
+
 import org.apache.struts2.ServletActionContext;
 import org.apache.struts2.StrutsInternalTestCase;
 import org.apache.struts2.StrutsStatics;
@@ -40,18 +48,16 @@ import org.easymock.IMocksControl;
 import org.springframework.mock.web.MockHttpServletRequest;
 import org.springframework.mock.web.MockHttpServletResponse;
 
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.util.HashMap;
-import java.util.Map;
-
-import static javax.servlet.http.HttpServletResponse.SC_SEE_OTHER;
-import static org.easymock.EasyMock.createControl;
-import static org.easymock.EasyMock.createNiceMock;
-import static org.easymock.EasyMock.expect;
-import static org.easymock.EasyMock.replay;
+import com.mockobjects.dynamic.C;
+import com.mockobjects.dynamic.Mock;
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.config.entities.ActionConfig;
+import com.opensymphony.xwork2.config.entities.PackageConfig;
+import com.opensymphony.xwork2.config.entities.ResultConfig;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+import com.opensymphony.xwork2.util.ValueStack;
 
 
 /**
@@ -225,6 +231,67 @@ public class ServletRedirectResultTest extends StrutsInternalTestCase
implements
         control.verify();
     }
 
+    public void testIncludeCollectionParameterInResult() throws Exception {
+        List<String> paramValues = new ArrayList<String>();
+        paramValues.add("value 1");
+        paramValues.add("");
+        paramValues.add("value 2");
+        paramValues.add(null);
+
+        ResultConfig resultConfig = new ResultConfig.Builder("", "")
+            .addParam("namespace", "someNamespace")
+            .addParam("param", "${list}")
+            .build();
+
+        ActionContext context = ActionContext.getContext();
+        MockHttpServletRequest req = new MockHttpServletRequest();
+        MockHttpServletResponse res = new MockHttpServletResponse();
+        context.put(ServletActionContext.HTTP_REQUEST, req);
+        context.put(ServletActionContext.HTTP_RESPONSE, res);
+
+        Map<String, ResultConfig> results=  new HashMap<String, ResultConfig>();
+        results.put("myResult", resultConfig);
+
+        ActionConfig actionConfig = new ActionConfig.Builder("", "", "")
+                .addResultConfigs(results).build();
+
+        ServletRedirectResult result = new ServletRedirectResult();
+        result.setLocation("/myNamespace/myAction.action");
+        result.setParse(true);
+        result.setEncode(false);
+        result.setPrependServletContext(false);
+        result.setUrlHelper(new DefaultUrlHelper());
+        result.setSuppressEmptyParameters(true);
+
+        IMocksControl control = createControl();
+        ActionProxy mockActionProxy = control.createMock(ActionProxy.class);
+        ActionInvocation mockInvocation = control.createMock(ActionInvocation.class);
+
+        ValueStack mockValueStack = control.createMock(ValueStack.class);
+        Map<String, Object> mockContext = new HashMap<String, Object>();
+        mockContext.put(ActionContext.CONTAINER, container);
+
+        expect(mockInvocation.getStack()).andReturn(mockValueStack);
+        expect(mockValueStack.getContext()).andReturn(mockContext);
+
+        expect(mockInvocation.getStack()).andReturn(mockValueStack);
+
+        expect(mockValueStack.findValue("list")).andReturn(paramValues); // no asType !!!
+
+        expect(mockInvocation.getProxy()).andReturn(mockActionProxy);
+        expect(mockInvocation.getResultCode()).andReturn("myResult");
+        expect(mockActionProxy.getConfig()).andReturn(actionConfig);
+        expect(mockInvocation.getInvocationContext()).andReturn(context);
+
+        expect(mockValueStack.getContext()).andReturn(mockContext);
+
+        control.replay();
+        result.setActionMapper(container.getInstance(ActionMapper.class));
+        result.execute(mockInvocation);
+        assertEquals("/myNamespace/myAction.action?param=value+1&param=value+2", res.getRedirectedUrl());
+        control.verify();
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         configurationManager.getConfiguration().


Mime
View raw message