Hi Jon,

A few general remarks first :) (we'll tackle the hard problems just after
... )

* The beginXXX() methods are optional so if you don't use it, you can simply
remove it from the test, making it more readable
* If you're testing for a positive response, like a doPost that executes
correctly, you shouldn't try to catch a possible error in a try/catch block.
Just let the exception be bounced up in the call stack. It will eventually
be picked up by the JUnit test runner. Again, this is to make it easier to
read a test and guess it's intent.

Ok, now the hard part ...

It actually looks quite strange. The line that seems to cause problem seems
to be the following from ServletTestCaller.java (although I am not sure as I
may be using a newer version than yours)

"        ServletTestResult result =
(ServletTestResult)theObjects.m_Config.getServletContext().getAttribute(TEST
_RESULTS);"

This line could return a null value if the attribute is not set but I don't
see how it could return an object of a type different than a
ServletTestResult unless :
* The getAtrtibute(TEST_RESULTS) calls returns a java object that is not a
ServletTestResult but as TEST_RESULTS is declared as 'private final static
String TEST_RESULTS = "ServletTestRedirector_TestResults";', I don't see how
this value could have been overwritten ...

No, sorry, I don't get it ... Could you try to trim your class under test
and your test class so that it contains minimum code (remove any unnecessary
code) that still triggers the error. Once done, could you send it to the
list ?

Thanks.
Vincent.

----- Original Message -----
From: "Jon Belinfante" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Thursday, May 24, 2001 5:49 PM
Subject: Cactus Error on testing servlet.doPost Method


> Hi Guys
>
> I am using Cactus to test a single servlet, connected to two EJB's in
> tomcat/jboss.
>
> All my tests on the servlet work except for when I try to test a doPost or
a
> doGet servlet on the code.
>
> My code is as follows
>
>
>
> public void beginProcessRequest(ServletTestRequest theRequest)
>           throws IOException
>     {
>     }
>
>   public void testProcessRequest( )
>                throws IOException, Exception
>     {
>
>           ViewStaffResourceServlet servlet =
>                new ViewStaffResourceServlet();
>           try
>           {
>                servlet.init(config);
>
>                servlet.doPost( request, response);
>           }
>
>           catch (Exception e)
>           {
>                throw e;
>           }
> }
>
> public void endProcessrequest(HttpURLConnection theConnection)
> {
> }
>
> When I run this test I get error messages from both Tomcat and also in the
> Cactus Dialog.
> The Error from Tomcat is as follows
>
> 2001-05-24 05:41:00 - Ctx( /staffResource ): Exception in: R(
/staffResource +
> /ServletRedirector + null) - java.lang.ClassCastException:
> org.apache.commons.cactus.ServletTestResult
>         at
>
org.apache.commons.cactus.server.ServletTestCaller.doGetResults(ServletTestC
aller.java:201)
>         at
>
org.apache.commons.cactus.server.ServletTestRedirector.doPost(ServletTestRed
irector.java:121)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
>         at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
>         at
> org.apache.tomcat.core.ServletWrapper.doService(ServletWrapper.java:404)
>         at org.apache.tomcat.core.Handler.service(Handler.java:286)
>         at
> org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372)
>         at
>
org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:79
7)
>         at
> org.apache.tomcat.core.ContextManager.service(ContextManager.java:743)
>         at
>
org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpC
onnectionHandler.java:210)
>         at
> org.apache.tomcat.service.TcpWorkerThread.runIt(PoolTcpEndpoint.java:416)
>         at
> org.apache.tomcat.util.ThreadPool$ControlRunnable.run(ThreadPool.java:498)
>         at java.lang.Thread.run(Thread.java:484)
>
> And the Error from Cactus  is as follows
>
> java.io.FileNotFoundException:
> http://localhost:8080/staffResource/ServletRedirector
>      at
>
sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection
.java:549)
>      at
>
org.apache.commons.cactus.client.ServletHttpClient.doTest(ServletHttpClient.
java:119)
>      at
>
org.apache.commons.cactus.ServletTestCase.runGenericTest(ServletTestCase.jav
a:153)
>      at
>
org.apache.commons.cactus.ServletTestCase.runTest(ServletTestCase.java:128)
>      at
>
org.apache.commons.cactus.AbstractTestCase.runBare(AbstractTestCase.java:266
)
>
> I feel resonably confident that I have my configuration correct because I
have
> other tests working correctly in the test suite - however I am always
willing to
> be proved wrong here.
> The name of my web-app here is staffResource.
>
> If anyone can help, I will be very greatful.
>
> Thanks
>
> Jon Belinfante
>
>
>
****************************************************************************
**************************************************************************
> This e-mail has been prepared using information  believed  by  the  author
> to be reliable and accurate, but CWB makes  no  warranty  as to accuracy
or
> completeness. In particular CWB does not  accept  responsibility  for
> changes  made to this e-mail after it was sent.  Any  opinions expressed
in
> this document are those of the author and do  not  necessarily reflect the
> opinions of the company or its affiliates. They may be subject to change
> without notice.
>
****************************************************************************
***************************************************************************
>
>
>

Reply via email to