struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1139729 [3/3] - in /struts/struts2/trunk: ./ apps/portlet/ apps/portlet/src/main/webapp/WEB-INF/ archetypes/struts2-archetype-dbportlet/src/main/resources/archetype-resources/ archetypes/struts2-archetype-dbportlet/src/main/resources/arche...
Date Sun, 26 Jun 2011 08:30:02 GMT
Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java
Sun Jun 26 08:30:00 2011
@@ -18,27 +18,22 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.struts2.portlet.util;
 
-import static org.apache.struts2.portlet.PortletConstants.*;
+package org.apache.struts2.portlet.util;
 
-import java.io.IOException;
-import java.io.Writer;
 import java.util.HashMap;
 import java.util.Map;
 
 import javax.portlet.PortletMode;
-import javax.portlet.PortletModeException;
-import javax.portlet.PortletSecurityException;
 import javax.portlet.PortletURL;
 import javax.portlet.RenderRequest;
 import javax.portlet.RenderResponse;
 import javax.portlet.WindowState;
-import javax.portlet.WindowStateException;
 
 import junit.framework.TestCase;
 
-import org.easymock.EasyMock;
+import org.apache.struts2.portlet.context.PortletActionContext;
+import org.easymock.MockControl;
 
 import com.opensymphony.xwork2.ActionContext;
 
@@ -50,154 +45,116 @@ public class PortletUrlHelperTest extend
 
     RenderRequest renderRequest;
 
-    MockUrl url;
+    PortletURL url;
+
+    MockControl renderResponseControl;
+
+    MockControl renderRequestControl;
+
+    MockControl portletUrlControl;
 
     public void setUp() throws Exception {
         super.setUp();
 
-        renderResponse = EasyMock.createMock(RenderResponse.class);
-        renderRequest = EasyMock.createMock(RenderRequest.class);
-        url = new MockUrl();
-        
-        EasyMock.expect(renderRequest.getPortletMode()).andReturn(PortletMode.VIEW).anyTimes();
-        EasyMock.expect(renderRequest.getWindowState()).andReturn(WindowState.NORMAL).anyTimes();
+        renderRequestControl = MockControl.createControl(RenderRequest.class);
+        renderResponseControl = MockControl.createControl(RenderResponse.class);
+        portletUrlControl = MockControl.createControl(PortletURL.class);
+
+        renderRequest = (RenderRequest) renderRequestControl.getMock();
+        renderResponse = (RenderResponse) renderResponseControl.getMock();
+        url = (PortletURL) portletUrlControl.getMock();
+
+        renderRequestControl.expectAndDefaultReturn(renderRequest
+                .getPortletMode(), PortletMode.VIEW);
+        renderRequestControl.expectAndDefaultReturn(renderRequest
+                .getWindowState(), WindowState.NORMAL);
 
-        Map<String, String> modeNamespaceMap = new HashMap<String, String>();
+        Map modeNamespaceMap = new HashMap();
         modeNamespaceMap.put("view", "/view");
         modeNamespaceMap.put("edit", "/edit");
         modeNamespaceMap.put("help", "/help");
 
-        Map<String, Object> context = new HashMap<String, Object>();
-        context.put(REQUEST, renderRequest);
-        context.put(RESPONSE, renderResponse);
-        context.put(PHASE, RENDER_PHASE);
-        context.put(MODE_NAMESPACE_MAP, modeNamespaceMap);
+        Map context = new HashMap();
+        context.put(PortletActionContext.REQUEST, renderRequest);
+        context.put(PortletActionContext.RESPONSE, renderResponse);
+        context.put(PortletActionContext.PHASE,
+                PortletActionContext.RENDER_PHASE);
+        context.put(PortletActionContext.MODE_NAMESPACE_MAP, modeNamespaceMap);
 
         ActionContext.setContext(new ActionContext(context));
 
     }
 
     public void testCreateRenderUrlWithNoModeOrState() throws Exception {
-    	EasyMock.expect(renderResponse.createRenderURL()).andReturn(url);
-
-        EasyMock.replay(renderRequest);
-        EasyMock.replay(renderResponse);
+        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
+                url);
 
-        (new PortletUrlHelper()).buildUrl("testAction", null, null,
+        url.setPortletMode(PortletMode.VIEW);
+        url.setWindowState(WindowState.NORMAL);
+        url.setParameters(null);
+        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
+        renderRequestControl.replay();
+        renderResponseControl.replay();
+        portletUrlControl.replay();
+        PortletUrlHelper.buildUrl("testAction", null, null,
                 new HashMap(), null, null, null);
-        assertEquals(PortletMode.VIEW, url.getPortletMode());
-        assertEquals(WindowState.NORMAL, url.getWindowState());
-        assertEquals("testAction", url.getParameterMap().get(ACTION_PARAM)[0]);
-        assertEquals("view", url.getParameterMap().get(MODE_PARAM)[0]);
+        portletUrlControl.verify();
+        renderRequestControl.verify();
+        renderResponseControl.verify();
     }
 
     public void testCreateRenderUrlWithDifferentPortletMode() throws Exception {
-    	EasyMock.expect(renderResponse.createRenderURL()).andReturn(url);
+        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
+                url);
 
