You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by Patrick Lightbody <pl...@hotmail.com> on 2002/07/30 14:45:27 UTC

Using Cactus with WebWork

Has anyone used Cactus with WebWork? I'd like to be able to have the
container execute my WW actions and then somehow check the getXxx methods in
my actions for valid data. Has anyone done this?

-Pat

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Using Cactus with WebWork

Posted by Patrick Lightbody <pl...@hotmail.com>.
I have a base action for all my WebWork-based test cases that provides this
function:

    protected ActionResult executeAction(String name, Map paramters) {
        ActionContext ac = new ActionContext();
        ac.setRequest(request);
        ac.setParameters(paramters);
        ActionContext.setContext(ac);

        try {
            Action a = webwork.action.factory.ActionFactory.getAction(name);
            String result = a.execute();
            return new ActionResult(result, a);
        } catch (Exception e) {
            log.fatal("Could not execute WebWork action", e);
            return null;
        }
    }

    public class ActionResult {
        private String result;
        private Action action;

        public ActionResult(String result, Action action) {
            this.result = result;
            this.action = action;
        }

        public String getResult() {
            return result;
        }

        public Action getAction() {
            return action;
        }
    }



----- Original Message -----
From: "Vincent Massol" <vm...@octo.com>
To: "'Cactus Users List'" <ca...@jakarta.apache.org>
Sent: Sunday, August 04, 2002 12:48 PM
Subject: RE: Using Cactus with WebWork


> If you make some progress on the subject, could you post back - We could
> add a Howto page on Cactus web page to explain how to do this ... :-)
>
> Thanks
> -Vincent
>
> > -----Original Message-----
> > From: Vincent Massol [mailto:vmassol@octo.com]
> > Sent: 04 August 2002 20:44
> > To: 'Cactus Users List'
> > Cc: 'Patrick Lightbody'
> > Subject: RE: Using Cactus with WebWork
> >
> > Hi Patrick,
> >
> > I have not done it and I have never used webwork (Actually I just
> > noticed it is now a subproject of opensymphony. Congratulations!).
> >
> > Ok, I've just had a very quick look at webwork.
> >
> > I guess it all depends what you want to test. I can see several
> > possibilities :
> >
> > 1/ test your action. You do not need Cactus for that as the Actions
> are
> > pure java beans that you can test directly from JUnit easily (using a
> > Mock Objects approach if need be).
> >
> > 2/ test integration of your action in the container, to ensure that
> > everything is set up correctly for example.
> >
> > For 2/, Cactus needs to control the server side, thus you would have
> to
> > do something like the following in your testXXX() :
> >
> > public void testXXX()
> > {
> >    ServletDispatcher dispatcher = new ServletDispatcher();
> >    dispatcher.init(config);
> >
> >    // Start web work
> >    dispatcher.service(request, response);
> >
> >    // Get a handle on your action
> >    Action action = ActionFactory.getAction("your action name");
> >
> >    // Perform asserts on your action
> >    asssertEquals("xxx", action.getXXX());
> > }
> >
> > Note: You need to define all the parameters needed by
> ServletDispatcher
> > on the Cactus ServeltRedirector in your web.xml.
> >
> > Would that do the trick for you ?
> >
> > Hope it helps (again I have just learned WebWork in 15 minutes by
> > looking at the ServletDispatcher code so I'm may be completely of the
> > mark!).
> >
> > Thanks
> > -Vincent
> >
> >
> > > -----Original Message-----
> > > From: Patrick Lightbody [mailto:plightbo@hotmail.com]
> > > Sent: 30 July 2002 13:45
> > > To: cactus-user@jakarta.apache.org
> > > Subject: Using Cactus with WebWork
> > >
> > > Has anyone used Cactus with WebWork? I'd like to be able to have the
> > > container execute my WW actions and then somehow check the getXxx
> > methods
> > > in
> > > my actions for valid data. Has anyone done this?
> > >
> > > -Pat
> > >
> > > --
> > > To unsubscribe, e-mail:   <mailto:cactus-user-
> > > unsubscribe@jakarta.apache.org>
> > > For additional commands, e-mail: <mailto:cactus-user-
> > > help@jakarta.apache.org>
> >
> >
> >
> > --
> > To unsubscribe, e-mail:   <mailto:cactus-user-
> > unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <mailto:cactus-user-
> > help@jakarta.apache.org>
>
>
>
> --
> To unsubscribe, e-mail:
<ma...@jakarta.apache.org>
> For additional commands, e-mail:
<ma...@jakarta.apache.org>
>
>

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Using Cactus with WebWork

