jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Pedro Nevado" <pnev...@javato.com>
Subject RE: Sample Cactus project-specifically JSP example
Date Fri, 18 Nov 2005 16:26:16 GMT
I use MVC architectures (Struts, Spring Web) and JSTL for tags, so I do no put almost any worthy
 to test in a JSP, with the exception of the state of some scoped variables, as it showed
my previous example. For that kind of tests, I prefer to extend ServletTestCase.
  -----Mensaje original-----
  De: Nagaraj Palanichamy [mailto:nagaraj.palanichamy@gmail.com]
  Enviado el: jueves, 17 de noviembre de 2005 15:50
  Para: Pedro Nevado
  Asunto: Re: Sample Cactus project-specifically JSP example

             Still there is some confusion. Whatever we have discussed so far is extending
ServletTestCsae. Do you have anything like for extending JspTestCase?

  Thank you
  Nagaraj P

  On 11/17/05, Pedro Nevado <pnevado@javato.com> wrote: 
    Nagaraj, try with what  I have added to the begin() method.
    I hope it helps.
      -----Mensaje original-----
      De: Nagaraj Palanichamy [mailto: nagaraj.palanichamy@gmail.com]
      Enviado el: jueves, 17 de noviembre de 2005 13:48
      Para: pnevado@javato.com
      Asunto: Re: Sample Cactus project-specifically JSP example

                   Greetings!! Now i have got some idea about the ServletTestCase.Please clirify
the following.

      My MyServletTestCase  looks like:::

      package com.test;

      import javax.servlet.ServletException;
      import junit.framework.Test;
      import org.apache.cactus.ServletTestCase;
      import org.apache.cactus.WebRequest;
      import org.apache.cactus.WebResponse;

      public class MyServletTestCase  extends ServletTestCase {
       private TestServlet ts=null;

        public TestServletCase(){
         System.out.println("Inside the TestServletCase");
        public TestServletCase(String name){
        public TestServletCase(String name,Test t){ 

        protected void setUp(){
         ts=new TestServlet();
         }catch(ServletException se){
          System.out.println("Inside the Servletexception se");
          se.printStackTrace ();

        public void begin(WebRequest request){

         request.addParameter("txtName","Nagaraj" [Pedro Nevado] ,WebRequest.POST_METHOD 

        public void testValidSearch(){
         System.err.println("Inside the testValidSearch");
        public void endValidSearch(WebResponse response){
         assertTrue((response.getText().indexOf("Error:")<0) && 
           (response.getText().indexOf("Search results") >=0 ));
        protected void tearDown(){
        private void invokePost(){
           ts.doPost(this.request, this.response);
         }catch(Exception ex){

      The Actual servlet looks like::::

      package com.test;

      import javax.servlet.ServletConfig;
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse ;
      import java.io.IOException;
      import javax.servlet.RequestDispatcher;

      public class TestServlet extends HttpServlet{
       public void init(ServletConfig config) throws ServletException{
       public void doPost(HttpServletRequest req,HttpServletResponse res) throws 
        System.out.println("Inside the doPost Method");
        String str=req.getParameter("txtName");
        req.setAttribute ("NAME",str);
        //getServletContext().getRequestDispatcher("/jsp/Results.jsp").forward(req, res);


      My Client class looks like::::

      class ClientTest{
      public static void main(String args[]){
      TestServletCase ts=new TestServletCase();

      My web.xml looks like:::
      <?xml version="1.0" encoding="UTF-8"?>
      <web-app id="WebApp_ID" version="2.4" xmlns=" http://java.sun.com/xml/ns/j2ee " xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance
" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <servlet-class> com.test.TestServlet</servlet-class>
        <welcome-file> default.html</welcome-file>

      I am getting the Null pointer Exception in doPost() method of TestServlet  class(Marked
in Red color).It says the incoming request is null.Could you please help me i am doing the
      Then how to invoke the actual test case?? if i will put System.out.println() in the
testSetUp(),begin() method , it is not executed. please help me resolve this one?

      Thank you
      Nagaraj P

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message