-        EasyMock.replay(renderRequest);
-        EasyMock.replay(renderResponse);
-
-        (new PortletUrlHelper()).buildUrl("testAction", null, null,
+        url.setPortletMode(PortletMode.EDIT);
+        url.setWindowState(WindowState.NORMAL);
+        url.setParameters(null);
+        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
+        renderRequestControl.replay();
+        renderResponseControl.replay();
+        portletUrlControl.replay();
+        PortletUrlHelper.buildUrl("testAction", null, null,
                 new HashMap(), null, "edit", null);
-        
-        assertEquals(PortletMode.EDIT, url.getPortletMode());
-        assertEquals(WindowState.NORMAL, url.getWindowState());
-        assertEquals("testAction", url.getParameterMap().get(ACTION_PARAM)[0]);
-        assertEquals("edit", url.getParameterMap().get(MODE_PARAM)[0]);
+        portletUrlControl.verify();
+        renderRequestControl.verify();
+        renderResponseControl.verify();
     }
 
     public void testCreateRenderUrlWithDifferentWindowState() throws Exception {
-    	EasyMock.expect(renderResponse.createRenderURL()).andReturn(url);
-        
-        EasyMock.replay(renderRequest);
-        EasyMock.replay(renderResponse);
-        
-        (new PortletUrlHelper()).buildUrl("testAction", null, null,
+        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
+                url);
+
+        url.setPortletMode(PortletMode.VIEW);
+        url.setWindowState(WindowState.MAXIMIZED);
+        url.setParameters(null);
+        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
+        renderRequestControl.replay();
+        renderResponseControl.replay();
+        portletUrlControl.replay();
+        PortletUrlHelper.buildUrl("testAction", null, null,
                 new HashMap(), null, null, "maximized");
-        
-        assertEquals(PortletMode.VIEW, url.getPortletMode());
-        assertEquals(WindowState.MAXIMIZED, url.getWindowState());
-        assertEquals("testAction", url.getParameterMap().get(ACTION_PARAM)[0]);
-        assertEquals("view", url.getParameterMap().get(MODE_PARAM)[0]);
+        portletUrlControl.verify();
+        renderRequestControl.verify();
+        renderResponseControl.verify();
     }
 
     public void testCreateActionUrl() throws Exception {
-    	EasyMock.expect(renderResponse.createActionURL()).andReturn(url);
-        
-        EasyMock.replay(renderResponse);
-        EasyMock.replay(renderRequest);
-        
-        (new PortletUrlHelper()).buildUrl("testAction", null, null,
-                new HashMap(), "action", null, null);
-        
-        assertEquals(PortletMode.VIEW, url.getPortletMode());
-        assertEquals(WindowState.NORMAL, url.getWindowState());
-        assertEquals("testAction", url.getParameterMap().get(ACTION_PARAM)[0]);
-        assertEquals("view", url.getParameterMap().get(MODE_PARAM)[0]);
-    }
-    
-    @Override
-    public void tearDown() {
-    	EasyMock.verify(renderResponse);
-    	EasyMock.verify(renderRequest);
-    }
-    
-    private class MockUrl implements PortletURL {
+        renderResponseControl.expectAndReturn(renderResponse.createActionURL(),
+                url);
 
-    	private PortletMode portletMode;
-		private WindowState windowState;
-		private Map<String, String[]> parameters;
-    	
-		public PortletMode getPortletMode() {
-			return portletMode;
-		}
-
-		public WindowState getWindowState() {
-			return windowState;
-		}
-
-		public void removePublicRenderParameter(String name) {
-		}
-
-		public void setPortletMode(PortletMode portletMode) throws PortletModeException {
-			this.portletMode = portletMode;
-		}
-
-		public void setWindowState(WindowState windowState) throws WindowStateException {
-			this.windowState = windowState;
-		}
-
-		public void addProperty(String arg0, String arg1) {
-		}
-
-		public Map<String, String[]> getParameterMap() {
-			return parameters;
-		}
-
-		public void setParameter(String name, String value) {
-			parameters.put(name, new String[]{value});
-		}
-
-		public void setParameter(String name, String[] values) {
-			parameters.put(name, values);
-		}
-
-		public void setParameters(Map<String, String[]> parameters) {
-			this.parameters = parameters;
-		}
-
-		public void setProperty(String arg0, String arg1) {
-		}
-
-		public void setSecure(boolean arg0) throws PortletSecurityException {
-		}
-
-		public void write(Writer arg0) throws IOException {
-		}
-
-		public void write(Writer arg0, boolean arg1) throws IOException {
-		}
-    	
+        url.setPortletMode(PortletMode.VIEW);
+        url.setWindowState(WindowState.NORMAL);
+        url.setParameters(null);
+        portletUrlControl.setMatcher(MockControl.ALWAYS_MATCHER);
+        renderRequestControl.replay();
+        renderResponseControl.replay();
+        portletUrlControl.replay();
+        PortletUrlHelper.buildUrl("testAction", null, null,
+                new HashMap(), "action", null, null);
+        portletUrlControl.verify();
+        renderRequestControl.verify();
+        renderResponseControl.verify();
     }
 
 }

