RE: ServletUnit with Struts

2001-08-31 Thread dion

> http://httpunit.sourceforge.net/

> I believe that it is primarily a functional testing tool.  I would
imagine
> that you could use it for load-testing...

I wouldn't believe it. Our attempts to load test with HttpUnit spent more
time parsing code on the client than they did generate HTTP requests.
--
dIon Gillard, Multitask Consulting
Work:  http://www.multitask.com.au
JavaNews: http://www.multitask.com.au/JavaNews
- Forwarded by dIon Gillard/Multitask Consulting/AU on 31/08/2001 02:24
PM -
RE: ServletUnit with Struts



ServletUnit is part of the open-source HttpUnit testing framework.  You can
get HttpUnit from SourceForge at:

http://httpunit.sourceforge.net/

I believe that it is primarily a functional testing tool.  I would imagine
that you could use it for load-testing...


Regarding my original problem.

The solution I am now pursuing, so far with success, is removing almost all
of the application-specific "meat" from my Action subclasses.  I will
delegate to a simple command class from the action.  The command class will
take input paramaters, access the model layer to carry out the operation,
and make available a logical forwarding name, result objects hash, and
ActionErrors which can be accessed by the Action class following command
execution.  All that will be left in the Action class will be Struts
frame-worky stuff.

The consequence is that I can unit test the command independently with
vanilla junit, without relying on a host of mock servlet / struts objects
or an in-container testing framework.  The only Struts object I'm going to
allow the commands to work with is an ActionErrors instance.  Removing that
Struts dependency would be even nicer, in that you could then survive a
departure from the struts framework with the vast bulk of your control
layer logic unaffected.  Easy to get rid of the ActionErrors and just have
the command class save the keys of the errors in a collection...

We'll see how this goes...

Jim Weaver
Software Developer - ThoughtWorks




"Duffey,
Kevin"   To:
"'[EMAIL PROTECTED]'" <[EMAIL PROTECTED]>
     Subject: RE: ServletUnit with
Struts

08/24/2001
04:17 PM
Please respond
to struts-user






