struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Michael Nash" <mn...@jcorporate.com>
Subject RE: ServletUnit with Struts
Date Sat, 25 Aug 2001 15:13:54 GMT
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
>


Mime
View raw message