You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@struts.apache.org by ni...@apache.org on 2008/01/21 11:09:07 UTC

svn commit: r613823 [4/4] - in /struts/sandbox/trunk/struts2-portlet2-plugin: ./ src/ src/main/ src/main/java/ src/main/java/org/ src/main/java/org/apache/ src/main/java/org/apache/struts2/ src/main/java/org/apache/struts2/components/ src/main/java/org...

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,124 @@
+/*
+ * $Id: PortletSessionMapTest.java 580134 2007-09-27 19:44:01Z nilsga $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.portlet;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PortletSession;
+
+import junit.framework.TestCase;
+
+import org.springframework.mock.web.portlet.MockPortletRequest;
+
+
+/**
+ * PortletSessionMapTest. Insert description.
+ *
+ */
+public class PortletSessionMapTest extends TestCase {
+
+    public void testPut() {
+
+    	MockPortletRequest request = new MockPortletRequest();
+
+        PortletSessionMap map = new PortletSessionMap(request);
+        assertEquals("testValue1", map.put("testAttribute1", "testValue1"));
+        assertEquals("testValue2", map.put("testAttribute2", "testValue2"));
+
+        PortletSession session = request.getPortletSession();
+        // Assert that the values has been propagated to the session
+        assertEquals("testValue1", session.getAttribute("testAttribute1"));
+        assertEquals("testValue2", session.getAttribute("testAttribute2"));
+    }
+
+    public void testGet() {
+    	MockPortletRequest request = new MockPortletRequest();
+    	PortletSession session = request.getPortletSession();
+    	session.setAttribute("testAttribute1", "testValue1");
+    	session.setAttribute("testAttribute2", "testValue2");
+        PortletSessionMap map = new PortletSessionMap(request);
+        Object val1 = map.get("testAttribute1");
+        Object val2 = map.get("testAttribute2");
+        // Assert that the values from the session is in the map
+        assertEquals("testValue1", val1);
+        assertEquals("testValue2", val2);
+    }
+
+    public void testClear() {
+        MockPortletRequest req = new MockPortletRequest();
+        PortletSession session = req.getPortletSession();
+    	session.setAttribute("testAttribute1", "testValue1");
+    	session.setAttribute("testAttribute2", "testValue2");
+        
+        PortletSessionMap map = new PortletSessionMap(req);
+        map.clear();
+        
+        // Assert that there are no elements in the portlet session
+        assertFalse(req.getPortletSession().getAttributeNames().hasMoreElements());
+    }
+
+    public void testRemove() {
+    	MockPortletRequest request = new MockPortletRequest();
+    	PortletSession session = request.getPortletSession();
+    	session.setAttribute("testAttribute1", "testValue1");
+
+        PortletSessionMap map = new PortletSessionMap(request);
+        Object ret = map.remove("testAttribute1");
+        // Assert that the element that was removed was returned and the key is no longer in the
+        // portlet session
+        assertEquals("testValue1", ret);
+        assertNull(session.getAttribute("testAttribute1"));
+    }
+
+    public void testEntrySet() {
+    	MockPortletRequest request = new MockPortletRequest();
+    	PortletSession session = request.getPortletSession();
+    	session.setAttribute("testAttribute1", "testValue1");
+    	session.setAttribute("testAttribute2", "testValue2");
+
+        PortletSessionMap map = new PortletSessionMap(request);
+        Set entries = map.entrySet();
+
+        assertEquals(2, entries.size());
+        Iterator it = entries.iterator();
+        Map.Entry entry = (Map.Entry)it.next();
+        checkEntry(entry);
+        entry = (Map.Entry)it.next();
+        checkEntry(entry);
+
+    }
+
+	private void checkEntry(Map.Entry entry) {
+		if(entry.getKey().equals("testAttribute1")) {
+        	assertEquals("testValue1", entry.getValue());
+        }
+        else if(entry.getKey().equals("testAttribute2")) {
+        	assertEquals("testValue2", entry.getValue());
+        }
+        else {
+        	fail("Unexpected entry in etry set: " + entry);
+        }
+	}
+
+
+}

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,183 @@
+/*
+ * $Id: PortletActionContextTest.java 557544 2007-07-19 10:03:06Z nilsga $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.portlet.context;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import junit.textui.TestRunner;
+
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+import com.opensymphony.xwork2.ActionContext;
+
+/**
+ */
+public class PortletActionContextTest extends MockObjectTestCase {
+
+    Mock mockRenderRequest;
+    Mock mockRenderResponse;
+    Mock mockPortletConfig;
+    Mock mockActionRequest;
+    Mock mockActionResponse;
+
+    RenderRequest renderRequest;
+    RenderResponse renderResponse;
+
+    ActionRequest actionRequest;
+    ActionResponse actionResponse;
+
+    PortletConfig portletConfig;
+
+    Map context = new HashMap();
+
+    public void setUp() throws Exception {
+        super.setUp();
+        mockRenderRequest = mock(RenderRequest.class);
+        mockRenderResponse = mock(RenderResponse.class);
+        mockActionRequest = mock(ActionRequest.class);
+        mockActionResponse = mock(ActionResponse.class);
+        mockPortletConfig = mock(PortletConfig.class);
+
+        renderRequest = (RenderRequest)mockRenderRequest.proxy();
+        renderResponse = (RenderResponse)mockRenderResponse.proxy();
+        actionRequest = (ActionRequest)mockActionRequest.proxy();
+        actionResponse = (ActionResponse)mockActionResponse.proxy();
+        portletConfig = (PortletConfig)mockPortletConfig.proxy();
+
+
+        ActionContext.setContext(new ActionContext(context));
+    }
+
+    public void testGetPhase() {
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+
+        assertEquals(PortletActionConstants.RENDER_PHASE, PortletActionContext.getPhase());
+    }
+
+    public void testIsRender() {
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+
+        assertTrue(PortletActionContext.isRender());
+        assertFalse(PortletActionContext.isAction());
+    }
+
+    public void testIsEvent() {
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.ACTION_PHASE);
+
+        assertTrue(PortletActionContext.isAction());
+        assertFalse(PortletActionContext.isRender());
+    }
+
+    public void testGetPortletConfig() {
+        context.put(PortletActionConstants.PORTLET_CONFIG, portletConfig);
+        assertSame(portletConfig, PortletActionContext.getPortletConfig());
+    }
+
+    public void testGetRenderRequestAndResponse() {
+        context.put(PortletActionConstants.REQUEST, renderRequest);
+        context.put(PortletActionConstants.RESPONSE, renderResponse);
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+        assertSame(renderRequest, PortletActionContext.getRenderRequest());
+        assertSame(renderResponse, PortletActionContext.getRenderResponse());
+        assertSame(renderRequest, PortletActionContext.getRequest());
+        assertSame(renderResponse, PortletActionContext.getResponse());
+    }
+
+    public void testGetRenderRequestAndResponseInEventPhase() {
+        context.put(PortletActionConstants.REQUEST, renderRequest);
+        context.put(PortletActionConstants.RESPONSE, renderResponse);
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.ACTION_PHASE);
+        try {
+            PortletActionContext.getRenderRequest();
+            fail("Should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e) {
+            assertTrue(true);
+        }
+        try {
+            PortletActionContext.getRenderResponse();
+            fail("Should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e) {
+            assertTrue(true);
+        }
+    }
+
+    public void testGetActionRequestAndResponse() {
+        context.put(PortletActionConstants.REQUEST, actionRequest);
+        context.put(PortletActionConstants.RESPONSE, actionResponse);
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.ACTION_PHASE);
+        assertSame(actionRequest, PortletActionContext.getActionRequest());
+        assertSame(actionResponse, PortletActionContext.getActionResponse());
+        assertSame(actionRequest, PortletActionContext.getRequest());
+        assertSame(actionResponse, PortletActionContext.getResponse());
+    }
+
+    public void testGetActionRequestAndResponseInRenderPhase() {
+        context.put(PortletActionConstants.REQUEST, actionRequest);
+        context.put(PortletActionConstants.RESPONSE, actionResponse);
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+        try {
+            PortletActionContext.getActionRequest();
+            fail("Should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e) {
+            assertTrue(true);
+        }
+        try {
+            PortletActionContext.getActionResponse();
+            fail("Should throw IllegalStateException!");
+        }
+        catch(IllegalStateException e) {
+            assertTrue(true);
+        }
+    }
+
+    public void testGetNamespace() {
+        context.put(PortletActionConstants.PORTLET_NAMESPACE, "testNamespace");
+        assertEquals("testNamespace", PortletActionContext.getPortletNamespace());
+    }
+
+    public void testGetDefaultActionForMode() {
+        ActionMapping mapping = new ActionMapping();
+        context.put(PortletActionConstants.DEFAULT_ACTION_FOR_MODE, mapping);
+        assertEquals(mapping, PortletActionContext.getDefaultActionForMode());
+    }
+
+    public void tearDown() throws Exception {
+        ActionContext.setContext(null);
+        super.tearDown();
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(PortletActionContextTest.class);
+    }
+}

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,329 @@
+/*
+ * $Id: Jsr168DispatcherTest.java 602665 2007-12-09 12:11:25Z mrdon $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.portlet.dispatcher;
+
+import java.io.File;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.ListResourceBundle;
+import java.util.Locale;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletSession;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import org.apache.struts2.StrutsConstants;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.easymock.EasyMock;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+import org.jmock.core.Constraint;
+import org.springframework.mock.web.portlet.MockActionRequest;
+import org.springframework.mock.web.portlet.MockActionResponse;
+import org.springframework.mock.web.portlet.MockPortletConfig;
+import org.springframework.mock.web.portlet.MockPortletContext;
+
+import com.opensymphony.xwork2.Action;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.ActionProxyFactory;
+import com.opensymphony.xwork2.util.ValueStack;
+
+/**
+ * Jsr168DispatcherTest. Insert description.
+ *
+ */
+public class Jsr168DispatcherTest extends MockObjectTestCase implements PortletActionConstants {
+
+	private final String MULTIPART_REQUEST = "-----------------------------4827543632391\r\n" 
+		+ "Content-Disposition: form-data; name=\"upload\"; filename=\"test.txt\"\r\n"
+		+ "Content-Type: text/plain\r\n"
+		+ "\r\n"
+		+ "This is a test file\r\n"
+		+ "-----------------------------4827543632391\r\n"
+		+ "Content-Disposition: form-data; name=\"caption\"\r\n"
+		+ "\r\n"
+		+ "TestCaption\r\n"
+		+ "-----------------------------4827543632391--";
+	
+    Jsr168Dispatcher dispatcher = null;
+    Mock mockConfig = null;
+    Mock mockCtx = null;
+    Mock mockRequest = null;
+    Mock mockSession = null;
+    Mock mockActionFactory = null;
+    Mock mockActionProxy = null;
+    Mock mockAction = null;
+    Mock mockInvocation = null;
+
+    public void setUp() {
+        dispatcher = new Jsr168Dispatcher();
+    }
+
+    private void initPortletConfig(final Map initParams, final Map attributes) {
+        mockConfig = mock(PortletConfig.class);
+        mockCtx = mock(PortletContext.class);
+        mockConfig.stubs().method(ANYTHING);
+        mockCtx.stubs().method(ANYTHING);
+        setupStub(initParams, mockConfig, "getInitParameter");
+        mockCtx.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(attributes.keySet())));
+        setupStub(attributes, mockCtx, "getAttribute");
+        mockConfig.stubs().method("getPortletContext").will(returnValue(mockCtx.proxy()));
+        mockCtx.stubs().method("getInitParameterNames").will(returnValue(Collections.enumeration(initParams.keySet())));
+        setupStub(initParams, mockCtx, "getInitParameter");
+        mockConfig.stubs().method("getInitParameterNames").will(returnValue(Collections.enumeration(initParams.keySet())));
+        setupStub(initParams, mockConfig, "getInitParameter");
+        mockConfig.stubs().method("getResourceBundle").will(returnValue(new ListResourceBundle() {
+            protected Object[][] getContents() {
+                return new String[][]{{"javax.portlet.title", "MyTitle"}};
+            }
+        }));
+    }
+
+    private void setupActionFactory(String namespace, String actionName, String result, ValueStack stack) {
+        if(mockActionFactory == null) {
+            mockActionFactory = mock(ActionProxyFactory.class);
+        }
+        mockAction = mock(Action.class);
+        mockActionProxy = mock(ActionProxy.class);
+        mockInvocation = mock(ActionInvocation.class);
+
+        mockActionFactory.expects(once()).method("createActionProxy").with(new Constraint[]{eq(namespace), eq(actionName), NULL, isA(Map.class)}).will(returnValue(mockActionProxy.proxy()));
+        mockActionProxy.stubs().method("getAction").will(returnValue(mockAction.proxy()));
+        mockActionProxy.expects(once()).method("execute").will(returnValue(result));
+        mockActionProxy.expects(once()).method("getInvocation").will(returnValue(mockInvocation.proxy()));
+        mockInvocation.stubs().method("getStack").will(returnValue(stack));
+
+    }
+    
+    public void testParseConfigWithBang() {
+    	MockPortletContext portletContext = new MockPortletContext();
+    	MockPortletConfig portletConfig = new MockPortletConfig(portletContext);
+
+    	portletConfig.addInitParameter("viewNamespace", "/view");
+    	portletConfig.addInitParameter("defaultViewAction", "index!input");
+    	
+    	Map<PortletMode, ActionMapping> actionMap = new HashMap<PortletMode, ActionMapping>();
+    	
+    	dispatcher.parseModeConfig(actionMap, portletConfig, PortletMode.VIEW, "viewNamespace", "defaultViewAction");
+    	
+    	ActionMapping mapping = actionMap.get(PortletMode.VIEW);
+    	assertEquals("index", mapping.getName());
+    	assertEquals("/view", mapping.getNamespace());
+    	assertEquals("input", mapping.getMethod());
+    }
+
+    public void testRender_ok() {
+        final Mock mockResponse = mock(RenderResponse.class);
+        mockResponse.stubs().method(ANYTHING);
+
+        PortletMode mode = PortletMode.VIEW;
+
+        Map requestParams = new HashMap();
+        requestParams.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/testAction"});
+        requestParams.put(EVENT_ACTION, new String[]{"true"});
+        requestParams.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
+
+        Map sessionMap = new HashMap();
+
+
+
+        Map initParams = new HashMap();
+        initParams.put("viewNamespace", "/view");
+        initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
+
+        initPortletConfig(initParams, new HashMap());
+        initRequest(requestParams, new HashMap(), sessionMap, new HashMap(), PortletMode.VIEW, WindowState.NORMAL, false, null);
+        setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
+
+        mockInvocation.expects(once()).method("getStack").will(
+                returnValue(null));
+        //mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
+        try {
+            dispatcher
+                    .setActionProxyFactory((ActionProxyFactory) mockActionFactory
+                            .proxy());
+            dispatcher.init((PortletConfig) mockConfig.proxy());
+            dispatcher.render((RenderRequest) mockRequest.proxy(),
+                    (RenderResponse) mockResponse.proxy());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Error occured");
+        }
+    }
+
+    public void testProcessAction_ok() {
+        final Mock mockResponse = mock(ActionResponse.class);
+
+        PortletMode mode = PortletMode.VIEW;
+        Map initParams = new HashMap();
+        initParams.put("viewNamespace", "/view");
+
+        Map requestParams = new HashMap();
+        requestParams.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/testAction"});
+        requestParams.put(PortletActionConstants.MODE_PARAM, new String[]{mode.toString()});
+
+        initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
+        initPortletConfig(initParams, new HashMap());
+        initRequest(requestParams, new HashMap(), new HashMap(), new HashMap(), PortletMode.VIEW, WindowState.NORMAL, true, null);
+        setupActionFactory("/view", "testAction", "success", EasyMock.createNiceMock(ValueStack.class));
+        //mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
+        try {
+            dispatcher
+                    .setActionProxyFactory((ActionProxyFactory) mockActionFactory
+                            .proxy());
+            dispatcher.init((PortletConfig) mockConfig.proxy());
+            dispatcher.processAction((ActionRequest) mockRequest.proxy(),
+                    (ActionResponse) mockResponse.proxy());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Error occured");
+        }
+    }
+
+    /**
+     * Initialize the mock request (and as a result, the mock session)
+     * @param requestParams The request parameters
+     * @param requestAttributes The request attributes
+     * @param sessionParams The session attributes
+     * @param renderParams The render parameters. Will only be set if <code>isEvent</code> is <code>true</code>
+     * @param mode The portlet mode
+     * @param state The portlet window state
+     * @param isEvent <code>true</code> when the request is an ActionRequest.
+     * @param locale The locale. If <code>null</code>, the request will return <code>Locale.getDefault()</code>
+     */
+    private void initRequest(Map requestParams, Map requestAttributes, Map sessionParams, Map renderParams, PortletMode mode, WindowState state, boolean isEvent, Locale locale) {
+        mockRequest = isEvent ? mock(ActionRequest.class) : mock(RenderRequest.class);
+        mockSession = mock(PortletSession.class);
+        mockSession.stubs().method(ANYTHING);
+        mockRequest.stubs().method(ANYTHING);
+        setupStub(sessionParams, mockSession, "getAttribute");
+        mockSession.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(sessionParams.keySet())));
+        setupParamStub(requestParams, mockRequest, "getParameter");
+        setupStub(requestAttributes, mockRequest, "getAttribute");
+        mockRequest.stubs().method("getAttributeNames").will(returnValue(Collections.enumeration(requestAttributes.keySet())));
+        mockRequest.stubs().method("getParameterMap").will(returnValue(requestParams));
+        mockRequest.stubs().method("getParameterNames").will(returnValue(Collections.enumeration(requestParams.keySet())));
+        mockRequest.stubs().method("getPortletSession").will(returnValue(mockSession.proxy()));
+        if(locale != null) {
+            mockRequest.stubs().method("getLocale").will(returnValue(locale));
+        }
+        else {
+            mockRequest.stubs().method("getLocale").will(returnValue(Locale.getDefault()));
+        }
+        mockRequest.stubs().method("getPortletMode").will(returnValue(mode));
+        mockRequest.stubs().method("getWindowState").will(returnValue(state));
+    }
+
+    private void setupParamStub(Map requestParams, Mock mockRequest, String method) {
+        Map newMap = new HashMap();
+        Iterator it = requestParams.keySet().iterator();
+        while(it.hasNext()) {
+            Object key = it.next();
+            String[] val = (String[])requestParams.get(key);
+            newMap.put(key, val[0]);
+        }
+        setupStub(newMap, mockRequest, method);
+
+    }
+
+    /**
+     * Set up stubs for the mock.
+     * @param map The map containing the <code>key</code> and <code>values</code>. The key is the
+     * expected parameter to <code>method</code>, and value is the value that should be returned from
+     * the stub.
+     * @param mock The mock to initialize.
+     * @param method The name of the method to stub.
+     */
+    private void setupStub(Map map, Mock mock, String method) {
+        Iterator it = map.keySet().iterator();
+        while(it.hasNext()) {
+            Object key = it.next();
+            Object val = map.get(key);
+            mock.stubs().method(method).with(eq(key)).will(returnValue(val));
+        }
+    }
+
+    public void testModeChangeUsingPortletWidgets() {
+        final Mock mockResponse = mock(RenderResponse.class);
+        mockResponse.stubs().method(ANYTHING);
+        PortletMode mode = PortletMode.EDIT;
+
+        Map requestParams = new HashMap();
+        requestParams.put(PortletActionConstants.ACTION_PARAM, new String[]{"/view/testAction"});
+        requestParams.put(EVENT_ACTION, new String[]{"false"});
+        requestParams.put(PortletActionConstants.MODE_PARAM, new String[]{PortletMode.VIEW.toString()});
+
+        Map sessionMap = new HashMap();
+
+        Map initParams = new HashMap();
+        initParams.put("viewNamespace", "/view");
+        initParams.put("editNamespace", "/edit");
+
+        initPortletConfig(initParams, new HashMap());
+        initRequest(requestParams, new HashMap(), sessionMap, new HashMap(), mode, WindowState.NORMAL, false, null);
+        setupActionFactory("/edit", "default", "success", EasyMock.createNiceMock(ValueStack.class));
+
+        mockInvocation.expects(once()).method("getStack").will(
+                returnValue(null));
+        //mockSession.expects(once()).method("setAttribute").with(new Constraint[]{eq(PortletActionConstants.LAST_MODE), eq(PortletMode.VIEW)});
+        try {
+            dispatcher
+                    .setActionProxyFactory((ActionProxyFactory) mockActionFactory
+                            .proxy());
+            dispatcher.init((PortletConfig) mockConfig.proxy());
+            dispatcher.render((RenderRequest) mockRequest.proxy(),
+                    (RenderResponse) mockResponse.proxy());
+        } catch (Exception e) {
+            e.printStackTrace();
+            fail("Error occured");
+        }
+    }
+    
+    public void testMultipartRequest_parametersAreCopiedToActionInvocation() throws Exception {
+    	MockPortletContext ctx = new MockPortletContext();
+    	ctx.setAttribute("javax.servlet.context.tempdir", new File("target").getAbsoluteFile());
+    	MockActionRequest request = new MockActionRequest(ctx);
+    	request.setContent(MULTIPART_REQUEST.getBytes("US-ASCII"));
+    	request.setContentType("multipart/form-data; boundary=---------------------------4827543632391");
+    	request.setProperty("Content-Length", "" + MULTIPART_REQUEST.length());
+    	MockActionResponse response = new MockActionResponse();
+    	Map<String, Object> requestMap = new HashMap<String, Object>();
+    	Map<String, String[]> paramMap = new HashMap<String, String[]>();
+    	Map<String, Object> sessionMap = new HashMap<String, Object>();
+    	Map<String, Object> applicationMap = new HashMap<String, Object>();
+    	initPortletConfig(new HashMap(), new HashMap());
+    	MockPortletConfig config = new MockPortletConfig(ctx);
+    	dispatcher.init(config);
+    	dispatcher.createContextMap(requestMap, paramMap, sessionMap, applicationMap, request, response, config, PortletActionConstants.ACTION_PHASE);
+    	assertNotNull("Caption was not found in parameter map!", paramMap.get("caption"));
+    	assertEquals("TestCaption", paramMap.get("caption")[0]);
+    }
+}

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,67 @@
+/*
+ * $Id: PortletAwareInterceptorTest.java 590812 2007-10-31 20:32:54Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.portlet.interceptor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletRequest;
+
+import junit.framework.TestCase;
+
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.easymock.EasyMock;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+
+public class PortletAwareInterceptorTest extends TestCase implements PortletActionConstants {
+
+	private PortletAwareInterceptor interceptor;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		interceptor = new PortletAwareInterceptor();
+	}
+	
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+	
+	public void testPortletRequestIsSet() throws Exception {
+		PortletRequest request = EasyMock.createMock(PortletRequest.class);
+		Map<String, Object> ctx = new HashMap<String, Object>();
+		ctx.put(REQUEST, request);
+		PortletRequestAware action = EasyMock.createMock(PortletRequestAware.class);
+		action.setPortletRequest(request);
+		
+		ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
+		EasyMock.expect(invocation.getInvocationContext()).andReturn(new ActionContext(ctx));
+		EasyMock.expect(invocation.getAction()).andReturn(action);
+		
+		EasyMock.replay(action);
+		EasyMock.replay(invocation);
+		
+		interceptor.intercept(invocation);
+		
+		EasyMock.verify(action);
+	}
+}

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,159 @@
+/*
+ * $Id: PortletStateInterceptorTest.java 590812 2007-10-31 20:32:54Z apetrelli $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.portlet.interceptor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.ActionResponse;
+import javax.portlet.RenderRequest;
+
+import junit.framework.TestCase;
+
+import org.apache.struts2.StrutsTestCase;
+import org.apache.struts2.dispatcher.DefaultActionSupport;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction;
+import org.easymock.EasyMock;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.util.ValueStack;
+import com.opensymphony.xwork2.util.ValueStackFactory;
+
+public class PortletStateInterceptorTest extends StrutsTestCase implements PortletActionConstants {
+
+	private PortletStateInterceptor interceptor;
+	
+	public void setUp() throws Exception {
+	    super.setUp();
+		interceptor = new PortletStateInterceptor();
+	}
+	
+	public void testCopyValueStackFromEventToRenderPhase() throws Exception {
+		ActionResponse actionResponse = EasyMock.createNiceMock(ActionResponse.class);
+		ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
+		
+		Map<String, Object> ctxMap = new HashMap<String, Object>();
+		ctxMap.put(PHASE, ACTION_PHASE);
+		ctxMap.put(RESPONSE, actionResponse);
+		Map<String, Object> session = new HashMap<String, Object>();
+		
+		ActionContext ctx = new ActionContext(ctxMap);
+		ctx.setSession(session);
+		EasyMock.expect(invocation.getInvocationContext()).andStubReturn(ctx);
+		actionResponse.setRenderParameter(EVENT_ACTION, "true");
+		
+		ValueStack stack = container.getInstance(ValueStackFactory.class).createValueStack();
+		EasyMock.expect(invocation.getStack()).andStubReturn(stack);
+		
+		EasyMock.replay(actionResponse);
+		EasyMock.replay(invocation);
+		
+		interceptor.intercept(invocation);
+		
+		EasyMock.verify(actionResponse);
+		EasyMock.verify(invocation);
+		
+		assertSame(stack, session.get(STACK_FROM_EVENT_PHASE));
+		
+	}
+	
+	public void testDoNotRestoreValueStackInRenderPhaseWhenProperPrg() throws Exception {
+		RenderRequest renderRequest = EasyMock.createNiceMock(RenderRequest.class);
+		ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
+		
+		
+		ValueStack eventPhaseStack = container.getInstance(ValueStackFactory.class).createValueStack();
+		eventPhaseStack.set("testKey", "testValue");
+		
+		ValueStack currentStack = container.getInstance(ValueStackFactory.class).createValueStack();
+		currentStack.set("anotherTestKey", "anotherTestValue");
+		
+		Map<String, Object> ctxMap = new HashMap<String, Object>();
+		Map<String, Object> session = new HashMap<String, Object>();
+		
+		session.put(STACK_FROM_EVENT_PHASE, eventPhaseStack);
+		
+		ctxMap.put(PHASE, RENDER_PHASE);
+		ctxMap.put(REQUEST, renderRequest);
+		
+		ActionContext ctx = new ActionContext(ctxMap);
+		ctx.setSession(session);
+		
+		EasyMock.expect(invocation.getInvocationContext()).andStubReturn(ctx);
+		EasyMock.expect(invocation.getStack()).andStubReturn(currentStack);
+		EasyMock.expect(invocation.getAction()).andStubReturn(new DefaultActionSupport());
+		EasyMock.expect(renderRequest.getParameter(EVENT_ACTION)).andStubReturn("true");
+		
+		EasyMock.replay(renderRequest);
+		EasyMock.replay(invocation);
+		
+		interceptor.intercept(invocation);
+		
+		ValueStack resultingStack = invocation.getStack();
+		
+		assertNull(resultingStack.findValue("testKey"));
+		assertEquals("anotherTestValue", resultingStack.findValue("anotherTestKey"));
+		
+		
+	}
+	
+	public void testRestoreValueStackInRenderPhaseWhenNotProperPrg() throws Exception {
+		RenderRequest renderRequest = EasyMock.createNiceMock(RenderRequest.class);
+		ActionInvocation invocation = EasyMock.createNiceMock(ActionInvocation.class);
+		
+		ValueStack eventPhaseStack = container.getInstance(ValueStackFactory.class).createValueStack();
+		eventPhaseStack.set("testKey", "testValue");
+		
+		ValueStack currentStack = container.getInstance(ValueStackFactory.class).createValueStack();
+		currentStack.set("anotherTestKey", "anotherTestValue");
+		
+		EasyMock.expect(invocation.getStack()).andStubReturn(currentStack);
+		
+		Map<String, Object> ctxMap = new HashMap<String, Object>();
+		Map<String, Object> session = new HashMap<String, Object>();
+		
+		session.put(STACK_FROM_EVENT_PHASE, eventPhaseStack);
+		
+		ctxMap.put(PHASE, RENDER_PHASE);
+		ctxMap.put(REQUEST, renderRequest);
+		
+		ActionContext ctx = new ActionContext(ctxMap);
+		ctx.setSession(session);
+		
+		EasyMock.expect(invocation.getInvocationContext()).andStubReturn(ctx);
+		EasyMock.expect(invocation.getStack()).andStubReturn(currentStack);
+		EasyMock.expect(invocation.getAction()).andStubReturn(new DirectRenderFromEventAction());
+		EasyMock.expect(renderRequest.getParameter(EVENT_ACTION)).andStubReturn("true");
+		
+		EasyMock.replay(renderRequest);
+		EasyMock.replay(invocation);
+		
+		interceptor.intercept(invocation);
+		
+		ValueStack resultingStack = invocation.getStack();
+		assertEquals("testValue", resultingStack.findValue("testKey"));
+		assertEquals("anotherTestValue", resultingStack.findValue("anotherTestKey"));
+		
+		
+	}
+}

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,238 @@
+/*
+ * $Id: PortletResultTest.java 564926 2007-08-11 14:31:18Z nilsga $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.portlet.result;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.ActionRequest;
+import javax.portlet.ActionResponse;
+import javax.portlet.PortletConfig;
+import javax.portlet.PortletContext;
+import javax.portlet.PortletMode;
+import javax.portlet.PortletRequestDispatcher;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+
+import junit.textui.TestRunner;
+
+import org.apache.struts2.StrutsConstants;
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+import org.jmock.core.Constraint;
+
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+
+/**
+ * PortletResultTest. Insert description.
+ *
+ */
+public class PortletResultTest extends MockObjectTestCase implements PortletActionConstants {
+
+    Mock mockInvocation = null;
+    Mock mockConfig = null;
+    Mock mockCtx = null;
+
+    public void setUp() throws Exception {
+        super.setUp();
+        mockInvocation = mock(ActionInvocation.class);
+        mockCtx = mock(PortletContext.class);
+
+        Map paramMap = new HashMap();
+        Map sessionMap = new HashMap();
+
+        Map context = new HashMap();
+        context.put(ActionContext.SESSION, sessionMap);
+        context.put(ActionContext.PARAMETERS, paramMap);
+        context.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, mockCtx.proxy());
+
+        ActionContext.setContext(new ActionContext(context));
+
+        mockInvocation.stubs().method("getInvocationContext").will(returnValue(ActionContext.getContext()));
+
+    }
+
+    public void testDoExecute_render() {
+        Mock mockRequest = mock(RenderRequest.class);
+        Mock mockResponse = mock(RenderResponse.class);
+        Mock mockRd = mock(PortletRequestDispatcher.class);
+
+        RenderRequest req = (RenderRequest)mockRequest.proxy();
+        RenderResponse res = (RenderResponse)mockResponse.proxy();
+        PortletRequestDispatcher rd = (PortletRequestDispatcher)mockRd.proxy();
+        PortletContext ctx = (PortletContext)mockCtx.proxy();
+        ActionInvocation inv = (ActionInvocation)mockInvocation.proxy();
+
+        Constraint[] params = new Constraint[]{same(req), same(res)};
+        mockRd.expects(once()).method("include").with(params);
+        mockCtx.expects(once()).method("getRequestDispatcher").with(eq("/WEB-INF/pages/testPage.jsp")).will(returnValue(rd));
+        mockResponse.expects(once()).method("setContentType").with(eq("text/html"));
+
+        mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
+
+        ActionContext ctxMap = ActionContext.getContext();
+        ctxMap.put(PortletActionConstants.RESPONSE, res);
+        ctxMap.put(PortletActionConstants.REQUEST, req);
+        ctxMap.put(StrutsStatics.SERVLET_CONTEXT, ctx);
+        ctxMap.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+
+        PortletResult result = new PortletResult();
+        try {
+            result.doExecute("/WEB-INF/pages/testPage.jsp", inv);
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            fail("Error occured!");
+        }
+
+    }
+
+    public void testDoExecute_event_locationIsAction() {
+
+        Mock mockRequest = mock(ActionRequest.class);
+        Mock mockResponse = mock(ActionResponse.class);
+
+        Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("testView")};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        params = new Constraint[]{eq(PortletActionConstants.MODE_PARAM), eq(PortletMode.VIEW.toString())};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
+        ActionContext ctx = ActionContext.getContext();
+
+        ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy());
+        ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy());
+        ctx.put(PortletActionConstants.PHASE, PortletActionConstants.ACTION_PHASE);
+
+        PortletResult result = new PortletResult();
+        try {
+            result.doExecute("testView.action", (ActionInvocation)mockInvocation.proxy());
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            fail("Error occured!");
+        }
+
+    }
+
+    public void testDoExecute_event_locationIsJsp() {
+        Mock mockRequest = mock(ActionRequest.class);
+        Mock mockResponse = mock(ActionResponse.class);
+
+        Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("renderDirect")};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        params = new Constraint[]{eq(PortletActionConstants.MODE_PARAM), eq(PortletMode.VIEW.toString())};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
+
+        ActionContext ctx = ActionContext.getContext();
+
+        Map session = new HashMap();
+        
+        ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy());
+        ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy());
+        ctx.put(PortletActionConstants.PHASE, PortletActionConstants.ACTION_PHASE);
+        ctx.put(ActionContext.SESSION, session);
+
+        PortletResult result = new PortletResult();
+        try {
+            result.doExecute("/WEB-INF/pages/testJsp.jsp", (ActionInvocation)mockInvocation.proxy());
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            fail("Error occured!");
+        }
+        assertEquals("/WEB-INF/pages/testJsp.jsp", session.get(RENDER_DIRECT_LOCATION));
+    }
+
+    public void testDoExecute_event_locationHasQueryParams() {
+        Mock mockRequest = mock(ActionRequest.class);
+        Mock mockResponse = mock(ActionResponse.class);
+
+        Constraint[] params = new Constraint[]{eq(PortletActionConstants.ACTION_PARAM), eq("testView")};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        params = new Constraint[]{eq("testParam1"), eq("testValue1")};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        params = new Constraint[]{eq("testParam2"), eq("testValue2")};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        params = new Constraint[]{eq(PortletActionConstants.MODE_PARAM), eq(PortletMode.VIEW.toString())};
+        mockResponse.expects(once()).method("setRenderParameter").with(params);
+        mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
+
+        ActionContext ctx = ActionContext.getContext();
+
+        ctx.put(PortletActionConstants.REQUEST, mockRequest.proxy());
+        ctx.put(PortletActionConstants.RESPONSE, mockResponse.proxy());
+        ctx.put(PortletActionConstants.PHASE, PortletActionConstants.ACTION_PHASE);
+
+        PortletResult result = new PortletResult();
+        try {
+            result.doExecute("testView.action?testParam1=testValue1&testParam2=testValue2", (ActionInvocation)mockInvocation.proxy());
+        }
+        catch(Exception e) {
+            e.printStackTrace();
+            fail("Error occured!");
+        }
+    }
+
+    public void testTitleAndContentType() throws Exception {
+        Mock mockRequest = mock(RenderRequest.class);
+        Mock mockResponse = mock(RenderResponse.class);
+        Mock mockRd = mock(PortletRequestDispatcher.class);
+
+        RenderRequest req = (RenderRequest)mockRequest.proxy();
+        RenderResponse res = (RenderResponse)mockResponse.proxy();
+        PortletRequestDispatcher rd = (PortletRequestDispatcher)mockRd.proxy();
+        PortletContext ctx = (PortletContext)mockCtx.proxy();
+
+        Constraint[] params = new Constraint[]{same(req), same(res)};
+        mockRd.expects(once()).method("include").with(params);
+        mockCtx.expects(once()).method("getRequestDispatcher").with(eq("/WEB-INF/pages/testPage.jsp")).will(returnValue(rd));
+
+        mockRequest.stubs().method("getPortletMode").will(returnValue(PortletMode.VIEW));
+
+        ActionContext ctxMap = ActionContext.getContext();
+        ctxMap.put(PortletActionConstants.RESPONSE, res);
+        ctxMap.put(PortletActionConstants.REQUEST, req);
+        ctxMap.put(StrutsStatics.SERVLET_CONTEXT, ctx);
+        ctxMap.put(PortletActionConstants.PHASE, PortletActionConstants.RENDER_PHASE);
+
+        mockResponse.expects(atLeastOnce()).method("setTitle").with(eq("testTitle"));
+        mockResponse.expects(atLeastOnce()).method("setContentType").with(eq("testContentType"));
+
+        PortletResult result = new PortletResult();
+        result.setTitle("testTitle");
+        result.setContentType("testContentType");
+        result.doExecute("/WEB-INF/pages/testPage.jsp", (ActionInvocation)mockInvocation.proxy());
+    }
+
+    public void tearDown() throws Exception {
+        super.tearDown();
+        ActionContext.setContext(null);
+    }
+
+    public static void main(String[] args) {
+        TestRunner.run(PortletResultTest.class);
+    }
+
+}

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/portlet/util/PortletUrlHelperTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,159 @@
+/*
+ * $Id: PortletUrlHelperTest.java 564967 2007-08-11 20:20:33Z nilsga $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.struts2.portlet.util;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletMode;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+
+import junit.framework.TestCase;
+
+import org.apache.struts2.portlet.context.PortletActionContext;
+import org.easymock.MockControl;
+
+import com.opensymphony.xwork2.ActionContext;
+
+/**
+ */
+public class PortletUrlHelperTest extends TestCase {
+
+    RenderResponse renderResponse;
+
+    RenderRequest renderRequest;
+
+    PortletURL url;
+
+    MockControl renderResponseControl;
+
+    MockControl renderRequestControl;
+
+    MockControl portletUrlControl;
+
+    public void setUp() throws Exception {
+        super.setUp();
+
+        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 modeNamespaceMap = new HashMap();
+        modeNamespaceMap.put("view", "/view");
+        modeNamespaceMap.put("edit", "/edit");
+        modeNamespaceMap.put("help", "/help");
+
+        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 {
+        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
+                url);
+
+        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);
+        portletUrlControl.verify();
+        renderRequestControl.verify();
+        renderResponseControl.verify();
+    }
+
+    public void testCreateRenderUrlWithDifferentPortletMode() throws Exception {
+        renderResponseControl.expectAndReturn(renderResponse.createRenderURL(),
+                url);
+
+        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);
+        portletUrlControl.verify();
+        renderRequestControl.verify();
+        renderResponseControl.verify();
+    }
+
+    public void testCreateRenderUrlWithDifferentWindowState() throws Exception {
+        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");
+        portletUrlControl.verify();
+        renderRequestControl.verify();
+        renderResponseControl.verify();
+    }
+
+    public void testCreateActionUrl() throws Exception {
+        renderResponseControl.expectAndReturn(renderResponse.createActionURL(),
+                url);
+
+        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();
+    }
+
+}

