Author: lukaszlenart
Date: Sun Jan 1 17:29:25 2012
New Revision: 1226265
URL: http://svn.apache.org/viewvc?rev=1226265&view=rev
Log:
WW-3733 - adds missing PortletContext to ActionContext to avoid NPE during
PortletResult initialisation
Modified:
struts/struts2/trunk/plugins/junit/pom.xml
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
struts/struts2/trunk/plugins/junit/src/test/java/org/apache/struts2/StrutsTestCaseTest.java
struts/struts2/trunk/plugins/portlet/pom.xml
struts/struts2/trunk/pom.xml
Modified: struts/struts2/trunk/plugins/junit/pom.xml
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/pom.xml?rev=1226265&r1=1226264&r2=1226265&view=diff
==
--- struts/struts2/trunk/plugins/junit/pom.xml (original)
+++ struts/struts2/trunk/plugins/junit/pom.xml Sun Jan 1 17:29:25 2012
@@ -55,7 +55,6 @@
org.apache.struts
struts2-spring-plugin
-${project.version}
true
@@ -67,5 +66,11 @@
junit
junit
+
+
+javax.portlet
+portlet-api
+test
+
Modified:
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
URL:
http://svn.apache.org/viewvc/struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java?rev=1226265&r1=1226264&r2=1226265&view=diff
==
---
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
(original)
+++
struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
Sun Jan 1 17:29:25 2012
@@ -37,6 +37,7 @@ import org.springframework.mock.web.Mock
import org.springframework.mock.web.MockHttpServletResponse;
import org.springframework.mock.web.MockPageContext;
import org.springframework.mock.web.MockServletContext;
+import org.springframework.mock.web.portlet.MockPortletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@@ -46,7 +47,11 @@ import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;
-import java.util.logging.*;
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+import java.util.logging.Logger;
/**
* Base test case for JUnit testing Struts.
@@ -57,7 +62,7 @@ public abstract class StrutsTestCase ext
protected MockPageContext pageContext;
protected MockServletContext servletContext;
protected Map dispatcherInitParams;
-
+
protected DefaultResourceLoader resourceLoader = new
DefaultResourceLoader();
static {
@@ -109,10 +114,9 @@ public abstract class StrutsTestCase ext
assertNotNull(mapping);
Dispatcher.getInstance().serviceAction(request, response,
servletContext, mapping);
-if (response.getStatus() != HttpServletResponse.SC_OK)
-throw new ServletException("Error code [" + response.getStatus() +
"], Error: ["
-+ response.getErrorMessage() + "]");
-
+if (response.getStatus() != HttpServletResponse.SC_OK) {
+throw new ServletException("Error code [" + response.getStatus() +
"], Error: [" + response.getErrorMessage() + "]");
+}
return response.getContentAsString();
}
@@ -131,12 +135,9 @@ public abstract class StrutsTestCase ext
ActionProxy proxy =
config.getContainer().getInstance(ActionProxyFactory.class).createActionProxy(
namespace, name, method, new HashMap(), true,
false);
-ActionContext invocationContext =
proxy.getInvocation().getInvocationContext();
-invocationContext.setParameters(new
HashMap(request.getParameterMap()));
-// set the action context to the one used by the proxy
-ActionContext.setContext(invocationContext);
+initActionContext(proxy.getInvocation().getInvocationContext());
-// this is normaly done in onSetUp(), but we are using Struts internal
+// this is normally done in onSetUp(), but we are using Struts internal
// objects (proxy and action invocation)
// so we have to hack around so it works
ServletActionContext.setServletContext(servletContext);
@@ -146,6 +147,29 @@ public abstract class StrutsTestCase ext
return proxy;
}
+private void initActionContext(ActionContext actionContext) {
+actionContext.setParameters(new HashMap(request.getParameterMap()));
+
+initMockPortletContext(actionContext);
+applyAdditionalParams(actionContext);
+
+// set the action context to the one used by the proxy
+ActionContext.setContext(action