----- Original Message -----
From: "Jari Worsley" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, June 20, 2001 3:43 PM
Subject: Re: Auto population of initParameters based on servlet name [Ideas
for Cactus 1.2 and 2.0 roadmap] ?


> [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
>   }
> }
>

hum ... normally each test case will trigger the Servlet redirector which
will instantiate a new test class for each call, meaning that your "if(first
time)" will always be true. Thus, you should not need it ! ... :)

> 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

Actually, the servlet redirector is set up to make calls to any java class.

> 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 ?
>

Better yet is either to create a utility package that has a factory that
returns actionServlet classes and the like or to create mock objects of
them. That's something I'd like to put in the roadmap for 1.2 or after. I'll
prepare a clean roadmap and submit it to the list this week end.

> Jari
Thanks
Vincent

Reply via email to