I haven't seen ServletUnit. Where do you get it from? Can it be used to
load-test a site?

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 24, 2001 1:59 PM
> To: [EMAIL PROTECTED]
> Subject: ServletUnit with Struts
>
>
>
> Hi,
>
> I'm trying to test ActionObjects painlessly with Mock Objects
> of some kind;
> I don't want in-container test cases particularly.  I'm trying to use
> ServletUnit, which is part of HttpUnit, as a starting point
> and am having a
> difficulty, not surprisinglym with the ActionServlet initialization.
>
> Here's a snippet of the test code:
>
>   WebRequest request = new PostMethodWebRequest
> ("http://test.meterware.com/actionServlet";);
>   request.setParameter etc.  set some parms for testing...
>
>   WebResponse response = sc.getResponse(request);
>
> The above line throws an exception when I run the testcase:
> javax.servlet.UnavailableException: Missing configuration
> resource for path
> /WEB-INF/struts-config.xml
>  at
> org.apache.struts.action.ActionServlet.initMapping(ActionServl
> et.java:1316)
>  at
> org.apache.struts.action.ActionServlet.init(ActionServlet.java:465)
>  at javax.servlet.GenericServlet.init(GenericServlet.java:258)
>  at
> com.meterware.servletunit.InvocationContext.getServlet(Invocat
> ionContext.java:69)
>
> I have added the war file for my application, which includes the
> /WEB-INF/struts-config.xml, at the bottom of my classpath
> that the testcase
> runs under junit with.
>
> Hmmm, just putting this email together I spotted something.
> The resource
> is obtained via getServletContext().getResourceAsStream
> ("/WEB-INF/struts-config.xml").  The servlet context must not
> be such that
> it is able to find that path in my war.
>
> Anybody used ServletUnit with Struts?  Or some other Mock
> Objects solution?
>
> tia,
> Jim Weaver
>
>






   
   
   
  Previous Document (Embe (Embe Next Document  
dded   dded
image image   

RE: ServletUnit with Struts

2001-08-25 Thread Michael Nash

Jim:

One of our contributors has just recently integrated Cactus with our
framework, and Struts components can be tested that way as well, and we've
used Junit for some time too. You may find some useful code for what you're
doing that way... I know he did a lot of work getting the initialization to
come up clean, so it may save you some time, if I understand what you're
looking for correctly.

Regards,

Mike
http://www.jcorporate.com


> I'm trying to test ActionObjects painlessly with Mock Objects of
> some kind;
> I don't want in-container test cases particularly.  I'm trying to use
> ServletUnit, which is part of HttpUnit, as a starting point and
> am having a
> difficulty, not surprisinglym with the ActionServlet initialization.
>
> Here's a snippet of the test code:
>
>   WebRequest request = new PostMethodWebRequest
> ("http://test.meterware.com/actionServlet";);
>   request.setParameter etc.  set some parms for testing...
>
>   WebResponse response = sc.getResponse(request);
>
> The above line throws an exception when I run the testcase:
> javax.servlet.UnavailableException: Missing configuration
> resource for path
> /WEB-INF/struts-config.xml
>  at
> org.apache.struts.action.ActionServlet.initMapping(ActionServlet.j
> ava:1316)
>  at
> org.apache.struts.action.ActionServlet.init(ActionServlet.java:465)
>  at javax.servlet.GenericServlet.init(GenericServlet.java:258)
>  at
> com.meterware.servletunit.InvocationContext.getServlet(InvocationC
> ontext.java:69)
>
> I have added the war file for my application, which includes the
> /WEB-INF/struts-config.xml, at the bottom of my classpath that
> the testcase
> runs under junit with.
>
> Hmmm, just putting this email together I spotted something.  The resource
> is obtained via getServletContext().getResourceAsStream
> ("/WEB-INF/struts-config.xml").  The servlet context must not be such that
> it is able to find that path in my war.
>
> Anybody used ServletUnit with Struts?  Or some other Mock Objects
> solution?
>
> tia,
> Jim Weaver
>




Re: ServletUnit with Struts

2001-08-25 Thread Ted Husted

[EMAIL PROTECTED] wrote:
> The solution I am now pursuing, so far with success, is removing almost all
> of the application-specific "meat" from my Action subclasses.  I will
> delegate to a simple command class from the action.  The command class will
> take input paramaters, access the model layer to carry out the operation,
> and make available a logical forwarding name, result objects hash, and
> ActionErrors which can be accessed by the Action class following command
> execution.  All that will be left in the Action class will be Struts
> frame-worky stuff.

> The consequence is that I can unit test the command independently with
> vanilla junit, without relying on a host of mock servlet / struts objects
> or an in-container testing framework.  

+1 = The day I became a true believe in layered Web applications was the
day I realized that the only reasonable way to Unit Test a Web
applications was to separate the business logic from the Web tier, so
tools like JUnit can be used.

Ideally, an Action should be an adapter to handle the error checking and
control flow. Everything else should be delegated to other objects, with
no HTTP dependencies, that can be used in other environments, and tested
with Junit.

> The only Struts object I'm going to
> allow the commands to work with is an ActionErrors instance.  Removing that
> Struts dependency would be even nicer, in that you could then survive a
> departure from the struts framework with the vast bulk of your control
> layer logic unaffected.  Easy to get rid of the ActionErrors and just have
> the command class save the keys of the errors in a collection...

You might consider having the command class return generic error codes,
and then map those to the ActionErrors. For (quick and dirty) example:

int error = command(something); 
if (error==CommandErrors.NOT_FOUND) { 
errors.add(ActionErrors.GLOBAL_ERROR, new
ActionError("errors.not.found"));
}


-- Ted Husted, Husted dot Com, Fairport NY USA.
-- Custom Software ~ Technical Services.
-- Tel +1 716 737-3463
-- http://www.husted.com/about/struts/



RE: ServletUnit with Struts

2001-08-24 Thread Duffey, Kevin

I haven't seen ServletUnit. Where do you get it from? Can it be used to
load-test a site?

> -Original Message-
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Friday, August 24, 2001 1:59 PM
> To: [EMAIL PROTECTED]
> Subject: ServletUnit with Struts
> 
> 
> 
> Hi,
> 
> I'm trying to test ActionObjects painlessly with Mock Objects 
> of some kind;
> I don't want in-container test cases particularly.  I'm trying to use
> ServletUnit, which is part of HttpUnit, as a starting point 
> and am having a
> difficulty, not surprisinglym with the ActionServlet initialization.
> 
> Here's a snippet of the test code:
> 
>   WebRequest request = new PostMethodWebRequest
> ("http://test.meterware.com/actionServlet";);
>   request.setParameter etc.  set some parms for testing...
> 
>   WebResponse response = sc.getResponse(request);
> 
> The above line throws an exception when I run the testcase:
> javax.servlet.UnavailableException: Missing configuration 
> resource for path
> /WEB-INF/struts-config.xml
>  at
> org.apache.struts.action.ActionServlet.initMapping(ActionServl
> et.java:1316)
>  at 
> org.apache.struts.action.ActionServlet.init(ActionServlet.java:465)
>  at javax.servlet.GenericServlet.init(GenericServlet.java:258)
>  at
> com.meterware.servletunit.InvocationContext.getServlet(Invocat
> ionContext.java:69)
> 
> I have added the war file for my application, which includes the
> /WEB-INF/struts-config.xml, at the bottom of my classpath 
> that the testcase
> runs under junit with.
> 
> Hmmm, just putting this email together I spotted something.  
> The resource
> is obtained via getServletContext().getResourceAsStream
> ("/WEB-INF/struts-config.xml").  The servlet context must not 
> be such that
> it is able to find that path in my war.
> 
> Anybody used ServletUnit with Struts?  Or some other Mock 
> Objects solution?
> 
> tia,
> Jim Weaver
> 
>