[EMAIL PROTECTED] wrote:
> 
> Hello.  I'm new to cactus and I think it's a wonderful tool ( much thanks ).
> After reading this thread, I wanted to ask a struts related question and
> pose a suggestion for 1.2 or 2.0.
> 
> Firstly,
> I've written some cactus tests that test out the perform method of the
> struts Action class,
> and the first thing I wanted to see was if I was going about it in the
> correct fashion.
> 
> Below is a code sampling of what I'm doing:
> 
> public void testPerform() throws Exception{
> 
>     config.setInitParameter( "application", "my.com.ApplicationResources" );
> //application initParam for ActionServlet
> 
>     actionServlet = new ActionServlet();  //instance variable declared
> elsewhere
>     actionServlet.init( config );
>     ActionMapping mapping = actionServlet.findMapping(
> "/somepath/somemapping" );
>     MyAction action = new MyAction();
>     action.setServlet( actionServlet );
>     // don't need ActionForm for this Action class, so use null
>     ActionForward forward = action.perform( mapping, null, request, response
> );
>     ....
> }
> 
> It works for me, but I was curious if there were better methods others were
> using?
> 

I've had to do something similar, and am doing the following in the
setUp method:

in pseudocode:
setup()
{
  if (first time)
  {
    check servlet context for servlet i want to use
    if not there then create and put in servlet context
  }
}

It means I can run test cases assuming that the actionservlet has
started up and is available for use.

Of course if your actionservlet doesn't start properly this method won't
work.
 Then all you need to do is write a testcase for each action that you
want to test.

In your example, you could at least move the creation of the
actionservlet into the setUp method.


I guess the real issue with testing struts dispatcher based work, is
that you have an extra level of redirection to go through. At the moment
the ServletRedirector is set up to make calls to Servlet classes. with a
dispatcher you have another level of indirection, with the ActionServlet
class acting like a "container extension" as far as the Action classes
are concerned. Perhaps it is possible to make some sort of "Cactus"
actionservlet to run testcases for Actions? perhaps some sort of
"ActionRedirector" servlet? This could work to provide "in struts
container" testing ?

Jari

--
Jari Worsley
Senior Programmer
Hyperlink Interactive Ltd

Reply via email to