Re: getNamedDispatcher and named JSP pages
Izzy Alanis <[email protected]> Wed, 19 May 2010 11:45:09 -0400
| Newsgroups | gmane.comp.web.httpunit.devel |
|---|---|
| Message-ID | <[email protected]> |
Your test for getNamedDispatcher was close.
In the test setup (in RequestDispatcherTest) you're calling this
version of addServlet:
addServlet( String urlPattern, Class servletClass ).
You need to call:
addServlet( String name, String urlPattern, Class servletClass )
So that the servlet has a specific name, that you can use later in
your call to getNamedDispatcher.
A simple fix would be to change (~line 88ish?):
_wxs.addServlet( errorPageServletName, ErrorPageServlet.class);
to:
_wxs.addServlet( errorPageServletName, errorPageServletName,
ErrorPageServlet.class);
An even better test would be to have the name and the urlPattern for
the servlet use separate values, so you know you're really accessing
the servlet by the *name* configured in the web xml and not the
servlet path.
_wxs.addServlet( "foobar", errorPageServletName, ErrorPageServlet.cl=
ass);
...
RequestDispatcher rd =3D
servlet.getServletContext().getNamedDispatcher("foobar");
assertNotNull("the dispatcher returned by getNamedDispatcher
should not be null",rd);
My particular use case also had to do with (and the patch included
support for) a named jsp file. A configuration that looked something
like:
<servlet>
<servlet-name>errorPage</servlet-name>
<display-name>Default Error Page</display-name>
<jsp-file>/errorPage.jsp</jsp-file>
</servlet>
That would be another good thing to add to the tests, but the
WebXMLString class can't (yet) create that type of configuration.
- Izzy
2010/5/7 Wolfgang Fahl <[email protected]>:
> Izzy,
>
> thank you for this patch. Subversion revision 1066 has your patch (at lea=
st
> so I hope). I was not able to get a proper JUnit test coded and working
> for this. Since your patch did not break any other test i have still
> submitted it. Would you please have a look at revision 1066 and let me kn=
ow
> what needs to be fixed to get things working the way you expected it?
>
> Yours
> =A0 wolfgang
> Am 28.12.09 16:17, schrieb Izzy Alanis:
>
> I needed to unit test an app that used getNamedDispatcher to reference
> a named jsp page. So, the servlet does something like:
>
> RequestDispatcher errorPage =3D
> getServletContext().getNamedDispatcher("errorPage");
> errorPage.forward(request, response);
>
> Where "errorPage" is defined in the web.xml as:
>
> <servlet>
> <servlet-name>errorPage</servlet-name>
> <display-name>Generic Error Page</display-name>
> <jsp-file>/errorPage.jsp</jsp-file>
> </servlet>
>
> Anyway, I've used httpunit before and am happy with it, but I was
> surprised to find that getNamedDispatcher wasn't implemented, so I
> patched up something quick to make it work (for me, ymmv).
>
> http://pastebin.com/f15093292
>
>
> -------------------------------------------------------------------------=
-----
> This SF.Net email is sponsored by the Verizon Developer Community
> Take advantage of Verizon's best-in-class app development support
> A streamlined, 14 day to market process makes app distribution fast and e=
asy
> Join now and get one step closer to millions of Verizon customers
> http://p.sf.net/sfu/verizon-dev2dev
>
> _______________________________________________
> Httpunit-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/httpunit-develop
>
>
> --
>
> BITPlan - smart solutions
> Wolfgang Fahl
> Pater-Delp-Str. 1, D-47877 Willich Schiefbahn
> Tel. +49 2154 811-480, Fax +49 2154 811-481
> Web: http://www.bitplan.de
> BITPlan GmbH, Willich - HRB 6820 Krefeld, Steuer-Nr.: 10258040548,
> Gesch=E4ftsf=FChrer: Wolfgang Fahl
>
> -------------------------------------------------------------------------=
-----
>
>
> _______________________________________________
> Httpunit-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/httpunit-develop
>
>
---------------------------------------------------------------------------=
---