You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by "Fromm, Stefan" <Fr...@dresden-informatik.de> on 2005/03/04 15:04:15 UTC

How to test servlet with filters?

Hello,

I've successfully set up Cactus 1.7 for J2EE 1.3 with Tomcat 5 and try
out how to write servlet tests with it. I encountered a problem:

I want to test a servlet which is originally configured to be executed
after two filters have been called. All the samples in the Cactus
distribution create the servlet instance on server side, configure and
run it.

My dilemma:
1) Whether I get access to an already configured servlet in my web.xml.
Here
   the problem is that the servlet specification forbids to retrieve a
   servlet instance by name.
2) Or: I can manage to create both filters and the servlet, configure
them
   and run it in the same TestCase class. Problem here is that
   ServletTestCase and FilterTestCase only allow me to access one type
of
   ConfigWrapper. So I cannot call config.init() first for the two
filters
   and then for the servlet.

The first option would be my favourite because with this I can trust
that really the container created and initialized everything.

Can anybody give me hints on how I can solve my problem?

Kind regards and thanks in advance
Stefan Fromm