Mimic an HTTPRequest and HTTPResponse object in Java

Posted by Ankur on Stack Overflow See other posts from Stack Overflow or by Ankur
Published on 2010-05-20T03:34:22Z Indexed on 2010/05/20 3:40 UTC
Read the original article Hit count: 287

How do I mimic an HTTPServletRequest and HTTPServletResponse object. The reason is I want to test the behaviour of some servlets.

I know JUnit probably provides this functionality but I don't know how to use it (I will learn soon) and need to do this reasonably quickly.

HTTPServletRequest and HTTPServletResponse are both interfaces so they can't be instantiated. There is a HttpServletRequestWrapper which implements HttpServletRequest but it doesn't seem to have any setParameter() type methods and HttpServletResponse doesn't seem to have any implementing classes at all.

How can I test my code by passing a suitable HttpServletRequest object and then checking that the received HttpServletResponse object matches what I expect?

© Stack Overflow or respective owner

Related posts about java

Related posts about servlets