struts-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jo...@apache.org
Subject svn commit: r1139061 [4/5] - in /struts/archive/plugins: ./ 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/apache/struts2/portl...
Date Thu, 23 Jun 2011 20:18:46 GMT
Added: struts/archive/plugins/src/main/resources/LICENSE.txt
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/resources/LICENSE.txt?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/main/resources/LICENSE.txt (added)
+++ struts/archive/plugins/src/main/resources/LICENSE.txt Thu Jun 23 20:18:43 2011
@@ -0,0 +1,174 @@
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.

Added: struts/archive/plugins/src/main/resources/NOTICE.txt
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/resources/NOTICE.txt?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/main/resources/NOTICE.txt (added)
+++ struts/archive/plugins/src/main/resources/NOTICE.txt Thu Jun 23 20:18:43 2011
@@ -0,0 +1,5 @@
+Apache Struts
+Copyright 2000-2011 The Apache Software Foundation
+
+This product includes software developed by
+The Apache Software Foundation (http://www.apache.org/).
\ No newline at end of file

Added: struts/archive/plugins/src/main/resources/struts-plugin.xml
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/main/resources/struts-plugin.xml?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/main/resources/struts-plugin.xml (added)
+++ struts/archive/plugins/src/main/resources/struts-plugin.xml Thu Jun 23 20:18:43 2011
@@ -0,0 +1,78 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+/*
+ * $Id: struts-plugin.xml 669193 2008-06-18 14:47:55Z hermanns $
+ *
+ * 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.
+ */
+-->
+<!DOCTYPE struts PUBLIC
+    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
+    "http://struts.apache.org/dtds/struts-2.0.dtd">
+    
+<struts>
+	
+	<bean type="org.apache.struts2.components.UrlRenderer" name="portlet" class="org.apache.struts2.components.PortletUrlRenderer"/>
+	
+	<constant name="struts.urlRenderer" value="portlet" />
+	<constant name="struts.portlet.useDispatcherServlet" value="false" />
+	<constant name="struts.portlet.dispatcherServletName" value="Struts2PortletDispatcherServlet" />
+	<constant name="struts.objectFactory.spring.autoWire.alwaysRespect" value="false" />
+
+    <package name="struts-portlet-default" extends="struts-default">
+
+	   <result-types>
+			<result-type name="dispatcher" class="org.apache.struts2.portlet.result.PortletResult" default="true"/>
+            <result-type name="redirect" class="org.apache.struts2.portlet.result.PortletResult"/>
+		    <result-type name="redirectAction" class="org.apache.struts2.portlet.result.PortletActionRedirectResult"/>
+			<result-type name="freemarker" class="org.apache.struts2.views.freemarker.PortletFreemarkerResult"/>
+			<result-type name="velocity" class="org.apache.struts2.portlet.result.PortletVelocityResult"/>
+	   </result-types>
+       
+       <interceptors>
+        <interceptor name="portletAware" class="org.apache.struts2.portlet.interceptor.PortletAwareInterceptor"/>
+		<interceptor name="portletState" class="org.apache.struts2.portlet.interceptor.PortletStateInterceptor"/>
+		<!-- Default stack for operating in portlet environment -->
+        <interceptor-stack name="portletDefaultStack">
+			<interceptor-ref name="portletState"/>
+            <interceptor-ref name="portletAware"/>
+            <interceptor-ref name="defaultStack"/>
+        </interceptor-stack>
+        <!-- Extension of the default portlet stack which also includes the token interceptor --> 
+		<interceptor-stack name="portletDefaultStackWithToken">
+			<interceptor-ref name="portletState"/>
+			<interceptor-ref name="portletAware"/>
+			<interceptor-ref name="token"/>
+			<interceptor-ref name="defaultStack"/>
+		</interceptor-stack>
+		   
+       </interceptors>
+       
+       <default-interceptor-ref name="portletDefaultStack"/>
+		
+	   <action name="renderDirect" class="org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction">
+	   		<result name="success">${location}</result>
+	   </action>
+	   <action name="freemarkerDirect" class="org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction">
+	   		<result type="freemarker" name="success">${location}</result>
+	   </action>
+	   <action name="velocityDirect" class="org.apache.struts2.portlet.dispatcher.DirectRenderFromEventAction">
+	   		<result type="velocity" name="success">${location}</result>
+	   </action>
+	</package>
+</struts>

Added: struts/archive/plugins/src/test/java/org/apache/struts2/components/PortletUrlRendererTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/components/PortletUrlRendererTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/components/PortletUrlRendererTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/components/PortletUrlRendererTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,237 @@
+/*
+ * $Id$
+ *
+ * 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.components;
+
+import java.io.IOException;
+import java.io.StringWriter;
+import java.io.Writer;
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletMode;
+import javax.portlet.PortletURL;
+
+import org.apache.struts2.StrutsStatics;
+import org.apache.struts2.StrutsTestCase;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.apache.struts2.portlet.context.PortletActionContext;
+import org.apache.struts2.portlet.servlet.PortletServletRequest;
+import org.apache.struts2.portlet.servlet.PortletServletResponse;
+import org.easymock.EasyMock;
+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.opensymphony.xwork2.ActionContext;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+import com.opensymphony.xwork2.mock.MockActionProxy;
+import com.opensymphony.xwork2.util.ValueStack;
+
+public class PortletUrlRendererTest extends StrutsTestCase {
+
+	PortletUrlRenderer renderer;
+	MockPortletURL renderUrl;
+	MockPortletURL actionUrl;
+	MockRenderRequest request;
+	MockRenderResponse response;
+	MockPortletContext context;
+	ActionContext ctx;
+	ValueStack stack;
+
+	public void setUp() throws Exception {
+		super.setUp();
+		renderer = new PortletUrlRenderer();
+		context = new MockPortletContext();
+		renderUrl = new MockPortletURL(
+				new MockPortalContext(), "render");
+		actionUrl = new MockPortletURL(
+				new MockPortalContext(), "action");
+		request = new MockRenderRequest();
+		response = new MockRenderResponse() {
+			@Override
+			public PortletURL createActionURL() {
+				return actionUrl;
+			}
+			@Override
+			public PortletURL createRenderURL() {
+				return renderUrl;
+			}
+		};
+
+		ctx = ActionContext.getContext();
+		ctx.put(PortletActionConstants.PHASE,
+				PortletActionConstants.RENDER_PHASE);
+		ctx.put(PortletActionConstants.REQUEST, request);
+		ctx.put(PortletActionConstants.RESPONSE, response);
+		ctx.put(StrutsStatics.STRUTS_PORTLET_CONTEXT, context);
+
+		Map<PortletMode, String> modeMap = new HashMap<PortletMode, String>();
+		modeMap.put(PortletMode.VIEW, "/view");
+		ctx.put(PortletActionConstants.MODE_NAMESPACE_MAP, modeMap);
+		stack = ctx.getValueStack();
+	}
+
+	/**
+	 * Ensure that the namespace of the current executing action is used when no
+	 * namespace is specified. (WW-1875)
+	 */
+	public void testShouldIncludeCurrentNamespaceIfNoNamespaceSpecifiedForRenderUrl()
+			throws Exception {
+		
+		URL url = new URL(stack, new PortletServletRequest(request, null),
+				new PortletServletResponse(response));
+
+		MockActionInvocation ai = new MockActionInvocation();
+		MockActionProxy ap = new MockActionProxy();
+		ap.setActionName("testAction");
+		ap.setNamespace("/current_namespace");
+		ai.setProxy(ap);
+		ai.setStack(stack);
+		ai.setAction(new Object());
+		ctx.setActionInvocation(ai);
+
+		StringWriter renderOutput = new StringWriter();
+		renderer.renderUrl(renderOutput, url.getUrlProvider());
+
+		String action = renderUrl
+				.getParameter(PortletActionConstants.ACTION_PARAM);
+		assertEquals("/view/current_namespace/testAction", action);
+	}
+
+	/**
+	 * Ensure that the namespace of the current executing action is used when no
+	 * namespace is specified. (WW-1875)
+	 */
+	public void testShouldIncludeCurrentNamespaceIfNoNamespaceSpecifiedForRenderFormUrl()
+			throws Exception {
+
+		Form form = new Form(stack, new PortletServletRequest(request, null),
+				new PortletServletResponse(response));
+
+		MockActionInvocation ai = new MockActionInvocation();
+		MockActionProxy ap = new MockActionProxy();
+		ap.setActionName("testAction");
+		ap.setNamespace("/current_namespace");
+		ai.setProxy(ap);
+		ai.setStack(stack);
+		ai.setAction(new Object());
+		ctx.setActionInvocation(ai);
+
+		renderer.renderFormUrl(form);
+
+		String action = actionUrl
+				.getParameter(PortletActionConstants.ACTION_PARAM);
+		assertEquals("/view/current_namespace/testAction", action);
+	}
+	
+	public void testShouldEvaluateActionAsOGNLExpression() throws Exception {
+		
+		TestObject obj = new TestObject();
+		obj.someProperty = "EvaluatedProperty";
+		stack.push(obj);
+		MockActionInvocation ai = new MockActionInvocation();
+		MockActionProxy ap = new MockActionProxy();
+		ap.setActionName("testAction");
+		ap.setNamespace("");
+		ai.setProxy(ap);
+		ai.setStack(stack);
+		ctx.setActionInvocation(ai);
+		
+		URL url = new URL(stack, new PortletServletRequest(request, null),
+				new PortletServletResponse(response));
+		url.setAction("%{someProperty}");
+		
+		StringWriter renderOutput = new StringWriter();
+		renderer.renderUrl(renderOutput, url.getUrlProvider());
+
+		String action = renderUrl
+				.getParameter(PortletActionConstants.ACTION_PARAM);
+		assertEquals("/view/EvaluatedProperty", action);
+		
+	}
+	
+	public void testShouldEvaluateAnchorAsOGNLExpression() throws Exception {
+		
+		TestObject obj = new TestObject();
+		obj.someProperty = "EvaluatedProperty";
+		stack.push(obj);
+		MockActionInvocation ai = new MockActionInvocation();
+		MockActionProxy ap = new MockActionProxy();
+		ap.setActionName("testAction");
+		ap.setNamespace("");
+		ai.setProxy(ap);
+		ai.setStack(stack);
+		ctx.setActionInvocation(ai);
+		
+		URL url = new URL(stack, new PortletServletRequest(request, null),
+				new PortletServletResponse(response));
+		url.setAnchor("%{someProperty}");
+		
+		StringWriter renderOutput = new StringWriter();
+		renderer.renderUrl(renderOutput, url.getUrlProvider());
+		assertTrue(renderOutput.toString().indexOf("#EvaluatedProperty") != -1);
+		
+	}
+	
+	public void testShouldPassThroughRenderUrlToServletUrlRendererIfNotPortletRequest() throws Exception {
+		UrlRenderer mockRenderer = EasyMock.createMock(UrlRenderer.class);
+		ActionContext.getContext().put(StrutsStatics.STRUTS_PORTLET_CONTEXT, null);
+		renderer.setServletRenderer(mockRenderer);
+		URL url = new URL(stack, new PortletServletRequest(request, null), new PortletServletResponse(response));
+		StringWriter renderOutput = new StringWriter();
+		mockRenderer.renderUrl(renderOutput, url.getUrlProvider());
+		EasyMock.replay(mockRenderer);
+		renderer.renderUrl(renderOutput, url.getUrlProvider());
+		EasyMock.verify(mockRenderer);
+	}
+	
+	public void testShouldPassThroughRenderFormUrlToServletUrlRendererIfNotPortletRequest() throws Exception {
+		UrlRenderer mockRenderer = EasyMock.createMock(UrlRenderer.class);
+		ActionContext.getContext().put(StrutsStatics.STRUTS_PORTLET_CONTEXT, null);
+		renderer.setServletRenderer(mockRenderer);
+		Form form = new Form(stack, new PortletServletRequest(request, null), new PortletServletResponse(response));
+		mockRenderer.renderFormUrl(form);
+		EasyMock.replay(mockRenderer);
+		renderer.renderFormUrl(form);
+		EasyMock.verify(mockRenderer);
+	}
+	
+	public void testShouldPassThroughRenderUrlToServletUrlRendererWhenPortletUrlTypeIsNone() throws Exception {
+		UrlRenderer mockRenderer = EasyMock.createMock(UrlRenderer.class);
+		renderer.setServletRenderer(mockRenderer);
+		URL url = new URL(stack, new PortletServletRequest(request, null), new PortletServletResponse(response));
+		url.setPortletUrlType("none");
+		StringWriter renderOutput = new StringWriter();
+		mockRenderer.renderUrl(renderOutput, url.getUrlProvider());
+		EasyMock.replay(mockRenderer);
+		renderer.renderUrl(renderOutput, url.getUrlProvider());
+		EasyMock.verify(mockRenderer);
+	}
+	
+	private final static class TestObject {
+		public String someProperty;
+	}
+	
+	
+}

