I'm trying to test a servlet whose service() method throws a ServletException (actually my own exception which is a subclass of ServletException). In the live app, this is trapped by an <error-page> definition and handled by a special error servlet.
However, the servletunit framework catches my servletexception and throws a runtime exception (something like HttpUnitInternalServerException). I tried catching that, but it does not provide my original exception (it only shows the message) and no response is available.
I was trying to think of ways to allow me to test for the throwing of a ServletException AND getting the response even in that case:
a) ServletUnit could support definition of equivalent of <error-page> entries, thus allowing invocation of another servlet in the event of an error. However, this makes the test less of a single unit of work.
b) Allow ServletExceptions to pass all the way to the unit test and let my test catch them. This might involve changing a number of signatures.
c) (I patched my own httpunit source to do this one). Define a new runtime exception, e.g. ServletUnitServletException, that maintains both the original ServletException and the WebResponse. This allows me to catch that exception and examine the response and the ServletException that was thrown. Of course, it would be documented that this runtime exception is thrown.
Anyone else had this issue? Any thoughts?
If (c) was acceptable, I can contribute a patch. Does HttpUnit strive to be compatibile with JDK 1.3?
Tim
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm trying to test a servlet whose service() method throws a ServletException (actually my own exception which is a subclass of ServletException). In the live app, this is trapped by an <error-page> definition and handled by a special error servlet.
However, the servletunit framework catches my servletexception and throws a runtime exception (something like HttpUnitInternalServerException). I tried catching that, but it does not provide my original exception (it only shows the message) and no response is available.
I was trying to think of ways to allow me to test for the throwing of a ServletException AND getting the response even in that case:
a) ServletUnit could support definition of equivalent of <error-page> entries, thus allowing invocation of another servlet in the event of an error. However, this makes the test less of a single unit of work.
b) Allow ServletExceptions to pass all the way to the unit test and let my test catch them. This might involve changing a number of signatures.
c) (I patched my own httpunit source to do this one). Define a new runtime exception, e.g. ServletUnitServletException, that maintains both the original ServletException and the WebResponse. This allows me to catch that exception and examine the response and the ServletException that was thrown. Of course, it would be documented that this runtime exception is thrown.
Anyone else had this issue? Any thoughts?
If (c) was acceptable, I can contribute a patch. Does HttpUnit strive to be compatibile with JDK 1.3?
Tim