Modified: struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
(original)
+++ struts/struts2/trunk/plugins/portlet/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
Sun Jun 26 08:30:00 2011
@@ -18,398 +18,382 @@
  * specific language governing permissions and limitations
  * under the License.
  */
+
 package org.apache.struts2.views.jsp;
 
-import java.util.Arrays;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 
-import javax.portlet.*;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import javax.servlet.jsp.PageContext;
-
-import junit.textui.TestRunner;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletModeException;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletURL;
+import javax.portlet.WindowState;
+import javax.portlet.WindowStateException;
 
-import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.StrutsTestCase;
 import org.apache.struts2.portlet.PortletActionConstants;
+import org.apache.struts2.portlet.servlet.PortletServletRequest;
 import org.apache.struts2.portlet.util.PortletUrlHelper;
-import org.apache.struts2.StrutsStatics;
-import static org.apache.struts2.StrutsStatics.*;
-import org.jmock.Mock;
-import org.jmock.cglib.MockObjectTestCase;
-import org.jmock.core.Constraint;
+import org.springframework.mock.web.portlet.MockPortalContext;
+import org.springframework.mock.web.portlet.MockPortletContext;
+import org.springframework.mock.web.portlet.MockPortletURL;
+import org.springframework.mock.web.portlet.MockRenderRequest;
+import org.springframework.mock.web.portlet.MockRenderResponse;
 
 import com.mockobjects.servlet.MockJspWriter;
+import com.mockobjects.servlet.MockPageContext;
 import com.opensymphony.xwork2.ActionContext;
-import com.opensymphony.xwork2.ActionInvocation;
-import com.opensymphony.xwork2.ActionProxy;
-import static com.opensymphony.xwork2.ActionContext.SESSION;
-import static com.opensymphony.xwork2.ActionContext.PARAMETERS;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+import com.opensymphony.xwork2.mock.MockActionProxy;
 import com.opensymphony.xwork2.util.ValueStack;
-import com.opensymphony.xwork2.util.ValueStackFactory;
 
 /**
  */
 @SuppressWarnings("unchecked")
