Hi Perry,
Thanks a lot and sorry for taking so long to answer. I had a pile of email
to catch up ... :). I know that's no excuse so please accept my apologies.
See my answers below in the text.

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


> 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
> );
>     ....
> }
>

I have never done it yet myself (i.e. testing struts Actions) but it looks
very good to me.

>
> It works for me, but I was curious if there were better methods others
were
> using?
>
>
> Secondly,
> I don't know if cactus already does this, but to me the following would be
> very useful to keep from having to call config.initParameter() for each of
> the struts ActionServlet init parameters ( in the above example, I only
set
> one, since that's all I needed for the test, but there are many for the
> ActionServlet ).
>
> It would be nice if cactus parsed the web.xml file, and provided a way to
> associate a servlet with a <servlet> tag in the web.xml file (based on the
> <servlet-name></servlet-name> tag) for the purpose of setting up the
config
> to automatically provide the init parameters specified in the web.xml
file.
> I would think doing this in the config.setServletName method would be
> natural enough
>
> MyServlet servlet = new MyServlet();
> config.setServletName( "myserv" );  // this would cause cactus to create
the
> init parameters for that <servlet-name>
> servlet.init( config );
>
> This would be very beneficial, as I would not have to hardcode my
> initParameters in my test classes, or create a utility class to parse the
> web.xml file myself.  I could then change my web.xml file and see the
> changes immediately in my test cases without having to recompile them.
>
> Does such a thing seem feasible and useful?
>

It is an interesting idea. For the moment there are already 2 solutions :
- solution 1 : put your config parameters in the <servlet> tag for the
Redirector servlet in web.xml. Everything there is available in the implicit
config object
- solution 2 : use config.setInitParameter()

Solution 1 is good if you don't need to have different set of init values
for your tests and Solution 2 is the one to use if you want to have several
test cases but with different init parameter. For example, you may want to
verify that such method handles correctly the fact that such init parameter
is missing or when it has such given value, ...

Your solution is also possible but it looks to me it is a bit complicated as
compared to solution 1.  What do you think ?

> Perry Tew
Thanks!

Vincent.

Reply via email to