You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@struts.apache.org by Maurizio Cucchiara <mc...@apache.org> on 2012/04/11 09:28:12 UTC
Re: svn commit: r1311951 - /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
Hi Lukasz,
+ actionContext.setSession(new HashMap<String, Object>());
what about setting session at a lower level (I didn't test though):
request.setSession(new MockHttpSession(servletContext));
On 10 April 2012 21:33, <lu...@apache.org> wrote:
> Author: lukaszlenart
> Date: Tue Apr 10 19:33:51 2012
> New Revision: 1311951
>
> URL: http://svn.apache.org/viewvc?rev=1311951&view=rev
> Log:
> WW-3442 adds Session initialisation method to solve problem with missing
> session and allow to initialise session on its own in test cases
>
> Modified:
>
> struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
>
> 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=1311951&r1=1311950&r2=1311951&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
> Tue Apr 10 19:33:51 2012
> @@ -149,17 +149,23 @@ public abstract class StrutsTestCase ext
> return proxy;
> }
>
> - private void initActionContext(ActionContext actionContext) {
> - actionContext.setParameters(new
> HashMap(request.getParameterMap()));
> -
> - initMockPortletContext(actionContext);
> + protected void initActionContext(ActionContext actionContext) {
> + actionContext.setParameters(new HashMap<String,
> Object>(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<String, Object> session = actionContext.getSession();
> + if (session == null) {
> + }
> + }
> +
> + protected void initPortletContext(ActionContext actionContext) {
> try {
> ClassLoaderUtil.loadClass("javax.portlet.PortletContext",
> getClass());
> Class mockClazz =
> ClassLoaderUtil.loadClass("org.springframework.mock.web.portlet.MockPortletContext",
> getClass());
>
>
>
Re: svn commit: r1311951 - /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
Posted by Łukasz Lenart <lu...@googlemail.com>.
2012/4/11 Maurizio Cucchiara <mc...@apache.org>:
> Since Struts Junit Test uses MockHttp stuff, I thought that it would
> be a good thing leave that layer consistent.
Right, changed, please check :-)
Regards
--
Łukasz http://www.lenart.org.pl/
mobile +48 606 323 122, office +27 11 0838747
Warszawa JUG conference - Confitura http://confitura.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: svn commit: r1311951 - /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
Posted by Maurizio Cucchiara <mc...@apache.org>.
Since Struts Junit Test uses MockHttp stuff, I thought that it would
be a good thing leave that layer consistent.
Twitter :http://www.twitter.com/m_cucchiara
G+ :https://plus.google.com/107903711540963855921
Linkedin :http://www.linkedin.com/in/mauriziocucchiara
Maurizio Cucchiara
On 11 April 2012 18:58, Lukasz Lenart <lu...@apache.org> wrote:
> 2012/4/11 Maurizio Cucchiara <mc...@apache.org>:
>> Hi Lukasz,
>>
>>> + actionContext.setSession(new HashMap<String, Object>());
>>
>>
>> what about setting session at a lower level (I didn't test though):
>>
>> request.setSession(new MockHttpSession(servletContext));
>
> but basically, the S2 actions shouldn't depend on the raw servlet
> objects, but maybe it'd be good to test interceptors
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
> For additional commands, e-mail: dev-help@struts.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org
Re: svn commit: r1311951 - /struts/struts2/trunk/plugins/junit/src/main/java/org/apache/struts2/StrutsTestCase.java
Posted by Lukasz Lenart <lu...@apache.org>.
2012/4/11 Maurizio Cucchiara <mc...@apache.org>:
> Hi Lukasz,
>
>> + actionContext.setSession(new HashMap<String, Object>());
>
>
> what about setting session at a lower level (I didn't test though):
>
> request.setSession(new MockHttpSession(servletContext));
but basically, the S2 actions shouldn't depend on the raw servlet
objects, but maybe it'd be good to test interceptors
Regards
--
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@struts.apache.org
For additional commands, e-mail: dev-help@struts.apache.org