Struts2.3.12 junit4 testcase request & session are null

ⅰ亾dé卋堺 提交于 2019-11-29 12:07:15

If you are using getActionProxy method to execute your actions then you need to set new session map into the invocation context.

ActionProxy actionProxy = getActionProxy("/action");
Map<String, Object> sessionMap = new HashMap<String, Object>();
actionProxy.getInvocation().getInvocationContext().setSession(sessionMap);
actionProxy.execute();

If you don't need reference to action proxy then you can use executeAction method. Note that executeAction will return actual output of the result, not the result returned from execute method.

loweryjk

In my case I needed to call super.setUp from my test.

To avoid request from being null:

request = new MockHttpServletRequest();

For session:

Map<String, Object> sessionMap = new HashMap<String, Object>();
actionProxy.getInvocation().getInvocationContext().setSession(sessionMap);
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!