Hi Rakesh,
----- Original Message -----
From: "Rakesh Bhalla" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, September 18, 2001 1:17 PM
Subject: Testing JSPs with Cactus v 1.1 - HOW TO ??
> Hello,
> I downloaded Cactus very recently. I tell you it is really a
> wonderful piece of software written for enterprise network. I could
> test it for servlets.
thanks
> Now I have got starting problems with testing JSPs with Cactus.
> The example file that was provided along with Cactus distribution
> contained a file in -
>
> sample/src/share/org/apache/org/apache/commons/cactus/sample/unit -
> called TestJspTestCase.java .
> I use cactus 1.1 .
>
> Now according to what I have interpreted, it contains a method called
> testOut which uses the out object of type JspWriter to write
> something and again in endOut an assertion is made if we get the
> right value.
> Now my question is if I have a test.jsp something like this.
>
> <!doctype html public "-//w3c/dtd HTML 4.0//en">
> <html>
> <head><title>Hello World</title></head>
> <body>
> <% out.print("Hello World!"); %>
> </body>
> </html>
>
> The file mentioned is the classic Hello World printing program.
>
> Now I want to test on the server side if actually the writer prints
> the Hello World! . Now how would I associate a JSP file to a JSP Test
> case in a servlet container ? I use the Tomcat v4 rc-2 container .
>
It seems what you are really trying to do is functional testing rather than
unit testing. However, functional testing is also possible with Cactus
although the main benefit is unit testing. Now, why would you want to assert
the output of the JSP on the server side ?
I think what you want to write is :
public class MyJspTest extends JspTestCase
{
public void testXXX()
{
pageContext.forward("/some/path/myjsp.jsp");
// (optional) assert values that the JSP would put in the session or
pageContext or servlet context scope. In your example, there are none.
}
// With Cactus 1.2:
public void endXXX(WebResponse theResponse)
{
assertEquals("Hello World!", theResponse.getText());
}
// With Cactus 1.1:
public void endXXX(HttpURLConnection theConnection)
{
assertEquals("Hello World!",
AssertUtils.getResponseAsString(theConnection));
}
}
Hope it helps.
-Vincent
Note: You can do the same by extending ServletTestCase and forwarding to
your JSP using a request dispatcher (see the cactus samples)
--
Vincent Massol, [EMAIL PROTECTED]
OCTO Technology, www.octo.com
Information System Architecture Consulting