From 5c15306366dfdf47da3779300ab5303aa323ef07 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Tue, 10 Apr 2012 19:33:51 +0000 Subject: [PATCH] WW-3442 adds Session initialisation method to solve problem with missing session and allow to initialise session on its own in test cases git-svn-id: https://svn.apache.org/repos/asf/struts/struts2/trunk@1311951 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/struts2/StrutsTestCase.java | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java b/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java index 3e9c51fcd..d52a0dd6a 100644 --- a/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java +++ b/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java @@ -149,17 +149,23 @@ public abstract class StrutsTestCase extends XWorkTestCase { return proxy; } - private void initActionContext(ActionContext actionContext) { - actionContext.setParameters(new HashMap(request.getParameterMap())); - - initMockPortletContext(actionContext); + protected void initActionContext(ActionContext actionContext) { + actionContext.setParameters(new HashMap(request.getParameterMap())); + initSession(actionContext); + initPortletContext(actionContext); applyAdditionalParams(actionContext); - // set the action context to the one used by the proxy ActionContext.setContext(actionContext); } - private void initMockPortletContext(ActionContext actionContext) { + protected void initSession(ActionContext actionContext) { + Map session = actionContext.getSession(); + if (session == null) { + actionContext.setSession(new HashMap()); + } + } + + protected void initPortletContext(ActionContext actionContext) { try { ClassLoaderUtil.loadClass("javax.portlet.PortletContext", getClass()); Class mockClazz = ClassLoaderUtil.loadClass("org.springframework.mock.web.portlet.MockPortletContext", getClass());