I want to set up a test rig for HttpServlet things.
The idea is that my test rig creates (from scratch,
not underneath an actual HTTP/Tomcat/J2EE session)
both HttpServletRequest and HttpServletResponse
objects, populating them with realistic data,
then calls the HttpServlet with those as args,
then upon return checks the HttpServletResponse
object to see if the HttpServlet worked correctly.
Unfortunately I haven't been able to find any
public constructor for any class that implements
HttpServletRequest (I haven't even started looking
at HttpServletResponse because I'm already stumped
here), except one which takes another already-constructed
request object as parameter to constructor thereby
begging the question how to construct one from scratch
in the first place.
So I decided to write my own dummy request class which
would implement the interface hence be acceptable as
parameter to a servlet, starting with this skeleton:
public class DummyHttpServletRequest
implements javax.servlet.http.HttpServletRequest {
}
I tried to compile that, expecting to get a compiler
error that I'm missing one or more of the methods
needed to implement the interface. Instead I got this:
DummyHttpServletRequest.java:2: cannot resolve symbol
symbol : class HttpServletRequest
location: package http
implements javax.servlet.http.HttpServletRequest {
^
1 error
What's wrong, and how can I fix it so I can move ahead with this project??
.
ByteCoder - 15 May 2005 13:55 GMT
> I want to set up a test rig for HttpServlet things.
> The idea is that my test rig creates (from scratch,
[quoted text clipped - 35 lines]
> What's wrong, and how can I fix it so I can move ahead with this
> project?? .
This class:
javax.servlet.http.HttpServletRequestWrapper
"Provides a convenient implementation of the HttpServletRequest
interface that can be subclassed by developers wishing to adapt the
request to a Servlet. This class implements the Wrapper or Decorator
pattern. Methods default to calling through to the wrapped request
object."
I think you are being too hard on yourself, maybe you should try an
'easy' way out and extend the HttpServletRequestWrapper.

Signature
-------------
- ByteCoder - ...I see stupid people
-------------
Curiosity *Skilled* the cat
shakah - 15 May 2005 17:02 GMT
> I want to set up a test rig for HttpServlet things.
> The idea is that my test rig creates (from scratch,
[quoted text clipped - 34 lines]
>
> What's wrong, and how can I fix it so I can move ahead with this project??
Is that class in your compilation classpath? After a quick look in
Tomcat's directories, it appears to exist in
./common/lib/servlet-api.jar.
Wibble - 15 May 2005 17:47 GMT
Your looking for a 'Mock Object' servlet engine.
http://strutstestcase.sourceforge.net/api/servletunit/package-summary.html
http://java-source.net/open-source/testing-tools/mockrunner
are some examples.
Also look at htmlunit
http://htmlunit.sourceforge.net/
for testing the client side.
I rolled my own mock servlet engine, it wasnt too hard, and coupled
it with htmlunit for full testing of servlets, javascript, jsps etc.
>>I want to set up a test rig for HttpServlet things.
>>The idea is that my test rig creates (from scratch,
[quoted text clipped - 40 lines]
> Tomcat's directories, it appears to exist in
> ./common/lib/servlet-api.jar.
Ross Bamford - 15 May 2005 22:05 GMT
> I want to set up a test rig for HttpServlet things.
> The idea is that my test rig creates (from scratch,
[quoted text clipped - 4 lines]
> then upon return checks the HttpServletResponse
> object to see if the HttpServlet worked correctly.
You cannot construct one because it is implementation-specific - the
Servlet Container provides an implementation that suits it's internal
layout (usually as a facade to many other objects).
Instead try:
1) http://www.mockobjects.com/FrontPage.html

Signature
[Ross A. Bamford] [ross AT the.website.domain]
Roscopeco Open Tech ++ Open Source + Java + Apache + CMF
http://www.roscopec0.f9.co.uk/ + info@the.website.domain