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 Kim Thrysøe <kt...@netnord.dk> on 2002/01/11 13:28:19 UTC

Cactus Tests and WebApp seem to use different class loaders

When I recently changed to tomcat4 my Cactus tests seem to work on 
different classes (different class loader) than the web application, 
which suggests that I have something wrong in my Cactus 
configuration(?). The result of course is that my testcases work on an 
uninitialized instance of the application that I am testing.

My cactus version is 1.2, jdk is 1.3.1, tomcat is 4.0.1.

I can see that at least one other person has had trouble with a 
ServletRedirector been configured to the wrong context, so I suspect 
that this has something to do with my problem. However, the 
ServletRedirector runs in the same context as the rest of the webapp.

The webapp (a single Filter) is configured to use the default context 
and sits in "/". This Filter is configured to keep its hands from 
"/ServletRedirector/*", which it also does -- i.e. the tests *are* 
executed.

The cactus.properties file contains simply
cactus.servletRedirectorURL = http://localhost:80/ServletRedirector/

The web.xml has the two servlets mounted as follows
 <!-- *****************
       * Root Servlets *
       ***************** -->
  <filter>
    <filter-name>rootFilter</filter-name>
    <filter-class>dk.netnord.cmd.servlet.RootFilter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>rootFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>

  <!-- *****************************
       * Serverside unit testing servlets *
       ***************************** -->
    <servlet>
        <servlet-name>ServletRedirector</servlet-name>
        
<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>ServletRedirector</servlet-name>
        <url-pattern>/ServletRedirector/</url-pattern>
    </servlet-mapping>

Does anyone have experiences in this direction or can anyone explain why 
the test Classes use a different ClassLoader?

Cheers

-- 
Kim Thrysoe - Netnord A/S - http://www.netnord.dk



--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


RE: Cactus Tests and WebApp seem to use different class loaders

Posted by Vincent Massol <vm...@octo.com>.
Hi Kim,

Are you unit testing a filter or any java class that is called by a
filter ? If so you probably want to look at
http://jakarta.apache.org/cactus/howto_testcase_filter.html

It will not work if you're using a ServletRedirector which should be
used only to unit test servlet code or any code called by a servlet.

Hope it helps and sorry for answering so late.
-Vincent

> -----Original Message-----
> From: Kim Thrysøe [mailto:kt@netnord.dk]
> Sent: 11 January 2002 12:28
> To: cactus-user@jakarta.apache.org
> Subject: Cactus Tests and WebApp seem to use different class loaders
> 
> When I recently changed to tomcat4 my Cactus tests seem to work on
> different classes (different class loader) than the web application,
> which suggests that I have something wrong in my Cactus
> configuration(?). The result of course is that my testcases work on an
> uninitialized instance of the application that I am testing.
> 
> My cactus version is 1.2, jdk is 1.3.1, tomcat is 4.0.1.
> 
> I can see that at least one other person has had trouble with a
> ServletRedirector been configured to the wrong context, so I suspect
> that this has something to do with my problem. However, the
> ServletRedirector runs in the same context as the rest of the webapp.
> 
> The webapp (a single Filter) is configured to use the default context
> and sits in "/". This Filter is configured to keep its hands from
> "/ServletRedirector/*", which it also does -- i.e. the tests *are*
> executed.
> 
> The cactus.properties file contains simply
> cactus.servletRedirectorURL = http://localhost:80/ServletRedirector/
> 
> The web.xml has the two servlets mounted as follows
>  <!-- *****************
>        * Root Servlets *
>        ***************** -->
>   <filter>
>     <filter-name>rootFilter</filter-name>
>     <filter-class>dk.netnord.cmd.servlet.RootFilter</filter-class>
>   </filter>
>   <filter-mapping>
>     <filter-name>rootFilter</filter-name>
>     <url-pattern>/*</url-pattern>
>   </filter-mapping>
> 
>   <!-- *****************************
>        * Serverside unit testing servlets *
>        ***************************** -->
>     <servlet>
>         <servlet-name>ServletRedirector</servlet-name>
> 
>
<servlet-class>org.apache.cactus.server.ServletTestRedirector</servlet-
> class>
>     </servlet>
>     <servlet-mapping>
>         <servlet-name>ServletRedirector</servlet-name>
>         <url-pattern>/ServletRedirector/</url-pattern>
>     </servlet-mapping>
> 
> Does anyone have experiences in this direction or can anyone explain
why
> the test Classes use a different ClassLoader?
> 
> Cheers
> 
> --
> Kim Thrysoe - Netnord A/S - http://www.netnord.dk
> 
> 
> 
> --
> To unsubscribe, e-mail:   <mailto:cactus-user-
> unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: <mailto:cactus-user-
> help@jakarta.apache.org>
> 




--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>