Added: struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java
URL: http://svn.apache.org/viewvc/struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java?rev=613823&view=auto
==============================================================================
--- struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java (added)
+++ struts/sandbox/trunk/struts2-portlet2-plugin/src/test/java/org/apache/struts2/views/jsp/PortletUrlTagTest.java Mon Jan 21 02:09:00 2008
@@ -0,0 +1,403 @@
+/*
+ * $Id: PortletUrlTagTest.java 609901 2008-01-08 08:18:23Z nilsga $
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * 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.PortletMode;
+import javax.portlet.PortletRequest;
+import javax.portlet.PortletResponse;
+import javax.portlet.PortletURL;
+import javax.portlet.RenderRequest;
+import javax.portlet.RenderResponse;
+import javax.portlet.WindowState;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import javax.servlet.jsp.PageContext;
+
+import junit.textui.TestRunner;
+
+import org.apache.struts2.dispatcher.Dispatcher;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.apache.struts2.portlet.util.PortletUrlHelper;
+import org.jmock.Mock;
+import org.jmock.cglib.MockObjectTestCase;
+import org.jmock.core.Constraint;
+
+import com.mockobjects.servlet.MockJspWriter;
+import com.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.ActionInvocation;
+import com.opensymphony.xwork2.ActionProxy;
+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;
+
+    Mock mockPortletReq = null;
+
+    Mock mockPortletRes = null;
+
+    Mock mockPageCtx = null;
+
+    Mock mockPortletUrl = null;
+
+    MockJspWriter mockJspWriter = 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();
+
+        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);
+        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()));
+
+        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()));
+
+        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()));
+
+        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()));
+
+        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");
+        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");
+
+        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");
+
+        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()));
+    	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()));
+    	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;
+        }
+
+
+
+    }
+
+}