-public class PortletUrlTagTest extends MockObjectTestCase {
-
-    URLTag tag = new URLTag();
-
-    Mock mockHttpReq = null;
-
-    Mock mockHttpRes = null;
+public class PortletUrlTagTest extends StrutsTestCase {
 
-    Mock mockPortletReq = null;
-
-    Mock mockPortletRes = null;
-
-    Mock mockPageCtx = null;
-
-    Mock mockPortletUrl = null;
-
-    MockJspWriter mockJspWriter = null;
-
-    Mock mockCtx = null;
-
-    ValueStack stack = null;
-
-    public static void main(String[] args) {
-        TestRunner.run(PortletUrlTagTest.class);
-    }
-
-
-    public void setUp() throws Exception {
-        super.setUp();
-
-        Dispatcher du = new Dispatcher(null, new HashMap());
-        du.init();
-        Dispatcher.setInstance(du);
-
-        stack = du.getContainer().getInstance(ValueStackFactory.class).createValueStack();
-        stack.getContext().put(ActionContext.CONTAINER, du.getContainer());
-        ActionContext.setContext(new ActionContext(stack.getContext()));
-        
-
-
-        mockHttpReq = mock(HttpServletRequest.class);
-        mockHttpRes = mock(HttpServletResponse.class);
-        mockPortletReq = mock(RenderRequest.class);
-        mockPortletRes = mock(RenderResponse.class);
-        mockPageCtx = mock(PageContext.class);
-        mockPortletUrl = mock(PortletURL.class);
-        mockJspWriter = new MockJspWriter();
-        mockCtx = mock(PortletContext.class);
-
-        mockPageCtx.stubs().method("getRequest").will(
-                returnValue((HttpServletRequest) mockHttpReq.proxy()));
-        mockPageCtx.stubs().method("getResponse").will(
-                returnValue((HttpServletResponse) mockHttpRes.proxy()));
-        mockPageCtx.stubs().method("getOut").will(returnValue(mockJspWriter));
-
-        mockHttpReq.stubs().method("getScheme").will(returnValue("http"));
-        mockHttpReq.stubs().method("getAttribute").with(
-                eq("struts.valueStack")).will(returnValue(stack));
-        mockHttpReq.stubs().method("getAttribute").with(
-                eq("javax.portlet.response")).will(
-                returnValue((PortletResponse) mockPortletRes.proxy()));
-        mockHttpReq.stubs().method("getAttribute").with(
-                eq("javax.portlet.request")).will(
-                returnValue((PortletRequest) mockPortletReq.proxy()));
-
-        mockPortletReq.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
-        mockPortletReq.stubs().method("getWindowState").will(returnValue(WindowState.NORMAL));
-        mockPortletReq.stubs().method("getContextPath").will(returnValue("/contextPath"));
-
-        tag.setPageContext((PageContext) mockPageCtx.proxy());
-
-        Map modeMap = new HashMap();
-        modeMap.put(PortletMode.VIEW, "/view");
-        modeMap.put(PortletMode.HELP, "/help");
-        modeMap.put(PortletMode.EDIT, "/edit");
-        Map sessionMap = new HashMap();
-        Map contextMap = new HashMap();
-        contextMap.put(ActionContext.SESSION, sessionMap);
-        contextMap.put(PortletActionConstants.REQUEST, mockPortletReq.proxy());
-        contextMap.put(PortletActionConstants.RESPONSE, mockPortletRes.proxy());
-        contextMap.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
-        contextMap.put(PortletActionConstants.MODE_NAMESPACE_MAP, modeMap);
-        contextMap.put(STRUTS_PORTLET_CONTEXT, mockCtx.proxy());
-        ActionContext ctx = new ActionContext(contextMap);
-        ctx.setValueStack(stack);
-        ActionContext.setContext(ctx);
-    }
-
-    public void testEnsureParamsAreStringArrays() {
-        Map params = new HashMap();
-        params.put("param1", "Test1");
-        params.put("param2", new String[] { "Test2" });
-
-        Map result = PortletUrlHelper.ensureParamsAreStringArrays(params);
-        assertEquals(2, result.size());
-        assertTrue(result.get("param1") instanceof String[]);
-    }
-
-    public void testSetWindowState() throws Exception {
-
-        PortletMode mode = PortletMode.VIEW;
-
-        mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-
-        mockPortletRes.expects(once()).method("createRenderURL").will(
-                returnValue((PortletURL) mockPortletUrl.proxy()));
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-
-        Map paramMap = new HashMap();
-        paramMap.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/testAction"});
-        paramMap.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
-
-        mockPortletUrl.expects(once()).method("setParameters").with(new ParamMapConstraint(paramMap));
-        mockPortletUrl.expects(once()).method("setWindowState").with(eq(WindowState.MAXIMIZED));
-        mockPortletUrl.expects(once()).method("setPortletMode").with(eq(PortletMode.VIEW));
-
-        tag.setAction("testAction");
-        tag.setWindowState("maximized");
-        tag.doStartTag();
-        tag.doEndTag();
-
-    }
-
-    public void testSetPortletMode() throws Exception  {
-
-        PortletMode mode = PortletMode.HELP;
-
-        mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-
-        mockPortletRes.expects(once()).method("createRenderURL").will(
-                returnValue((PortletURL) mockPortletUrl.proxy()));
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-
-        Map paramMap = new HashMap();
-        paramMap.put(PortletActionConstants.ACTION_PARAM, new String[]{"/help/testAction"});
-        paramMap.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
-
-        mockPortletUrl.expects(once()).method("setParameters").with(new ParamMapConstraint(paramMap));
-        mockPortletUrl.expects(once()).method("setPortletMode").with(eq(PortletMode.HELP));
-        mockPortletUrl.expects(once()).method("setWindowState").with(eq(WindowState.NORMAL));
-
-        tag.setAction("testAction");
-        tag.setPortletMode("help");
-        tag.doStartTag();
-        tag.doEndTag();
-    }
-
-    public void testUrlWithQueryParams() throws Exception {
-
-        PortletMode mode = PortletMode.VIEW;
-
-        mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-
-        mockPortletRes.expects(once()).method("createRenderURL").will(
-                returnValue((PortletURL) mockPortletUrl.proxy()));
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-
-        Map paramMap = new HashMap();
-        paramMap.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/testAction"});
-        paramMap.put("testParam1", new String[]{"testValue1"});
-        paramMap.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
-
-        mockPortletUrl.expects(once()).method("setParameters").with(new ParamMapConstraint(paramMap));
-        mockPortletUrl.expects(once()).method("setPortletMode").with(eq(PortletMode.VIEW));
-        mockPortletUrl.expects(once()).method("setWindowState").with(eq(WindowState.NORMAL));
-
-        tag.setAction("testAction?testParam1=testValue1");
-        tag.doStartTag();
-        tag.doEndTag();
-    }
-
-    public void testActionUrl() throws Exception {
-
-        PortletMode mode = PortletMode.VIEW;
-
-        mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-
-        mockPortletRes.expects(once()).method("createActionURL").will(
-                returnValue((PortletURL) mockPortletUrl.proxy()));
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-
-        Map paramMap = new HashMap();
-        paramMap.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/testAction"});
-        paramMap.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
-
-        mockPortletUrl.expects(once()).method("setParameters").with(new ParamMapConstraint(paramMap));
-        mockPortletUrl.expects(once()).method("setPortletMode").with(eq(PortletMode.VIEW));
-        mockPortletUrl.expects(once()).method("setWindowState").with(eq(WindowState.NORMAL));
-
-        tag.setAction("testAction");
-        tag.setPortletUrlType("action");
-        tag.doStartTag();
-        tag.doEndTag();
-    }
-
-    public void testResourceUrl() throws Exception {
-        mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-        mockPortletRes.expects(once()).method("encodeURL").will(returnValue("/contextPath/image.gif"));
-        mockJspWriter.setExpectedData("/contextPath/image.gif");
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-        tag.setValue("image.gif");
-        tag.doStartTag();
-        tag.doEndTag();
-        mockJspWriter.verify();
-    }
-
-    public void testResourceUrlWithNestedParam() throws Exception {
-        mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-        mockPortletRes.expects(once()).method("encodeURL").with(eq("/contextPath/image.gif?testParam1=testValue1")).will(returnValue("/contextPath/image.gif?testParam1=testValue1"));
-        mockJspWriter.setExpectedData("/contextPath/image.gif?testParam1=testValue1");
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-
-        ParamTag paramTag = new ParamTag();
-        paramTag.setPageContext((PageContext)mockPageCtx.proxy());
-        paramTag.setParent(tag);
-        paramTag.setName("testParam1");
-        paramTag.setValue("'testValue1'");
-        tag.setValue("image.gif");
-        tag.doStartTag();
-        paramTag.doStartTag();
-        paramTag.doEndTag();
-        tag.doEndTag();
-        mockJspWriter.verify();
-    }
-
-    public void testResourceUrlWithTwoNestedParam() throws Exception {
-        mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-        mockPortletRes.expects(once()).method("encodeURL").with(eq("/contextPath/image.gif?testParam1=testValue1&testParam2=testValue2")).will(returnValue("/contextPath/image.gif?testParam1=testValue1&testParam2=testValue2"));
-        mockJspWriter.setExpectedData("/contextPath/image.gif?testParam1=testValue1&testParam2=testValue2");
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-
-        ParamTag paramTag = new ParamTag();
-        paramTag.setPageContext((PageContext)mockPageCtx.proxy());
-        paramTag.setParent(tag);
-        paramTag.setName("testParam1");
-        paramTag.setValue("'testValue1'");
-        ParamTag paramTag2 = new ParamTag();
-        paramTag2.setPageContext((PageContext)mockPageCtx.proxy());
-        paramTag2.setParent(tag);
-        paramTag2.setName("testParam2");
-        paramTag2.setValue("'testValue2'");
-        tag.setValue("image.gif");
-        tag.doStartTag();
-        paramTag.doStartTag();
-        paramTag.doEndTag();
-        paramTag2.doStartTag();
-        paramTag2.doEndTag();
-        tag.doEndTag();
-        mockJspWriter.verify();
-    }
-
-    public void testUrlWithMethod() throws Exception {
-    	PortletMode mode = PortletMode.VIEW;
-    	mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-        mockPortletRes.expects(once()).method("createRenderURL").will(
-                returnValue((PortletURL) mockPortletUrl.proxy()));
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-    	tag.setAction("testAction");
-    	Map paramMap = new HashMap();
-        paramMap.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/testAction!input"});
-        paramMap.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
-        mockPortletUrl.expects(once()).method("setParameters").with(new ParamMapConstraint(paramMap));
-        mockPortletUrl.expects(once()).method("setPortletMode").with(eq(PortletMode.VIEW));
-        mockPortletUrl.expects(once()).method("setWindowState").with(eq(WindowState.NORMAL));
-    	tag.setMethod("input");
-    	tag.doStartTag();
-    	tag.doEndTag();
-    }
-    
-    public void testUrlWithNoActionOrMethod() throws Exception {
-    	PortletMode mode = PortletMode.VIEW;
-    	mockHttpReq.stubs().method("getQueryString").will(returnValue(""));
-        mockPortletRes.expects(once()).method("createRenderURL").will(
-                returnValue((PortletURL) mockPortletUrl.proxy()));
-        mockCtx.expects(atLeastOnce()).method("getMajorVersion").will(returnValue(1));
-    	Map paramMap = new HashMap();
-    	
-    	Mock mockActionProxy = mock(ActionProxy.class);
-    	mockActionProxy.stubs().method("getActionName").will(returnValue("currentExecutingAction"));
-    	final ActionProxy proxy = (ActionProxy)mockActionProxy.proxy();
-    	
-    	Mock mockActionInvocation = mock(ActionInvocation.class);
-    	mockActionInvocation.stubs().method("getProxy").will(returnValue(proxy));
-    	ActionInvocation ai = (ActionInvocation)mockActionInvocation.proxy();
-
-    	stack.getContext().put(ActionContext.ACTION_INVOCATION, ai);
-        paramMap.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/currentExecutingAction"});
-        paramMap.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
-        mockPortletUrl.expects(once()).method("setParameters").with(new ParamMapConstraint(paramMap));
-        mockPortletUrl.expects(once()).method("setPortletMode").with(eq(PortletMode.VIEW));
-        mockPortletUrl.expects(once()).method("setWindowState").with(eq(WindowState.NORMAL));
-    	tag.doStartTag();
-    	tag.doEndTag();    	
-    }
-    
-    private static class ParamMapConstraint implements Constraint {
-
-        private Map myExpectedMap = null;
-        private Map myActualMap = null;
-
-        public ParamMapConstraint(Map expectedMap) {
-            if(expectedMap == null) {
-                throw new IllegalArgumentException("Use an isNull constraint instead!");
-            }
-            myExpectedMap = expectedMap;
-        }
-
-        /* (non-Javadoc)
-         * @see org.jmock.core.Constraint#eval(java.lang.Object)
-         */
-        public boolean eval(Object val) {
-            myActualMap = (Map)val;
-            boolean result = false;
-            if(val != null) {
-                if(myExpectedMap.size() == myActualMap.size()) {
-                    Iterator keys = myExpectedMap.keySet().iterator();
-                    boolean allSame = true;
-                    while(keys.hasNext()) {
-                        Object key = keys.next();
-                        if(!myActualMap.containsKey(key)) {
-                            allSame = false;
-                            break;
-                        }
-                        else {
-                            String[] expected = (String[])myExpectedMap.get(key);
-                            String[] actual = (String[])myActualMap.get(key);
-                            if(!Arrays.equals(expected, actual)) {
-                                allSame = false;
-                                break;
-                            }
-                        }
-                    }
-                    result = allSame;
-                }
-            }
-            return result;
-        }
-
-        /* (non-Javadoc)
-         * @see org.jmock.core.SelfDescribing#describeTo(java.lang.StringBuffer)
-         */
-        public StringBuffer describeTo(StringBuffer sb) {
-        	Iterator<String> it = myExpectedMap.keySet().iterator();
-        	while(it.hasNext()) {
-        		String key = it.next();
-        		sb.append(key).append("=");
-        		String[] value = (String[])myExpectedMap.get(key);
-        		sb.append(value[0]);
-        		if(it.hasNext()) {
-        			sb.append(", ");
-        		}
-        	}
-            return sb;
-        }
+	private URLTag tag = new URLTag();
 
+	private ValueStack stack = null;
 
+	private ActionContext context = null;
 
-    }
+	private MockRenderRequest renderRequest;
+
+	private MockPortletUrl renderUrl;
+
+	private MockPortletUrl actionUrl;
+
+	private MockRenderResponse renderResponse;
+
+	private MockPageContext pageContext;
+
+	private MockActionInvocation actionInvocation;
+
+	private MockActionProxy actionProxy;
+
+	private MockJspWriter jspWriter;
+	
+	private MockPortletContext portletContext;
+
+	public void setUp() throws Exception {
+		super.setUp();
+
+		context = ActionContext.getContext();
+		stack = context.getValueStack();
+
+		portletContext = new MockPortletContext();
+		renderRequest = new MockRenderRequest();
+		renderRequest.setAttribute(ServletActionContext.STRUTS_VALUESTACK_KEY, stack);
+		renderUrl = new MockPortletUrl("render");
+		actionUrl = new MockPortletUrl("action");
+		renderResponse = new MockRenderResponse() {
+			@Override
+			public PortletURL createRenderURL() {
+				return renderUrl;
+			}
+
+			@Override
+			public PortletURL createActionURL() {
+				return actionUrl;
+			}
+		};
+
+		Map modeMap = new HashMap();
+		modeMap.put(PortletMode.VIEW, "/view");
+		modeMap.put(PortletMode.HELP, "/help");
+		modeMap.put(PortletMode.EDIT, "/edit");
+
+		context.put(PortletActionConstants.REQUEST, renderRequest);
+		context.put(PortletActionConstants.RESPONSE, renderResponse);
+		context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+		context.put(PortletActionConstants.MODE_NAMESPACE_MAP, modeMap);
+		context.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, portletContext);
+
+		actionInvocation = new MockActionInvocation();
+		actionProxy = new MockActionProxy();
+
+		actionInvocation.setAction(new Object());
+		actionInvocation.setProxy(actionProxy);
+		actionInvocation.setStack(stack);
+
+		context.setActionInvocation(actionInvocation);
+
+		pageContext = new MockPageContext();
+		pageContext.setRequest(new PortletServletRequest(renderRequest, null));
+		jspWriter = new MockJspWriter();
+		pageContext.setJspWriter(jspWriter);
+
+		tag.setPageContext(pageContext);
+
+	}
+
+	public void testEnsureParamsAreStringArrays() {
+		Map params = new HashMap();
+		params.put("param1", "Test1");
+		params.put("param2", new String[] { "Test2" });
+
+		Map result = PortletUrlHelper.ensureParamsAreStringArrays(params);
+		assertEquals(2, result.size());
+		assertTrue(result.get("param1") instanceof String[]);
+	}
+
+	public void testSetWindowState() throws Exception {
+
+		tag.setAction("testAction");
+		tag.setWindowState("maximized");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/view/testAction", renderUrl.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals(PortletMode.VIEW.toString(), renderUrl.getParameter(PortletActionConstants.MODE_PARAM));
+		assertEquals(PortletMode.VIEW, renderUrl.getPortletMode());
+		assertEquals(WindowState.MAXIMIZED, renderUrl.getWindowState());
+
+	}
+
+	public void testSetPortletMode() throws Exception {
+
+		tag.setAction("testAction");
+		tag.setPortletMode("help");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/help/testAction", renderUrl.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals(PortletMode.HELP.toString(), renderUrl.getParameter(PortletActionConstants.MODE_PARAM));
+		assertEquals(PortletMode.HELP, renderUrl.getPortletMode());
+		assertEquals(WindowState.NORMAL, renderUrl.getWindowState());
+	}
+
+	public void testUrlWithQueryParams() throws Exception {
+
+		tag.setAction("testAction?testParam1=testValue1");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/view/testAction", renderUrl.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals("testValue1", renderUrl.getParameter("testParam1"));
+		assertEquals(PortletMode.VIEW.toString(), renderUrl.getParameter(PortletActionConstants.MODE_PARAM));
+		assertEquals(PortletMode.VIEW, renderUrl.getPortletMode());
+		assertEquals(WindowState.NORMAL, renderUrl.getWindowState());
+	}
+
+	public void testActionUrl() throws Exception {
+
+		tag.setAction("testAction");
+		tag.setPortletUrlType("action");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/view/testAction", actionUrl.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals(PortletMode.VIEW, actionUrl.getPortletMode());
+		assertEquals(WindowState.NORMAL, actionUrl.getWindowState());
+	}
+
+	public void testResourceUrl() throws Exception {
+		renderRequest.setContextPath("/myPortlet");
+		jspWriter.setExpectedData("/myPortlet/image.gif");
+		tag.setValue("image.gif");
+		tag.doStartTag();
+		tag.doEndTag();
+		jspWriter.verify();
+	}
+
+	public void testResourceUrlWithNestedParam() throws Exception {
+		renderRequest.setContextPath("/myPortlet");
+		jspWriter.setExpectedData("/myPortlet/image.gif?testParam1=testValue1");
+
+		ParamTag paramTag = new ParamTag();
+		paramTag.setPageContext(pageContext);
+		paramTag.setParent(tag);
+		paramTag.setName("testParam1");
+		paramTag.setValue("'testValue1'");
+		tag.setValue("image.gif");
+		tag.doStartTag();
+		paramTag.doStartTag();
+		paramTag.doEndTag();
+		tag.doEndTag();
+		jspWriter.verify();
+	}
+
+	public void testResourceUrlWithTwoNestedParam() throws Exception {
+		renderRequest.setContextPath("/myPortlet");
+		jspWriter.setExpectedData("/myPortlet/image.gif?testParam1=testValue1&testParam2=testValue2");
+
+		ParamTag paramTag = new ParamTag();
+		paramTag.setPageContext(pageContext);
+		paramTag.setParent(tag);
+		paramTag.setName("testParam1");
+		paramTag.setValue("'testValue1'");
+		ParamTag paramTag2 = new ParamTag();
+		paramTag2.setPageContext(pageContext);
+		paramTag2.setParent(tag);
+		paramTag2.setName("testParam2");
+		paramTag2.setValue("'testValue2'");
+		tag.setValue("image.gif");
+		tag.doStartTag();
+		paramTag.doStartTag();
+		paramTag.doEndTag();
+		paramTag2.doStartTag();
+		paramTag2.doEndTag();
+		tag.doEndTag();
+		jspWriter.verify();
+	}
+	
+	public void testResourceUrlWithNestedParamThatIsNotString() throws Exception {
+		renderRequest.setContextPath("/myPortlet");
+		jspWriter.setExpectedData("/myPortlet/image.gif?id=5");
+		
+		ParamTag paramTag = new ParamTag();
+		paramTag.setPageContext(pageContext);
+		paramTag.setParent(tag);
+		paramTag.setName("id");
+		paramTag.setValue("5");
+		
+		tag.setValue("image.gif");
+		tag.doStartTag();
+		paramTag.doStartTag();
+		paramTag.doEndTag();
+		tag.doEndTag();
+		jspWriter.verify();
+	}
+	
+	public void testResourceUrlWithNestedOgnlExpressionParamThatIsNotString() throws Exception
{
+		renderRequest.setContextPath("/myPortlet");
+		jspWriter.setExpectedData("/myPortlet/image.gif?id=5");
+		
+		Object o = new Object() {
+			public Integer getId() {
+				return 5;
+			}
+		};
+		tag.getStack().push(o);
+		
+		ParamTag paramTag = new ParamTag();
+		paramTag.setPageContext(pageContext);
+		paramTag.setParent(tag);
+		paramTag.setName("id");
+		paramTag.setValue("id");
+		
+		tag.setValue("image.gif");
+		tag.doStartTag();
+		paramTag.doStartTag();
+		paramTag.doEndTag();
+		tag.doEndTag();
+		jspWriter.verify();
+	}
+
+	public void testUrlWithMethod() throws Exception {
+		tag.setAction("testAction");
+		tag.setMethod("input");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/view/testAction!input", renderUrl.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals(PortletMode.VIEW.toString(), renderUrl.getParameter(PortletActionConstants.MODE_PARAM));
+		assertEquals(PortletMode.VIEW, renderUrl.getPortletMode());
+		assertEquals(WindowState.NORMAL, renderUrl.getWindowState());
+	}
+
+	public void testUrlWithNoActionOrMethod() throws Exception {
+		actionProxy.setActionName("currentExecutingAction");
+		actionProxy.setNamespace("/currentNamespace");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/view/currentNamespace/currentExecutingAction", renderUrl
+				.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals(PortletMode.VIEW.toString(), renderUrl.getParameter(PortletActionConstants.MODE_PARAM));
+		assertEquals(PortletMode.VIEW, renderUrl.getPortletMode());
+		assertEquals(WindowState.NORMAL, renderUrl.getWindowState());
+	}
+
+	public void testUrlShouldNotIncludeParamsFromHttpQueryString() throws Exception {
+
+		PortletServletRequestWithQueryString req = new PortletServletRequestWithQueryString(renderRequest,
null);
+		req.setQueryString("thisParamShouldNotBeIncluded=thisValueShouldNotBeIncluded");
+		pageContext.setRequest(req);
+		tag.setAction("testAction?testParam1=testValue1");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/view/testAction", renderUrl.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals("testValue1", renderUrl.getParameter("testParam1"));
+		assertNull(renderUrl.getParameter("thisParamShouldNotBeIncluded"));
+		assertEquals(PortletMode.VIEW.toString(), renderUrl.getParameter(PortletActionConstants.MODE_PARAM));
+		assertEquals(PortletMode.VIEW, renderUrl.getPortletMode());
+		assertEquals(WindowState.NORMAL, renderUrl.getWindowState());
+	}
+
+	public void testUrlShouldIgnoreIncludeParams() throws Exception {
+		PortletServletRequestWithQueryString req = new PortletServletRequestWithQueryString(renderRequest,
null);
+		req.setQueryString("thisParamShouldNotBeIncluded=thisValueShouldNotBeIncluded");
+		pageContext.setRequest(req);
+		tag.setAction("testAction?testParam1=testValue1");
+		tag.setIncludeParams("GET");
+		tag.doStartTag();
+		tag.doEndTag();
+
+		assertEquals("/view/testAction", renderUrl.getParameter(PortletActionConstants.ACTION_PARAM));
+		assertEquals("testValue1", renderUrl.getParameter("testParam1"));
+		assertNull(renderUrl.getParameter("thisParamShouldNotBeIncluded"));
+		assertEquals(PortletMode.VIEW.toString(), renderUrl.getParameter(PortletActionConstants.MODE_PARAM));
+		assertEquals(PortletMode.VIEW, renderUrl.getPortletMode());
+		assertEquals(WindowState.NORMAL, renderUrl.getWindowState());
+	}
+
+	private static class PortletServletRequestWithQueryString extends PortletServletRequest
{
+
+		private String queryString;
+
+		public PortletServletRequestWithQueryString(PortletRequest portletRequest, PortletContext
portletContext) {
+			super(portletRequest, portletContext);
+		}
+
+		public void setQueryString(String queryString) {
+			this.queryString = queryString;
+		}
+
+		@Override
+		public String getQueryString() {
+			return queryString;
+		}
+
+	}
+
+	private static class MockPortletUrl extends MockPortletURL {
+
+		private PortletMode portletMode;
+
+		private WindowState windowState;
+
+		public MockPortletUrl(String urlType) {
+			super(new MockPortalContext(), urlType);
+		}
+
+		@Override
+		public void setPortletMode(PortletMode portletMode) throws PortletModeException {
+			super.setPortletMode(portletMode);
+			this.portletMode = portletMode;
+		}
+
+		public PortletMode getPortletMode() {
+			return portletMode;
+		}
+
+		@Override
+		public void setWindowState(WindowState windowState) throws WindowStateException {
+			super.setWindowState(windowState);
+			this.windowState = windowState;
+		}
+
+		public WindowState getWindowState() {
+			return windowState;
+		}
 
+	}
 }