Posted by Vincent Massol <vm...@octo.com>.
If you make some progress on the subject, could you post back - We could
add a Howto page on Cactus web page to explain how to do this ... :-)

Thanks
-Vincent

> -----Original Message-----
> From: Vincent Massol [mailto:vmassol@octo.com]
> Sent: 04 August 2002 20:44
> To: 'Cactus Users List'
> Cc: 'Patrick Lightbody'
> Subject: RE: Using Cactus with WebWork
> 
> Hi Patrick,
> 
> I have not done it and I have never used webwork (Actually I just
> noticed it is now a subproject of opensymphony. Congratulations!).
> 
> Ok, I've just had a very quick look at webwork.
> 
> I guess it all depends what you want to test. I can see several
> possibilities :
> 
> 1/ test your action. You do not need Cactus for that as the Actions
are
> pure java beans that you can test directly from JUnit easily (using a
> Mock Objects approach if need be).
> 
> 2/ test integration of your action in the container, to ensure that
> everything is set up correctly for example.
> 
> For 2/, Cactus needs to control the server side, thus you would have
to
> do something like the following in your testXXX() :
> 
> public void testXXX()
> {
>    ServletDispatcher dispatcher = new ServletDispatcher();
>    dispatcher.init(config);
> 
>    // Start web work
>    dispatcher.service(request, response);
> 
>    // Get a handle on your action
>    Action action = ActionFactory.getAction("your action name");
> 
>    // Perform asserts on your action
>    asssertEquals("xxx", action.getXXX());
> }
> 
> Note: You need to define all the parameters needed by
ServletDispatcher
> on the Cactus ServeltRedirector in your web.xml.
> 
> Would that do the trick for you ?
> 
> Hope it helps (again I have just learned WebWork in 15 minutes by
> looking at the ServletDispatcher code so I'm may be completely of the
> mark!).
> 
> Thanks
> -Vincent
> 
> 
> > -----Original Message-----
> > From: Patrick Lightbody [mailto:plightbo@hotmail.com]
> > Sent: 30 July 2002 13:45
> > To: cactus-user@jakarta.apache.org
> > Subject: Using Cactus with WebWork
> >
> > Has anyone used Cactus with WebWork? I'd like to be able to have the
> > container execute my WW actions and then somehow check the getXxx
> methods
> > in
> > my actions for valid data. Has anyone done this?
> >
> > -Pat
> >
> > --
> > To unsubscribe, e-mail:   <mailto:cactus-user-
> > unsubscribe@jakarta.apache.org>
> > For additional commands, e-mail: <mailto:cactus-user-
> > help@jakarta.apache.org>
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Using Cactus with WebWork

Posted by Vincent Massol <vm...@octo.com>.
Hi Patrick,

I have not done it and I have never used webwork (Actually I just
noticed it is now a subproject of opensymphony. Congratulations!).

Ok, I've just had a very quick look at webwork.

I guess it all depends what you want to test. I can see several
possibilities :

1/ test your action. You do not need Cactus for that as the Actions are
pure java beans that you can test directly from JUnit easily (using a
Mock Objects approach if need be).

2/ test integration of your action in the container, to ensure that
everything is set up correctly for example.

For 2/, Cactus needs to control the server side, thus you would have to
do something like the following in your testXXX() :

public void testXXX()
{
   ServletDispatcher dispatcher = new ServletDispatcher();
   dispatcher.init(config);

   // Start web work
   dispatcher.service(request, response);

   // Get a handle on your action
   Action action = ActionFactory.getAction("your action name");

   // Perform asserts on your action
   asssertEquals("xxx", action.getXXX());
}

Note: You need to define all the parameters needed by ServletDispatcher
on the Cactus ServeltRedirector in your web.xml.

Would that do the trick for you ?

Hope it helps (again I have just learned WebWork in 15 minutes by
looking at the ServletDispatcher code so I'm may be completely of the
mark!).

Thanks
-Vincent


> -----Original Message-----
> From: Patrick Lightbody [mailto:plightbo@hotmail.com]
> Sent: 30 July 2002 13:45
> To: cactus-user@jakarta.apache.org
> Subject: Using Cactus with WebWork
> 
> Has anyone used Cactus with WebWork? I'd like to be able to have the
> container execute my WW actions and then somehow check the getXxx
methods
> in
> my actions for valid data. Has anyone done this?
> 
> -Pat
> 
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>