Added: struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletApplicationMapTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,170 @@
+/*
+ * $Id: PortletApplicationMapTest.java 651946 2008-04-27 13:41:38Z 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;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.Enumeration;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PortletContext;
+
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+import org.jmock.core.Constraint;
+
+/**
+ */
+public class PortletApplicationMapTest extends MockObjectTestCase {
+
+    Mock mockPortletContext;
+
+    PortletContext portletContext;
+
+    public void setUp() throws Exception {
+        super.setUp();
+        mockPortletContext = mock(PortletContext.class);
+        portletContext = (PortletContext) mockPortletContext.proxy();
+    }
+
+    public void testGetFromAttributes() {
+        mockPortletContext.stubs().method("getAttribute").with(eq("dummyKey"))
+                .will(returnValue("dummyValue"));
+
+        PortletApplicationMap map = new PortletApplicationMap(
+                (PortletContext) mockPortletContext.proxy());
+
+        assertEquals("dummyValue", map.get("dummyKey"));
+    }
+
+    public void testGetFromInitParameters() {
+        mockPortletContext.stubs().method("getAttribute").with(eq("dummyKey"));
+        mockPortletContext.stubs().method("getInitParameter").with(
+                eq("dummyKey")).will(returnValue("dummyValue"));
+
+        PortletApplicationMap map = new PortletApplicationMap(
+                (PortletContext) mockPortletContext.proxy());
+
+        assertEquals("dummyValue", map.get("dummyKey"));
+    }
+
+    public void testPut() {
+        mockPortletContext.expects(once()).method("setAttribute").with(
+                new Constraint[] { eq("dummyKey"), eq("dummyValue") });
+        mockPortletContext.expects(once()).method("getAttribute").with(
+                eq("dummyKey")).will(returnValue("dummyValue"));
+        PortletApplicationMap map = new PortletApplicationMap(portletContext);
+        Object val = map.put("dummyKey", "dummyValue");
+        assertEquals("dummyValue", val);
+    }
+
+    public void testRemove() {
+        mockPortletContext.expects(once()).method("getAttribute").with(
+                eq("dummyKey")).will(returnValue("dummyValue"));
+        mockPortletContext.expects(once()).method("removeAttribute").with(
+                eq("dummyKey"));
+        PortletApplicationMap map = new PortletApplicationMap(portletContext);
+        Object val = map.remove("dummyKey");
+        assertEquals("dummyValue", val);
+    }
+
+    public void testEntrySet() {
+
+        Enumeration names = new Enumeration() {
+
+            List keys = Arrays.asList(new Object[] { "key1", "key2" });
+
+            Iterator it = keys.iterator();
+
+            public boolean hasMoreElements() {
+                return it.hasNext();
+            }
+
+            public Object nextElement() {
+                return it.next();
+            }
+
+        };
+        Enumeration initParamNames = new Enumeration() {
+
+            List keys = Arrays.asList(new Object[] { "key3" });
+
+            Iterator it = keys.iterator();
+
+            public boolean hasMoreElements() {
+                return it.hasNext();
+            }
+
+            public Object nextElement() {
+                return it.next();
+            }
+
+        };
+
+        mockPortletContext.stubs().method("getAttributeNames").will(
+                returnValue(names));
+        mockPortletContext.stubs().method("getInitParameterNames").will(
+                returnValue(initParamNames));
+        mockPortletContext.stubs().method("getAttribute").with(eq("key1"))
+                .will(returnValue("value1"));
+        mockPortletContext.stubs().method("getAttribute").with(eq("key2"))
+                .will(returnValue("value2"));
+        mockPortletContext.stubs().method("getInitParameter").with(eq("key3"))
+                .will(returnValue("value3"));
+
+        PortletApplicationMap map = new PortletApplicationMap(portletContext);
+        Set entries = map.entrySet();
+
+        assertEquals(3, entries.size());
+        Iterator it = entries.iterator();
+        Map.Entry entry = (Map.Entry) it.next();
+        assertEquals("key2", entry.getKey());
+        assertEquals("value2", entry.getValue());
+        entry = (Map.Entry) it.next();
+        assertEquals("key1", entry.getKey());
+        assertEquals("value1", entry.getValue());
+        entry = (Map.Entry) it.next();
+        assertEquals("key3", entry.getKey());
+        assertEquals("value3", entry.getValue());
+
+    }
+
+    public void testClear() {
+
+        mockPortletContext.expects(once()).method("removeAttribute").with(eq("key1"));
+        mockPortletContext.expects(once()).method("removeAttribute").with(eq("key2"));
+
+        ArrayList dummy = new ArrayList();
+        dummy.add("key1");
+        dummy.add("key2");
+
+        mockPortletContext.expects(once()).method("getAttributeNames").will(
+                returnValue(Collections.enumeration(dummy)));
+
+        PortletApplicationMap map = new PortletApplicationMap(portletContext);
+        map.clear();
+    }
+}

