You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Simon Chappell <si...@gmail.com> on 2005/02/08 23:56:29 UTC
Trying to test an Action using only JUnit
I'm trying to write a JUnit test for an Action and I'm having problems
with ClassCastExceptions on the findForward() method of ActionMapping.
I am not in a position to try any other packages or tools, so I have
to roll this one myself.
I have narrowed the problem down to getting the ClassCastException in
the following line of the action under test:
ActionForward forward = mapping.findForward("success");
A fairly straight-forward thing to do in an Action,so it must be in my
setting up of the ActionMapping. Here's the setup in my test:
// Now build an ForwardConfig
ForwardConfig config = new ForwardConfig("success", "/noOp.jsp", false);
config.freeze();
assertEquals("ForwardConfig[name=success,path=/noOp.jsp,redirect=false,contextRelative=false]",
config.toString());
The assertEquals passes, so I hope that my ForwardConfig was correct.
Here's my setup of the ActionMapping:
// Build an ActionMapping for our ForwardConfig
ActionMapping mapping = new ActionMapping();
mapping.addForwardConfig(config);
// Set remaining attributes
mapping.setAttribute("noOpForm");
mapping.setInput("/noOp.jsp");
mapping.setName("noOpForm");
mapping.setPath("/noOp");
mapping.setScope("request");
mapping.setType("com.landsend.ebs.jokertags.actions.NoOpAction");
mapping.freeze();
assertEquals("noOpForm", mapping.getAttribute());
assertEquals("/noOp.jsp", mapping.getInput());
assertEquals("noOpForm", mapping.getName());
assertEquals("/noOp", mapping.getPath());
assertEquals("request", mapping.getScope());
assertEquals("com.landsend.ebs.jokertags.actions.NoOpAction",
mapping.getType());
assertEquals("ActionConfig[path=/noOp,attribute=noOpForm,input=/noOp.jsp,name=noOpForm,scope=request,type=com.landsend.ebs.jokertags.actions.NoOpAction",
mapping.toString());
Again, all these asserts pass, so I hope that means that my
ActionMapping is right.
I call the action using the line:
ActionForward forward = action.execute(mapping, form, null, null);
I'm not using the HttpServletRequest or HttpServletResponse objects in
the action, so they're null for now.
What am I doing wrong?
Simon (the Lands' End guy now using GMail :-)
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: Trying to test an Action using only JUnit
Posted by Hubert Rabago <hr...@gmail.com>.
Have you tried using an ActionForward as opposed to a ForwardConfig?
On Tue, 8 Feb 2005 16:56:29 -0600, Simon Chappell
<si...@gmail.com> wrote:
> I'm trying to write a JUnit test for an Action and I'm having problems
> with ClassCastExceptions on the findForward() method of ActionMapping.
> I am not in a position to try any other packages or tools, so I have
> to roll this one myself.
>
> I have narrowed the problem down to getting the ClassCastException in
> the following line of the action under test:
>
> ActionForward forward = mapping.findForward("success");
>
> A fairly straight-forward thing to do in an Action,so it must be in my
> setting up of the ActionMapping. Here's the setup in my test:
>
> // Now build an ForwardConfig
> ForwardConfig config = new ForwardConfig("success", "/noOp.jsp", false);
> config.freeze();
> assertEquals("ForwardConfig[name=success,path=/noOp.jsp,redirect=false,contextRelative=false]",
> config.toString());
>
> The assertEquals passes, so I hope that my ForwardConfig was correct.
> Here's my setup of the ActionMapping:
>
> // Build an ActionMapping for our ForwardConfig
> ActionMapping mapping = new ActionMapping();
> mapping.addForwardConfig(config);
>
> // Set remaining attributes
> mapping.setAttribute("noOpForm");
> mapping.setInput("/noOp.jsp");
> mapping.setName("noOpForm");
> mapping.setPath("/noOp");
> mapping.setScope("request");
> mapping.setType("com.landsend.ebs.jokertags.actions.NoOpAction");
> mapping.freeze();
> assertEquals("noOpForm", mapping.getAttribute());
> assertEquals("/noOp.jsp", mapping.getInput());
> assertEquals("noOpForm", mapping.getName());
> assertEquals("/noOp", mapping.getPath());
> assertEquals("request", mapping.getScope());
> assertEquals("com.landsend.ebs.jokertags.actions.NoOpAction",
> mapping.getType());
> assertEquals("ActionConfig[path=/noOp,attribute=noOpForm,input=/noOp.jsp,name=noOpForm,scope=request,type=com.landsend.ebs.jokertags.actions.NoOpAction",
> mapping.toString());
>
> Again, all these asserts pass, so I hope that means that my
> ActionMapping is right.
>
> I call the action using the line:
>
> ActionForward forward = action.execute(mapping, form, null, null);
>
> I'm not using the HttpServletRequest or HttpServletResponse objects in
> the action, so they're null for now.
>
> What am I doing wrong?
>
> Simon (the Lands' End guy now using GMail :-)
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org