You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Krishnaraj A <ak...@gmail.com> on 2014/06/12 17:11:44 UTC

Issues in Struts2 unit testing

Hi Team,

Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit plugin
<http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
actions which is working fine. But I have issue when I am testing the
action which has interceptor.

<action name="MainAdminPage" class="com.action.MainAdminAction">
            <interceptor-ref name="newStack" />
            <result>/MainAdmin.jsp</result>
            <result name="Login_page">/Login.jsp</result>
</action>

When I start testing the control goes to interceptor and check all the
validation.
when it invoke "return invocation.invoke();". it throws error.
 java.lang.IllegalStateException: Action has already executed

I am not able to get the solution for the above problem. Can any one help
me in this problem to find the solution. Thanks in advance.

Thanks,
Krishna raj

Re: Issues in Struts2 unit testing

Posted by Paul Benedict <pb...@apache.org>.
I think you need to minimize your test case and start from something
simpler to diagnose the problem. First try using the default stack alone.
Let us know how that turns out.


Cheers,
Paul


On Fri, Jun 13, 2014 at 8:25 AM, Krishnaraj A <
akrajmscjavaquestion@gmail.com> wrote:

> Hi Team,
>
>
> Is any help for the above issue
>
> Thanks
> Krishna raj
>
>
> On Thu, Jun 12, 2014 at 9:05 PM, Krishnaraj A <
> akrajmscjavaquestion@gmail.com> wrote:
>
> > Hi Dave,
> >
> > I added my struts code.
> >
> > Junit Code:
> >
> > public class AdminValidation extends StrutsTestCase  {
> >
> >     @Test
> >     public void testUserNameErrorMessage() throws Exception {
> >
> >         HttpSession session = request.getSession();
> >         UserVO uservo1 =new UserVO();
> >         uservo1.setUserMailId("akrajmscjavaquestion@gmail.com");
> >         uservo1.setReturnedStatus("admin");
> >         uservo1.setAccessLevel("1293");
> >         uservo1.setIntranetId("Krishnaraj");
> >         uservo1.setSuperAdmin(true);
> >         uservo1.setShowRegContact(false);
> >         session.setAttribute("user", uservo1);
> >         ActionProxy proxy = getActionProxy("/MainAdminPage.action");
> >         ActionContext context
> > =proxy.getInvocation().getInvocationContext();
> >         Map<String,Object> session = new HashMap<String,Object>();
> >         session.put("user", uservo1);
> >         context.setSession(session);
> >          String result = proxy.execute();
> >          assertEquals("Result returned form executing the action was not
> > success but it should have been.", "success", result);
> >     }
> > }
> >
> > Struts.xml code:
> >
> > <interceptors>
> > <interceptor name="printMsgInterceptor"
> > class="com.interceptor.UserValidation"></interceptor>
> > <interceptor name="sessionClearInterceptor"
> > class="com.interceptor.SessionClearInterceptor"></interceptor>
> > <interceptor-stack name="newStack">
> > <interceptor-ref name="printMsgInterceptor" />
> > <interceptor-ref name="sessionClearInterceptor" />
> > <interceptor-ref name="defaultStack" />
> > </interceptor-stack>
> > </interceptors>
> >
> >
> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> >     <interceptor-ref name="newStack" />
> >     <result>/MainAdmin.jsp</result>
> >     <result name="Login_page">/Login.jsp</result>
> > </action>
> >
> > UserValidation.java code:
> >
> > public class UserValidation extends AbstractInterceptor implements
> > StrutsStatics {
> >
> >
> >     private static final long serialVersionUID = 1L;
> >
> >     public void init() {
> >
> >     }
> >
> >     public void destroy() {
> >     }
> >
> >     public String intercept(ActionInvocation invocation) throws
> Exception {
> >
> >         final ActionContext context = invocation.getInvocationContext();
> >         String str =invocation.getAction().getClass().getSimpleName();
> >         Map<String,Object> session =context.getSession() ;
> >         HttpServletRequest request=(HttpServletRequest)
> > context.get(HTTP_REQUEST);
> >         HttpServletResponse response=(HttpServletResponse)
> > context.get(HTTP_RESPONSE);
> >         String str1 =request.getRequestedSessionId();
> >
> >         request.setCharacterEncoding("UTF-8");
> >         final UserVO uservo =(UserVO) session.get("user");
> >             String userMailId;
> >             if(uservo !=null){
> >             String mailID=uservo.getUserMailId();
> >             if(mailID != null){
> >                 System.out.println("Success");
> >             }
> >         }
> >
> >         else {
> >             return "login";
> >
> >         }
> >         response.setHeader("Pragma","no-cache");
> >         response.setHeader("Cache-Control","no-store");
> >         response.setHeader("Expires","0");
> >         response.setDateHeader("Expires",-1);
> >         response.setCharacterEncoding("UTF-8");
> >         return invocation.invoke();
> >
> >     }
> > }
> >
> > I debug the application by placing the break point. When the control go
> to
> > " return invocation.invoke();" it throws error.
> >
> >  java.lang.
> > IllegalStateException: Action has already executed
> >
> >
> > Thanks,
> > Krishnaraj
> >
> >
> >
> >
> > On Thu, Jun 12, 2014 at 8:45 PM, Dave Newton <da...@gmail.com>
> > wrote:
> >
> >> Without knowing what's in your interceptor stack it's impossible to
> help.
> >>
> >> Dave
> >>
> >>
> >> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
> >> akrajmscjavaquestion@gmail.com> wrote:
> >>
> >> > Hi Team,
> >> >
> >> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
> >> plugin
> >> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
> >> > actions which is working fine. But I have issue when I am testing the
> >> > action which has interceptor.
> >> >
> >> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> >> >             <interceptor-ref name="newStack" />
> >> >             <result>/MainAdmin.jsp</result>
> >> >             <result name="Login_page">/Login.jsp</result>
> >> > </action>
> >> >
> >> > When I start testing the control goes to interceptor and check all the
> >> > validation.
> >> > when it invoke "return invocation.invoke();". it throws error.
> >> >  java.lang.IllegalStateException: Action has already executed
> >> >
> >> > I am not able to get the solution for the above problem. Can any one
> >> help
> >> > me in this problem to find the solution. Thanks in advance.
> >> >
> >> > Thanks,
> >> > Krishna raj
> >> >
> >>
> >>
> >>
> >> --
> >> e: davelnewton@gmail.com
> >> m: 908-380-8699
> >> s: davelnewton_skype
> >> t: @dave_newton <https://twitter.com/dave_newton>
> >> b: Bucky Bits <http://buckybits.blogspot.com/>
> >> g: davelnewton <https://github.com/davelnewton>
> >> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> >>
> >
> >
>

RE: Issues in Struts2 unit testing

Posted by Martin Gainty <mg...@hotmail.com>.


> Date: Fri, 13 Jun 2014 19:01:31 +0530
> Subject: Re: Issues in Struts2 unit testing
> From: akrajmscjavaquestion@gmail.com
> To: user@struts.apache.org
> 
> Hi Paul,
> 
> I placed the break points in struts code. But the control is not redirected
> to struts code. its throws error in interceptor code.\

MG>as dave mentioned you really need to show us what the interceptor stack looks like before we can offer a solution
MG>as paul mentioned struts is telling you the truth that the action is already executed so before the invoke put a sanity check
MG>if (proxy.getInvocation().isExecuted() )
MG>{ String result = proxy.execute();
MG>}
MG>http://struts.apache.org/release/2.0.x/struts2-core/apidocs/com/opensymphony/xwork2/ActionInvocation.html#isExecuted%28%29

> 
> Thanks
> Krishnaraj
> 
> 
> On Fri, Jun 13, 2014 at 6:58 PM, Paul Benedict <pb...@apache.org> wrote:
> 
> > Go set a breakpoint in Struts where the ISE is being thrown and see what
> > condition is being tested. If possible, take some time to determine when
> > that condition is being set before your invocation.
> >
> >
> > Cheers,
> > Paul
> >
> >
> > On Fri, Jun 13, 2014 at 8:25 AM, Krishnaraj A <
> > akrajmscjavaquestion@gmail.com> wrote:
> >
> > > Hi Team,
> > >
> > >
> > > Is any help for the above issue
> > >
> > > Thanks
> > > Krishna raj
> > >
> > >
> > > On Thu, Jun 12, 2014 at 9:05 PM, Krishnaraj A <
> > > akrajmscjavaquestion@gmail.com> wrote:
> > >
> > > > Hi Dave,
> > > >
> > > > I added my struts code.
> > > >
> > > > Junit Code:
> > > >
> > > > public class AdminValidation extends StrutsTestCase  {
> > > >
> > > >     @Test
> > > >     public void testUserNameErrorMessage() throws Exception {
> > > >
> > > >         HttpSession session = request.getSession();
> > > >         UserVO uservo1 =new UserVO();
> > > >         uservo1.setUserMailId("akrajmscjavaquestion@gmail.com");
> > > >         uservo1.setReturnedStatus("admin");
> > > >         uservo1.setAccessLevel("1293");
> > > >         uservo1.setIntranetId("Krishnaraj");
> > > >         uservo1.setSuperAdmin(true);
> > > >         uservo1.setShowRegContact(false);
> > > >         session.setAttribute("user", uservo1);
> > > >         ActionProxy proxy = getActionProxy("/MainAdminPage.action");
> > > >         ActionContext context
> > > > =proxy.getInvocation().getInvocationContext();
> > > >         Map<String,Object> session = new HashMap<String,Object>();
> > > >         session.put("user", uservo1);
> > > >         context.setSession(session);
> > > >          String result = proxy.execute();
> > > >          assertEquals("Result returned form executing the action was
> > not
> > > > success but it should have been.", "success", result);
> > > >     }
> > > > }
> > > >
> > > > Struts.xml code:
> > > >
> > > > <interceptors>
> > > > <interceptor name="printMsgInterceptor"
> > > > class="com.interceptor.UserValidation"></interceptor>
> > > > <interceptor name="sessionClearInterceptor"
> > > > class="com.interceptor.SessionClearInterceptor"></interceptor>
> > > > <interceptor-stack name="newStack">
> > > > <interceptor-ref name="printMsgInterceptor" />
> > > > <interceptor-ref name="sessionClearInterceptor" />
> > > > <interceptor-ref name="defaultStack" />
> > > > </interceptor-stack>
> > > > </interceptors>
> > > >
> > > >
> > > > <action name="MainAdminPage" class="com.action.MainAdminAction">
> > > >     <interceptor-ref name="newStack" />
> > > >     <result>/MainAdmin.jsp</result>
> > > >     <result name="Login_page">/Login.jsp</result>
> > > > </action>
> > > >
> > > > UserValidation.java code:
> > > >
> > > > public class UserValidation extends AbstractInterceptor implements
> > > > StrutsStatics {
> > > >
> > > >
> > > >     private static final long serialVersionUID = 1L;
> > > >
> > > >     public void init() {
> > > >
> > > >     }
> > > >
> > > >     public void destroy() {
> > > >     }
> > > >
> > > >     public String intercept(ActionInvocation invocation) throws
> > > Exception {
> > > >
> > > >         final ActionContext context =
> > invocation.getInvocationContext();
> > > >         String str =invocation.getAction().getClass().getSimpleName();
> > > >         Map<String,Object> session =context.getSession() ;
> > > >         HttpServletRequest request=(HttpServletRequest)
> > > > context.get(HTTP_REQUEST);
> > > >         HttpServletResponse response=(HttpServletResponse)
> > > > context.get(HTTP_RESPONSE);
> > > >         String str1 =request.getRequestedSessionId();
> > > >
> > > >         request.setCharacterEncoding("UTF-8");
> > > >         final UserVO uservo =(UserVO) session.get("user");
> > > >             String userMailId;
> > > >             if(uservo !=null){
> > > >             String mailID=uservo.getUserMailId();
> > > >             if(mailID != null){
> > > >                 System.out.println("Success");
> > > >             }
> > > >         }
> > > >
> > > >         else {
> > > >             return "login";
> > > >
> > > >         }
> > > >         response.setHeader("Pragma","no-cache");
> > > >         response.setHeader("Cache-Control","no-store");
> > > >         response.setHeader("Expires","0");
> > > >         response.setDateHeader("Expires",-1);
> > > >         response.setCharacterEncoding("UTF-8");
> > > >         return invocation.invoke();
> > > >
> > > >     }
> > > > }
> > > >
> > > > I debug the application by placing the break point. When the control go
> > > to
> > > > " return invocation.invoke();" it throws error.
> > > >
> > > >  java.lang.
> > > > IllegalStateException: Action has already executed
> > > >
> > > >
> > > > Thanks,
> > > > Krishnaraj
> > > >
> > > >
> > > >
> > > >
> > > > On Thu, Jun 12, 2014 at 8:45 PM, Dave Newton <da...@gmail.com>
> > > > wrote:
> > > >
> > > >> Without knowing what's in your interceptor stack it's impossible to
> > > help.
> > > >>
> > > >> Dave
> > > >>
> > > >>
> > > >> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
> > > >> akrajmscjavaquestion@gmail.com> wrote:
> > > >>
> > > >> > Hi Team,
> > > >> >
> > > >> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
> > > >> plugin
> > > >> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The
> > normal
> > > >> > actions which is working fine. But I have issue when I am testing
> > the
> > > >> > action which has interceptor.
> > > >> >
> > > >> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> > > >> >             <interceptor-ref name="newStack" />
> > > >> >             <result>/MainAdmin.jsp</result>
> > > >> >             <result name="Login_page">/Login.jsp</result>
> > > >> > </action>
> > > >> >
> > > >> > When I start testing the control goes to interceptor and check all
> > the
> > > >> > validation.
> > > >> > when it invoke "return invocation.invoke();". it throws error.
> > > >> >  java.lang.IllegalStateException: Action has already executed
> > > >> >
> > > >> > I am not able to get the solution for the above problem. Can any one
> > > >> help
> > > >> > me in this problem to find the solution. Thanks in advance.
> > > >> >
> > > >> > Thanks,
> > > >> > Krishna raj
> > > >> >
> > > >>
> > > >>
> > > >>
> > > >> --
> > > >> e: davelnewton@gmail.com
> > > >> m: 908-380-8699
> > > >> s: davelnewton_skype
> > > >> t: @dave_newton <https://twitter.com/dave_newton>
> > > >> b: Bucky Bits <http://buckybits.blogspot.com/>
> > > >> g: davelnewton <https://github.com/davelnewton>
> > > >> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> > > >>
> > > >
> > > >
> > >
> >
 		 	   		  

Re: Issues in Struts2 unit testing

Posted by Krishnaraj A <ak...@gmail.com>.
Hi Paul,

I placed the break points in struts code. But the control is not redirected
to struts code. its throws error in interceptor code.\


Thanks
Krishnaraj


On Fri, Jun 13, 2014 at 6:58 PM, Paul Benedict <pb...@apache.org> wrote:

> Go set a breakpoint in Struts where the ISE is being thrown and see what
> condition is being tested. If possible, take some time to determine when
> that condition is being set before your invocation.
>
>
> Cheers,
> Paul
>
>
> On Fri, Jun 13, 2014 at 8:25 AM, Krishnaraj A <
> akrajmscjavaquestion@gmail.com> wrote:
>
> > Hi Team,
> >
> >
> > Is any help for the above issue
> >
> > Thanks
> > Krishna raj
> >
> >
> > On Thu, Jun 12, 2014 at 9:05 PM, Krishnaraj A <
> > akrajmscjavaquestion@gmail.com> wrote:
> >
> > > Hi Dave,
> > >
> > > I added my struts code.
> > >
> > > Junit Code:
> > >
> > > public class AdminValidation extends StrutsTestCase  {
> > >
> > >     @Test
> > >     public void testUserNameErrorMessage() throws Exception {
> > >
> > >         HttpSession session = request.getSession();
> > >         UserVO uservo1 =new UserVO();
> > >         uservo1.setUserMailId("akrajmscjavaquestion@gmail.com");
> > >         uservo1.setReturnedStatus("admin");
> > >         uservo1.setAccessLevel("1293");
> > >         uservo1.setIntranetId("Krishnaraj");
> > >         uservo1.setSuperAdmin(true);
> > >         uservo1.setShowRegContact(false);
> > >         session.setAttribute("user", uservo1);
> > >         ActionProxy proxy = getActionProxy("/MainAdminPage.action");
> > >         ActionContext context
> > > =proxy.getInvocation().getInvocationContext();
> > >         Map<String,Object> session = new HashMap<String,Object>();
> > >         session.put("user", uservo1);
> > >         context.setSession(session);
> > >          String result = proxy.execute();
> > >          assertEquals("Result returned form executing the action was
> not
> > > success but it should have been.", "success", result);
> > >     }
> > > }
> > >
> > > Struts.xml code:
> > >
> > > <interceptors>
> > > <interceptor name="printMsgInterceptor"
> > > class="com.interceptor.UserValidation"></interceptor>
> > > <interceptor name="sessionClearInterceptor"
> > > class="com.interceptor.SessionClearInterceptor"></interceptor>
> > > <interceptor-stack name="newStack">
> > > <interceptor-ref name="printMsgInterceptor" />
> > > <interceptor-ref name="sessionClearInterceptor" />
> > > <interceptor-ref name="defaultStack" />
> > > </interceptor-stack>
> > > </interceptors>
> > >
> > >
> > > <action name="MainAdminPage" class="com.action.MainAdminAction">
> > >     <interceptor-ref name="newStack" />
> > >     <result>/MainAdmin.jsp</result>
> > >     <result name="Login_page">/Login.jsp</result>
> > > </action>
> > >
> > > UserValidation.java code:
> > >
> > > public class UserValidation extends AbstractInterceptor implements
> > > StrutsStatics {
> > >
> > >
> > >     private static final long serialVersionUID = 1L;
> > >
> > >     public void init() {
> > >
> > >     }
> > >
> > >     public void destroy() {
> > >     }
> > >
> > >     public String intercept(ActionInvocation invocation) throws
> > Exception {
> > >
> > >         final ActionContext context =
> invocation.getInvocationContext();
> > >         String str =invocation.getAction().getClass().getSimpleName();
> > >         Map<String,Object> session =context.getSession() ;
> > >         HttpServletRequest request=(HttpServletRequest)
> > > context.get(HTTP_REQUEST);
> > >         HttpServletResponse response=(HttpServletResponse)
> > > context.get(HTTP_RESPONSE);
> > >         String str1 =request.getRequestedSessionId();
> > >
> > >         request.setCharacterEncoding("UTF-8");
> > >         final UserVO uservo =(UserVO) session.get("user");
> > >             String userMailId;
> > >             if(uservo !=null){
> > >             String mailID=uservo.getUserMailId();
> > >             if(mailID != null){
> > >                 System.out.println("Success");
> > >             }
> > >         }
> > >
> > >         else {
> > >             return "login";
> > >
> > >         }
> > >         response.setHeader("Pragma","no-cache");
> > >         response.setHeader("Cache-Control","no-store");
> > >         response.setHeader("Expires","0");
> > >         response.setDateHeader("Expires",-1);
> > >         response.setCharacterEncoding("UTF-8");
> > >         return invocation.invoke();
> > >
> > >     }
> > > }
> > >
> > > I debug the application by placing the break point. When the control go
> > to
> > > " return invocation.invoke();" it throws error.
> > >
> > >  java.lang.
> > > IllegalStateException: Action has already executed
> > >
> > >
> > > Thanks,
> > > Krishnaraj
> > >
> > >
> > >
> > >
> > > On Thu, Jun 12, 2014 at 8:45 PM, Dave Newton <da...@gmail.com>
> > > wrote:
> > >
> > >> Without knowing what's in your interceptor stack it's impossible to
> > help.
> > >>
> > >> Dave
> > >>
> > >>
> > >> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
> > >> akrajmscjavaquestion@gmail.com> wrote:
> > >>
> > >> > Hi Team,
> > >> >
> > >> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
> > >> plugin
> > >> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The
> normal
> > >> > actions which is working fine. But I have issue when I am testing
> the
> > >> > action which has interceptor.
> > >> >
> > >> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> > >> >             <interceptor-ref name="newStack" />
> > >> >             <result>/MainAdmin.jsp</result>
> > >> >             <result name="Login_page">/Login.jsp</result>
> > >> > </action>
> > >> >
> > >> > When I start testing the control goes to interceptor and check all
> the
> > >> > validation.
> > >> > when it invoke "return invocation.invoke();". it throws error.
> > >> >  java.lang.IllegalStateException: Action has already executed
> > >> >
> > >> > I am not able to get the solution for the above problem. Can any one
> > >> help
> > >> > me in this problem to find the solution. Thanks in advance.
> > >> >
> > >> > Thanks,
> > >> > Krishna raj
> > >> >
> > >>
> > >>
> > >>
> > >> --
> > >> e: davelnewton@gmail.com
> > >> m: 908-380-8699
> > >> s: davelnewton_skype
> > >> t: @dave_newton <https://twitter.com/dave_newton>
> > >> b: Bucky Bits <http://buckybits.blogspot.com/>
> > >> g: davelnewton <https://github.com/davelnewton>
> > >> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> > >>
> > >
> > >
> >
>

Re: Issues in Struts2 unit testing

Posted by Paul Benedict <pb...@apache.org>.
Go set a breakpoint in Struts where the ISE is being thrown and see what
condition is being tested. If possible, take some time to determine when
that condition is being set before your invocation.


Cheers,
Paul


On Fri, Jun 13, 2014 at 8:25 AM, Krishnaraj A <
akrajmscjavaquestion@gmail.com> wrote:

> Hi Team,
>
>
> Is any help for the above issue
>
> Thanks
> Krishna raj
>
>
> On Thu, Jun 12, 2014 at 9:05 PM, Krishnaraj A <
> akrajmscjavaquestion@gmail.com> wrote:
>
> > Hi Dave,
> >
> > I added my struts code.
> >
> > Junit Code:
> >
> > public class AdminValidation extends StrutsTestCase  {
> >
> >     @Test
> >     public void testUserNameErrorMessage() throws Exception {
> >
> >         HttpSession session = request.getSession();
> >         UserVO uservo1 =new UserVO();
> >         uservo1.setUserMailId("akrajmscjavaquestion@gmail.com");
> >         uservo1.setReturnedStatus("admin");
> >         uservo1.setAccessLevel("1293");
> >         uservo1.setIntranetId("Krishnaraj");
> >         uservo1.setSuperAdmin(true);
> >         uservo1.setShowRegContact(false);
> >         session.setAttribute("user", uservo1);
> >         ActionProxy proxy = getActionProxy("/MainAdminPage.action");
> >         ActionContext context
> > =proxy.getInvocation().getInvocationContext();
> >         Map<String,Object> session = new HashMap<String,Object>();
> >         session.put("user", uservo1);
> >         context.setSession(session);
> >          String result = proxy.execute();
> >          assertEquals("Result returned form executing the action was not
> > success but it should have been.", "success", result);
> >     }
> > }
> >
> > Struts.xml code:
> >
> > <interceptors>
> > <interceptor name="printMsgInterceptor"
> > class="com.interceptor.UserValidation"></interceptor>
> > <interceptor name="sessionClearInterceptor"
> > class="com.interceptor.SessionClearInterceptor"></interceptor>
> > <interceptor-stack name="newStack">
> > <interceptor-ref name="printMsgInterceptor" />
> > <interceptor-ref name="sessionClearInterceptor" />
> > <interceptor-ref name="defaultStack" />
> > </interceptor-stack>
> > </interceptors>
> >
> >
> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> >     <interceptor-ref name="newStack" />
> >     <result>/MainAdmin.jsp</result>
> >     <result name="Login_page">/Login.jsp</result>
> > </action>
> >
> > UserValidation.java code:
> >
> > public class UserValidation extends AbstractInterceptor implements
> > StrutsStatics {
> >
> >
> >     private static final long serialVersionUID = 1L;
> >
> >     public void init() {
> >
> >     }
> >
> >     public void destroy() {
> >     }
> >
> >     public String intercept(ActionInvocation invocation) throws
> Exception {
> >
> >         final ActionContext context = invocation.getInvocationContext();
> >         String str =invocation.getAction().getClass().getSimpleName();
> >         Map<String,Object> session =context.getSession() ;
> >         HttpServletRequest request=(HttpServletRequest)
> > context.get(HTTP_REQUEST);
> >         HttpServletResponse response=(HttpServletResponse)
> > context.get(HTTP_RESPONSE);
> >         String str1 =request.getRequestedSessionId();
> >
> >         request.setCharacterEncoding("UTF-8");
> >         final UserVO uservo =(UserVO) session.get("user");
> >             String userMailId;
> >             if(uservo !=null){
> >             String mailID=uservo.getUserMailId();
> >             if(mailID != null){
> >                 System.out.println("Success");
> >             }
> >         }
> >
> >         else {
> >             return "login";
> >
> >         }
> >         response.setHeader("Pragma","no-cache");
> >         response.setHeader("Cache-Control","no-store");
> >         response.setHeader("Expires","0");
> >         response.setDateHeader("Expires",-1);
> >         response.setCharacterEncoding("UTF-8");
> >         return invocation.invoke();
> >
> >     }
> > }
> >
> > I debug the application by placing the break point. When the control go
> to
> > " return invocation.invoke();" it throws error.
> >
> >  java.lang.
> > IllegalStateException: Action has already executed
> >
> >
> > Thanks,
> > Krishnaraj
> >
> >
> >
> >
> > On Thu, Jun 12, 2014 at 8:45 PM, Dave Newton <da...@gmail.com>
> > wrote:
> >
> >> Without knowing what's in your interceptor stack it's impossible to
> help.
> >>
> >> Dave
> >>
> >>
> >> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
> >> akrajmscjavaquestion@gmail.com> wrote:
> >>
> >> > Hi Team,
> >> >
> >> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
> >> plugin
> >> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
> >> > actions which is working fine. But I have issue when I am testing the
> >> > action which has interceptor.
> >> >
> >> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> >> >             <interceptor-ref name="newStack" />
> >> >             <result>/MainAdmin.jsp</result>
> >> >             <result name="Login_page">/Login.jsp</result>
> >> > </action>
> >> >
> >> > When I start testing the control goes to interceptor and check all the
> >> > validation.
> >> > when it invoke "return invocation.invoke();". it throws error.
> >> >  java.lang.IllegalStateException: Action has already executed
> >> >
> >> > I am not able to get the solution for the above problem. Can any one
> >> help
> >> > me in this problem to find the solution. Thanks in advance.
> >> >
> >> > Thanks,
> >> > Krishna raj
> >> >
> >>
> >>
> >>
> >> --
> >> e: davelnewton@gmail.com
> >> m: 908-380-8699
> >> s: davelnewton_skype
> >> t: @dave_newton <https://twitter.com/dave_newton>
> >> b: Bucky Bits <http://buckybits.blogspot.com/>
> >> g: davelnewton <https://github.com/davelnewton>
> >> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> >>
> >
> >
>

Re: Issues in Struts2 unit testing

Posted by Krishnaraj A <ak...@gmail.com>.
Hi Team,


Is any help for the above issue

Thanks
Krishna raj


On Thu, Jun 12, 2014 at 9:05 PM, Krishnaraj A <
akrajmscjavaquestion@gmail.com> wrote:

> Hi Dave,
>
> I added my struts code.
>
> Junit Code:
>
> public class AdminValidation extends StrutsTestCase  {
>
>     @Test
>     public void testUserNameErrorMessage() throws Exception {
>
>         HttpSession session = request.getSession();
>         UserVO uservo1 =new UserVO();
>         uservo1.setUserMailId("akrajmscjavaquestion@gmail.com");
>         uservo1.setReturnedStatus("admin");
>         uservo1.setAccessLevel("1293");
>         uservo1.setIntranetId("Krishnaraj");
>         uservo1.setSuperAdmin(true);
>         uservo1.setShowRegContact(false);
>         session.setAttribute("user", uservo1);
>         ActionProxy proxy = getActionProxy("/MainAdminPage.action");
>         ActionContext context
> =proxy.getInvocation().getInvocationContext();
>         Map<String,Object> session = new HashMap<String,Object>();
>         session.put("user", uservo1);
>         context.setSession(session);
>          String result = proxy.execute();
>          assertEquals("Result returned form executing the action was not
> success but it should have been.", "success", result);
>     }
> }
>
> Struts.xml code:
>
> <interceptors>
> <interceptor name="printMsgInterceptor"
> class="com.interceptor.UserValidation"></interceptor>
> <interceptor name="sessionClearInterceptor"
> class="com.interceptor.SessionClearInterceptor"></interceptor>
> <interceptor-stack name="newStack">
> <interceptor-ref name="printMsgInterceptor" />
> <interceptor-ref name="sessionClearInterceptor" />
> <interceptor-ref name="defaultStack" />
> </interceptor-stack>
> </interceptors>
>
>
> <action name="MainAdminPage" class="com.action.MainAdminAction">
>     <interceptor-ref name="newStack" />
>     <result>/MainAdmin.jsp</result>
>     <result name="Login_page">/Login.jsp</result>
> </action>
>
> UserValidation.java code:
>
> public class UserValidation extends AbstractInterceptor implements
> StrutsStatics {
>
>
>     private static final long serialVersionUID = 1L;
>
>     public void init() {
>
>     }
>
>     public void destroy() {
>     }
>
>     public String intercept(ActionInvocation invocation) throws Exception {
>
>         final ActionContext context = invocation.getInvocationContext();
>         String str =invocation.getAction().getClass().getSimpleName();
>         Map<String,Object> session =context.getSession() ;
>         HttpServletRequest request=(HttpServletRequest)
> context.get(HTTP_REQUEST);
>         HttpServletResponse response=(HttpServletResponse)
> context.get(HTTP_RESPONSE);
>         String str1 =request.getRequestedSessionId();
>
>         request.setCharacterEncoding("UTF-8");
>         final UserVO uservo =(UserVO) session.get("user");
>             String userMailId;
>             if(uservo !=null){
>             String mailID=uservo.getUserMailId();
>             if(mailID != null){
>                 System.out.println("Success");
>             }
>         }
>
>         else {
>             return "login";
>
>         }
>         response.setHeader("Pragma","no-cache");
>         response.setHeader("Cache-Control","no-store");
>         response.setHeader("Expires","0");
>         response.setDateHeader("Expires",-1);
>         response.setCharacterEncoding("UTF-8");
>         return invocation.invoke();
>
>     }
> }
>
> I debug the application by placing the break point. When the control go to
> " return invocation.invoke();" it throws error.
>
>  java.lang.
> IllegalStateException: Action has already executed
>
>
> Thanks,
> Krishnaraj
>
>
>
>
> On Thu, Jun 12, 2014 at 8:45 PM, Dave Newton <da...@gmail.com>
> wrote:
>
>> Without knowing what's in your interceptor stack it's impossible to help.
>>
>> Dave
>>
>>
>> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
>> akrajmscjavaquestion@gmail.com> wrote:
>>
>> > Hi Team,
>> >
>> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
>> plugin
>> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
>> > actions which is working fine. But I have issue when I am testing the
>> > action which has interceptor.
>> >
>> > <action name="MainAdminPage" class="com.action.MainAdminAction">
>> >             <interceptor-ref name="newStack" />
>> >             <result>/MainAdmin.jsp</result>
>> >             <result name="Login_page">/Login.jsp</result>
>> > </action>
>> >
>> > When I start testing the control goes to interceptor and check all the
>> > validation.
>> > when it invoke "return invocation.invoke();". it throws error.
>> >  java.lang.IllegalStateException: Action has already executed
>> >
>> > I am not able to get the solution for the above problem. Can any one
>> help
>> > me in this problem to find the solution. Thanks in advance.
>> >
>> > Thanks,
>> > Krishna raj
>> >
>>
>>
>>
>> --
>> e: davelnewton@gmail.com
>> m: 908-380-8699
>> s: davelnewton_skype
>> t: @dave_newton <https://twitter.com/dave_newton>
>> b: Bucky Bits <http://buckybits.blogspot.com/>
>> g: davelnewton <https://github.com/davelnewton>
>> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>>
>
>

Re: Issues in Struts2 unit testing

Posted by Krishnaraj A <ak...@gmail.com>.
Hi Dave,

I added my struts code.

Junit Code:

public class AdminValidation extends StrutsTestCase  {

    @Test
    public void testUserNameErrorMessage() throws Exception {

        HttpSession session = request.getSession();
        UserVO uservo1 =new UserVO();
        uservo1.setUserMailId("akrajmscjavaquestion@gmail.com");
        uservo1.setReturnedStatus("admin");
        uservo1.setAccessLevel("1293");
        uservo1.setIntranetId("Krishnaraj");
        uservo1.setSuperAdmin(true);
        uservo1.setShowRegContact(false);
        session.setAttribute("user", uservo1);
        ActionProxy proxy = getActionProxy("/MainAdminPage.action");
        ActionContext context =proxy.getInvocation().getInvocationContext();
        Map<String,Object> session = new HashMap<String,Object>();
        session.put("user", uservo1);
        context.setSession(session);
         String result = proxy.execute();
         assertEquals("Result returned form executing the action was not
success but it should have been.", "success", result);
    }
}

Struts.xml code:

<interceptors>
<interceptor name="printMsgInterceptor"
class="com.interceptor.UserValidation"></interceptor>
<interceptor name="sessionClearInterceptor"
class="com.interceptor.SessionClearInterceptor"></interceptor>
<interceptor-stack name="newStack">
<interceptor-ref name="printMsgInterceptor" />
<interceptor-ref name="sessionClearInterceptor" />
<interceptor-ref name="defaultStack" />
</interceptor-stack>
</interceptors>

<action name="MainAdminPage" class="com.action.MainAdminAction">
    <interceptor-ref name="newStack" />
    <result>/MainAdmin.jsp</result>
    <result name="Login_page">/Login.jsp</result>
</action>

UserValidation.java code:

public class UserValidation extends AbstractInterceptor implements
StrutsStatics {


    private static final long serialVersionUID = 1L;

    public void init() {

    }

    public void destroy() {
    }

    public String intercept(ActionInvocation invocation) throws Exception {

        final ActionContext context = invocation.getInvocationContext();
        String str =invocation.getAction().getClass().getSimpleName();
        Map<String,Object> session =context.getSession() ;
        HttpServletRequest request=(HttpServletRequest)
context.get(HTTP_REQUEST);
        HttpServletResponse response=(HttpServletResponse)
context.get(HTTP_RESPONSE);
        String str1 =request.getRequestedSessionId();

        request.setCharacterEncoding("UTF-8");
        final UserVO uservo =(UserVO) session.get("user");
            String userMailId;
            if(uservo !=null){
            String mailID=uservo.getUserMailId();
            if(mailID != null){
                System.out.println("Success");
            }
        }

        else {
            return "login";

        }
        response.setHeader("Pragma","no-cache");
        response.setHeader("Cache-Control","no-store");
        response.setHeader("Expires","0");
        response.setDateHeader("Expires",-1);
        response.setCharacterEncoding("UTF-8");
        return invocation.invoke();

    }
}

I debug the application by placing the break point. When the control go to
" return invocation.invoke();" it throws error.

 java.lang.
IllegalStateException: Action has already executed


Thanks,
Krishnaraj




On Thu, Jun 12, 2014 at 8:45 PM, Dave Newton <da...@gmail.com> wrote:

> Without knowing what's in your interceptor stack it's impossible to help.
>
> Dave
>
>
> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
> akrajmscjavaquestion@gmail.com> wrote:
>
> > Hi Team,
> >
> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
> plugin
> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
> > actions which is working fine. But I have issue when I am testing the
> > action which has interceptor.
> >
> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> >             <interceptor-ref name="newStack" />
> >             <result>/MainAdmin.jsp</result>
> >             <result name="Login_page">/Login.jsp</result>
> > </action>
> >
> > When I start testing the control goes to interceptor and check all the
> > validation.
> > when it invoke "return invocation.invoke();". it throws error.
> >  java.lang.IllegalStateException: Action has already executed
> >
> > I am not able to get the solution for the above problem. Can any one help
> > me in this problem to find the solution. Thanks in advance.
> >
> > Thanks,
> > Krishna raj
> >
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton <https://twitter.com/dave_newton>
> b: Bucky Bits <http://buckybits.blogspot.com/>
> g: davelnewton <https://github.com/davelnewton>
> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>

Re: Issues in Struts2 unit testing

Posted by Krishnaraj A <ak...@gmail.com>.
Hi Paul,

The control is not redirected to execute() method.


Thanks
Krishnaraj


On Thu, Jun 12, 2014 at 8:48 PM, Paul Benedict <pb...@apache.org> wrote:

> Put a breakpoint in your execute() and see if it's being called. The error
> message might be telling the truth: the action has already been executed.
>
>
> Cheers,
> Paul
>
>
> On Thu, Jun 12, 2014 at 10:15 AM, Dave Newton <da...@gmail.com>
> wrote:
>
> > Without knowing what's in your interceptor stack it's impossible to help.
> >
> > Dave
> >
> >
> > On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
> > akrajmscjavaquestion@gmail.com> wrote:
> >
> > > Hi Team,
> > >
> > > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
> > plugin
> > > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
> > > actions which is working fine. But I have issue when I am testing the
> > > action which has interceptor.
> > >
> > > <action name="MainAdminPage" class="com.action.MainAdminAction">
> > >             <interceptor-ref name="newStack" />
> > >             <result>/MainAdmin.jsp</result>
> > >             <result name="Login_page">/Login.jsp</result>
> > > </action>
> > >
> > > When I start testing the control goes to interceptor and check all the
> > > validation.
> > > when it invoke "return invocation.invoke();". it throws error.
> > >  java.lang.IllegalStateException: Action has already executed
> > >
> > > I am not able to get the solution for the above problem. Can any one
> help
> > > me in this problem to find the solution. Thanks in advance.
> > >
> > > Thanks,
> > > Krishna raj
> > >
> >
> >
> >
> > --
> > e: davelnewton@gmail.com
> > m: 908-380-8699
> > s: davelnewton_skype
> > t: @dave_newton <https://twitter.com/dave_newton>
> > b: Bucky Bits <http://buckybits.blogspot.com/>
> > g: davelnewton <https://github.com/davelnewton>
> > so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
> >
>

Re: Issues in Struts2 unit testing

Posted by Paul Benedict <pb...@apache.org>.
Put a breakpoint in your execute() and see if it's being called. The error
message might be telling the truth: the action has already been executed.


Cheers,
Paul


On Thu, Jun 12, 2014 at 10:15 AM, Dave Newton <da...@gmail.com> wrote:

> Without knowing what's in your interceptor stack it's impossible to help.
>
> Dave
>
>
> On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
> akrajmscjavaquestion@gmail.com> wrote:
>
> > Hi Team,
> >
> > Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit
> plugin
> > <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
> > actions which is working fine. But I have issue when I am testing the
> > action which has interceptor.
> >
> > <action name="MainAdminPage" class="com.action.MainAdminAction">
> >             <interceptor-ref name="newStack" />
> >             <result>/MainAdmin.jsp</result>
> >             <result name="Login_page">/Login.jsp</result>
> > </action>
> >
> > When I start testing the control goes to interceptor and check all the
> > validation.
> > when it invoke "return invocation.invoke();". it throws error.
> >  java.lang.IllegalStateException: Action has already executed
> >
> > I am not able to get the solution for the above problem. Can any one help
> > me in this problem to find the solution. Thanks in advance.
> >
> > Thanks,
> > Krishna raj
> >
>
>
>
> --
> e: davelnewton@gmail.com
> m: 908-380-8699
> s: davelnewton_skype
> t: @dave_newton <https://twitter.com/dave_newton>
> b: Bucky Bits <http://buckybits.blogspot.com/>
> g: davelnewton <https://github.com/davelnewton>
> so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>
>

Re: Issues in Struts2 unit testing

Posted by Dave Newton <da...@gmail.com>.
Without knowing what's in your interceptor stack it's impossible to help.

Dave


On Thu, Jun 12, 2014 at 11:11 AM, Krishnaraj A <
akrajmscjavaquestion@gmail.com> wrote:

> Hi Team,
>
> Iam new to using Struts2 unit testing. Iam using the Struts 2 JUnit plugin
> <http://struts.apache.org/2.3.1.2/docs/junit-plugin.html>. The normal
> actions which is working fine. But I have issue when I am testing the
> action which has interceptor.
>
> <action name="MainAdminPage" class="com.action.MainAdminAction">
>             <interceptor-ref name="newStack" />
>             <result>/MainAdmin.jsp</result>
>             <result name="Login_page">/Login.jsp</result>
> </action>
>
> When I start testing the control goes to interceptor and check all the
> validation.
> when it invoke "return invocation.invoke();". it throws error.
>  java.lang.IllegalStateException: Action has already executed
>
> I am not able to get the solution for the above problem. Can any one help
> me in this problem to find the solution. Thanks in advance.
>
> Thanks,
> Krishna raj
>



-- 
e: davelnewton@gmail.com
m: 908-380-8699
s: davelnewton_skype
t: @dave_newton <https://twitter.com/dave_newton>
b: Bucky Bits <http://buckybits.blogspot.com/>
g: davelnewton <https://github.com/davelnewton>
so: Dave Newton <http://stackoverflow.com/users/438992/dave-newton>