Modified: struts/struts2/trunk/pom.xml
URL: http://svn.apache.org/viewvc/struts/struts2/trunk/pom.xml?rev=1139729&r1=1139728&r2=1139729&view=diff
==============================================================================
--- struts/struts2/trunk/pom.xml (original)
+++ struts/struts2/trunk/pom.xml Sun Jun 26 08:30:00 2011
@@ -87,7 +87,7 @@
         <currentVersion>${project.version}</currentVersion>
         <struts2.springPlatformVersion>3.0.5.RELEASE</struts2.springPlatformVersion>
         <ognl.version>3.0.2</ognl.version>
-        <asm.version>3.3</asm.version>
+        <asm.version>3.1</asm.version>
         <tiles.version>2.0.6</tiles.version>
     </properties>
 
@@ -625,14 +625,14 @@
             <dependency>
                 <groupId>jmock</groupId>
                 <artifactId>jmock</artifactId>
-                <version>1.2.0</version>
+                <version>1.0.1</version>
                 <scope>test</scope>
             </dependency>
 
             <dependency>
                 <groupId>jmock</groupId>
                 <artifactId>jmock-cglib</artifactId>
-                <version>1.2.0</version>
+                <version>1.0.1</version>
                 <scope>test</scope>
             </dependency>
 
@@ -682,9 +682,9 @@
 
             <!-- Portlet -->
             <dependency>
-                <groupId>javax.portlet</groupId>
+                <groupId>portlet-api</groupId>
                 <artifactId>portlet-api</artifactId>
-                <version>2.0</version>
+                <version>1.0</version>
             </dependency>
 
             <dependency>



Mime
View raw message