Added: struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletRequestMapTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,108 @@
+/*
+ * $Id: PortletRequestMapTest.java 651946 2008-04-27 13:41:38Z 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;
+
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Set;
+
+import javax.portlet.PortletRequest;
+
+import org.jmock.MockObjectTestCase;
+import org.springframework.mock.web.portlet.MockPortletRequest;
+
+
+/**
+ * PortletRequestMapTest. Insert description.
+ *
+ */
+public class PortletRequestMapTest extends MockObjectTestCase {
+
+    public void testGet() {
+    	PortletRequest request = new MockPortletRequest();
+    	request.setAttribute("testAttribute", "testValue");
+
+    	PortletRequestMap map = new PortletRequestMap(request);
+        String value = (String)map.get("testAttribute");
+        assertEquals("testValue", value);
+    }
+
+    public void testPut() {
+    	PortletRequest request = new MockPortletRequest();
+    	PortletRequestMap map = new PortletRequestMap(request);
+        Object obj = map.put("testAttribute", "testValue1");
+        
+        assertEquals(obj, "testValue1");
+        assertEquals("testValue1", request.getAttribute("testAttribute"));
+    }
+
+    public void testClear() {
+    	MockPortletRequest request = new MockPortletRequest();
+    	request.setAttribute("testAttribute1", "testValue1");
+    	request.setAttribute("testAttribute2", "testValue2");
+
+
+        PortletRequestMap map = new PortletRequestMap(request);
+        map.clear();
+
+        assertFalse(request.getAttributeNames().hasMoreElements());
+    }
+
+    public void testRemove() {
+        MockPortletRequest request = new MockPortletRequest();
+        request.setAttribute("testAttribute1", "testValue1");
+        
+        PortletRequestMap map = new PortletRequestMap(request);
+        assertEquals("testValue1", map.remove("testAttribute1"));
+        assertNull(request.getAttribute("testAttribute1"));
+    }
+
+    public void testEntrySet() {
+    	MockPortletRequest request = new MockPortletRequest();
+    	request.setAttribute("testAttribute1", "testValue1");
+    	request.setAttribute("testAttribute2", "testValue2");
+
+        PortletRequestMap map = new PortletRequestMap(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/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/PortletSessionMapTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,125 @@
+/*
+ * $Id: PortletSessionMapTest.java 651946 2008-04-27 13:41:38Z 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;
+
+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/archive/plugins/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/context/PortletActionContextTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,184 @@
+/*
+ * $Id: PortletActionContextTest.java 651946 2008-04-27 13:41:38Z 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.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.isEvent());
+    }
+
+    public void testIsEvent() {
+        context.put(PortletActionConstants.PHASE, PortletActionConstants.EVENT_PHASE);
+
+        assertTrue(PortletActionContext.isEvent());
+        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.EVENT_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.EVENT_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/archive/plugins/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/dispatcher/Jsr168DispatcherTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,299 @@
+/*
+ * $Id: Jsr168DispatcherTest.java 833239 2009-11-05 23:46:50Z rgielen $
+ *
+ * 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 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;
+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.MockPortletConfig;
+import org.springframework.mock.web.portlet.MockPortletContext;
+
+import javax.portlet.*;
+import java.util.*;
+
+/**
+ * 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() throws Exception {
+		super.setUp();
+		dispatcher = new Jsr168Dispatcher();
+	}
+
+	private void initPortletConfig(final Map<String, String> initParams, final Map<String, Object> 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() throws Exception {
+		final Mock mockResponse = mock(RenderResponse.class);
+		mockResponse.stubs().method(ANYTHING);
+
+		PortletMode mode = PortletMode.VIEW;
+
+		Map<String, String[]> requestParams = new HashMap<String, String[]>();
+		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<String, Object> sessionMap = new HashMap<String, Object>();
+
+		Map<String, String> initParams = new HashMap<String, String>();
+		initParams.put("viewNamespace", "/view");
+		initParams.put(StrutsConstants.STRUTS_ALWAYS_SELECT_FULL_NAMESPACE, "true");
+
+		initPortletConfig(initParams, new HashMap<String, Object>());
+		initRequest(requestParams, new HashMap<String, Object>(), sessionMap, new HashMap<String, String[]>(), 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)});
+		dispatcher.setActionProxyFactory((ActionProxyFactory) mockActionFactory.proxy());
+		dispatcher.init((PortletConfig) mockConfig.proxy());
+		dispatcher.render((RenderRequest) mockRequest.proxy(), (RenderResponse) mockResponse.proxy());
+	}
+
+	public void testProcessAction_ok() throws Exception {
+		final Mock mockResponse = mock(ActionResponse.class);
+
+		PortletMode mode = PortletMode.VIEW;
+		Map<String, String> initParams = new HashMap<String, String>();
+		initParams.put("viewNamespace", "/view");
+
+		Map<String, String[]> requestParams = new HashMap<String, String[]>();
+		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<String, Object>());
+		initRequest(requestParams, new HashMap<String, Object>(), new HashMap<String, Object>(), new HashMap<String, String[]>(), 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)});
+		dispatcher.setActionProxyFactory((ActionProxyFactory) mockActionFactory.proxy());
+		dispatcher.init((PortletConfig) mockConfig.proxy());
+		dispatcher.processAction((ActionRequest) mockRequest.proxy(), (ActionResponse) mockResponse.proxy());
+	}
+
+	/**
+	 * 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<String, String[]> requestParams, Map<String, Object> requestAttributes, Map<String, Object> sessionParams, Map<String, String[]> 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<String, String[]> requestParams, Mock mockRequest, String method) {
+		Map<String, String> newMap = new HashMap<String, String>();
+        for ( String key : requestParams.keySet() ) {
+            String[] val = 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) {
+        for ( Object key : map.keySet() ) {
+            Object val = map.get(key);
+            mock.stubs().method(method).with(eq(key)).will(returnValue(val));
+        }
+	}
+
+	public void testModeChangeUsingPortletWidgets() throws Exception {
+		final Mock mockResponse = mock(RenderResponse.class);
+		mockResponse.stubs().method(ANYTHING);
+		PortletMode mode = PortletMode.EDIT;
+
+		Map<String, String[]> requestParams = new HashMap<String, String[]>();
+		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<String, Object> sessionMap = new HashMap<String, Object>();
+
+		Map<String, String> initParams = new HashMap<String, String>();
+		initParams.put("viewNamespace", "/view");
+		initParams.put("editNamespace", "/edit");
+
+		initPortletConfig(initParams, new HashMap<String, Object>());
+		initRequest(requestParams, new HashMap<String, Object>(), sessionMap, new HashMap<String, String[]>(), 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)});
+		dispatcher.setActionProxyFactory((ActionProxyFactory) mockActionFactory.proxy());
+		dispatcher.init((PortletConfig) mockConfig.proxy());
+		dispatcher.render((RenderRequest) mockRequest.proxy(), (RenderResponse) mockResponse.proxy());
+	}
+
+}

Added: struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletAwareInterceptorTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,99 @@
+/*
+ * $Id: PortletAwareInterceptorTest.java 759073 2009-03-27 09:40:17Z 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.interceptor;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import javax.portlet.PortletConfig;
+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;
+	private TestAction action;
+	private PortletRequest portletRequest;
+	private PortletConfig portletConfig;
+	private Map<String, Object> contextMap;
+	private ActionInvocation invocation;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		interceptor = new PortletAwareInterceptor();
+		action = new TestAction();
+		portletRequest = EasyMock.createNiceMock(PortletRequest.class);
+		portletConfig = EasyMock.createNiceMock(PortletConfig.class);
+		contextMap = new HashMap<String, Object>();
+		invocation = EasyMock.createNiceMock(ActionInvocation.class);
+		EasyMock.expect(invocation.getAction()).andReturn(action);
+		EasyMock.expect(invocation.getInvocationContext()).andReturn(new ActionContext(contextMap));
+	}
+	
+	protected void tearDown() throws Exception {
+		super.tearDown();
+	}
+	
+	public void testPortletRequestIsSet() throws Exception {
+		contextMap.put(REQUEST, portletRequest);
+		EasyMock.replay(invocation);
+		interceptor.intercept(invocation);
+		assertEquals(portletRequest, action.getPortletRequest());
+	}
+	
+	public void testPortletConfigIsSet() throws Exception {
+		contextMap.put(PORTLET_CONFIG, portletConfig);
+		EasyMock.replay(invocation);
+		interceptor.intercept(invocation);
+		assertEquals(portletConfig, action.getPortletConfig());
+	}
+	
+	public static class TestAction implements PortletRequestAware, PortletConfigAware {
+
+		private PortletRequest request;
+		private PortletConfig config;
+
+		public void setPortletRequest(PortletRequest request) {
+			this.request = request;
+		}
+
+		public void setPortletConfig(PortletConfig portletConfig) {
+			this.config = portletConfig;
+		}
+
+		public PortletConfig getPortletConfig() {
+			return config;
+		}
+
+		public PortletRequest getPortletRequest() {
+			return request;
+		}
+		
+	}
+}

Added: struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/interceptor/PortletStateInterceptorTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,160 @@
+/*
+ * $Id: PortletStateInterceptorTest.java 651946 2008-04-27 13:41:38Z 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, EVENT_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/archive/plugins/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/result/PortletResultTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,246 @@
+/*
+ * $Id: PortletResultTest.java 670193 2008-06-21 13:01:53Z hermanns $
+ *
+ * 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;
+import com.opensymphony.xwork2.ActionProxy;
+import com.opensymphony.xwork2.mock.MockActionProxy;
+import com.opensymphony.xwork2.mock.MockActionInvocation;
+
+/**
+ * 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.EVENT_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);
+        Mock mockProxy = mock(ActionProxy.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));
+        mockProxy.stubs().method("getNamespace").will(returnValue(""));
+
+        mockInvocation.stubs().method("getProxy").will(returnValue(mockProxy.proxy()));
+
+        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.EVENT_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.EVENT_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/archive/plugins/src/test/java/org/apache/struts2/portlet/servlet/PortletServletRequestTest.java
URL: http://svn.apache.org/viewvc/struts/archive/plugins/src/test/java/org/apache/struts2/portlet/servlet/PortletServletRequestTest.java?rev=1139061&view=auto
==============================================================================
--- struts/archive/plugins/src/test/java/org/apache/struts2/portlet/servlet/PortletServletRequestTest.java (added)
+++ struts/archive/plugins/src/test/java/org/apache/struts2/portlet/servlet/PortletServletRequestTest.java Thu Jun 23 20:18:43 2011
@@ -0,0 +1,49 @@
+package org.apache.struts2.portlet.servlet;
+
+import org.apache.struts2.ServletActionContext;
+import org.apache.struts2.StrutsTestCase;
+import org.apache.struts2.dispatcher.mapper.ActionMapping;
+import org.apache.struts2.portlet.PortletActionConstants;
+import org.apache.struts2.portlet.context.PortletActionContext;
+import org.springframework.mock.web.portlet.MockPortletContext;
+import org.springframework.mock.web.portlet.MockPortletRequest;
+
+import com.opensymphony.xwork2.ActionContext;
+
+public class PortletServletRequestTest extends StrutsTestCase {
+	
+	private MockPortletRequest portletRequest;
+	private MockPortletContext portletContext;
+	private PortletServletRequest request;
+	
+	protected void setUp() throws Exception {
+		super.setUp();
+		portletRequest = new MockPortletRequest();
+		portletContext = new MockPortletContext();
+		request = new PortletServletRequest(portletRequest, portletContext);
+	}
+	
+	public void testGetServletPathShouldHandleDefaultActionExtension() throws Exception {
+		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
+		request.setExtension("action");
+		assertEquals("actionName.action", request.getServletPath());
+	}
+	
+	public void testGetServletPathShouldHandleCustomActionExtension() throws Exception {
+		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
+		request.setExtension("custom");
+		assertEquals("actionName.custom", request.getServletPath());
+	}
+	
+	public void testGetServletPathShouldHandleNoExtension() throws Exception {
+		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
+		request.setExtension("");
+		assertEquals("actionName", request.getServletPath());
+	}
+	
+	public void testGetServletPathShouldHandleMultipleExtensionsByUsingTheFirst() throws Exception {
+		portletRequest.setParameter(PortletActionConstants.ACTION_PARAM, "actionName");
+		request.setExtension("action,,");
+		assertEquals("actionName.action", request.getServletPath());
+	}
+}



Mime
View raw message