Hi Toru,

* You can use AssertUtils.getResponseAsString() and
AssertUtils.getResponseAsStringAray() if you wish (see the sample tests for
how to use it)
* You might not need to use the setURL() API. This is used only to simulate
the URL. If you don't use it and call a method like request.getQueryString()
you'll get the query string that was used internally by Cactus to call the
Redirector Servlet. So you would use setURL() only if your code make use of
such methods to make _as if_ it was your servlet/JSP (and not the redirector
one) that was called.
* the goal of the JSP Redirector is not to test JSPs but rather to provide a
JSP environment (i.e. pageContext, ...) to test some of your classes that
would need it (like JSP tags, ...).

So what happens here is that the generic redirector.jsp JSP is called, which
in turn instanciate and call your SampleJspTester class, which does nothing
(nothing in testOut() ), so when endOut() is called (on the client side),
probably nothing has been written in the servlet output stream so that's why
you get null ... Your test.jsp is never called !

If what you want to do is simply to verify the result of calling your JSP,
you should  extend ServletTestCase and in testOut() write the following :

public void testOut()
{
        RequestDispatcher rd =
config.getServletContext().getRequestDispatcher("/test/test/test.jsp"); <--
put the correct path
        rd.forward(request, response);
}

Hope it helps.
-Vincent

----- Original Message -----
From: "Toru Suzuki" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, July 03, 2001 12:04 PM
Subject: [Cactus] JSP Test


> Hello All,
>
> I hava question. I want to test a simple JSP with cactus.
> I wrote JSP Tester Class(see below), but sb.toString() return "null".
>
> Is this correct beginOut() method?
>
>
> public class SampleJspTester extends JspTestCase {
>     public SampleJspTester(String name) {
>         super(name);
>     }
>
>     ....
>
>      public void beginOut(ServletTestRequest theRequest) {
>          theRequest.setURL("localhost:8080", null, "/test/test/test.jsp",
>                            null, null);
>      }
>
>      public void testOut() {
>
>      }
>
>      public void endOut(HttpURLConnection theConnection) throws
IOException {
>
>          StringBuffer sb = new StringBuffer();
>          BufferdReader input = new BufferdReader(new
InputStreamReader(theConnection
>
.getInputStream()));
>          String str;
>          while (null != ((str = input.readLine()))) {
>              sb.append(str);
>          }
>          System.out.println(sb.toString());
>          assert(sb.toString().indexOf("Hello !") > 0);
>      }
> }
>
> ---
> Toru Suzuki
> MHI Aerospace Systems Corp.
>

Reply via email to