jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Ronnie" <lormee2...@yahoo.com.sg>
Subject Re: WebRequest Disappears?
Date Sun, 06 Apr 2003 07:41:55 GMT
Hi all,

I've just noticed my error. The beginXXX() method for my second test was beginTestLogin()
and not beginLogin().

This is what a flu bug can do to you if you do not rest!


Regards,
Ronnie
  ----- Original Message ----- 
  From: Ronnie 
  To: Cactus Users List 
  Sent: Sunday, 06 April, 2003 2:07 PM
  Subject: Re: WebRequest Disappears?


  The setUp is called before every testXXX() right? But the beginXXX() is called only when
starting the XXX test case. So I thought putting the request initialisation parameters relevant
to the test case in the beginXXX() would be the correct way to do it.

  And it worked for my first test case why shouldn't it work for my second test case in the
same class?
  I'm really stumped by this...

  Here's my entire test class, everything works in testAddCustomer() but the testLogin() has
all null values for "request.getParameter("")" and "config.getInitParameter("")"

    public class TestDispatcher1 extends ServletTestCase {

       public TestDispatcher1(String name){
          super(name);
       }

       public void setUp() throws Exception {
          jndiName = "ass2DB";
          addAccount(CUSTOMER2_FIRSTNAME, CUSTOMER2_LASTNAME, CUSTOMER2_ADDRESS,
                     CUSTOMER2_USERNAME, CUSTOMER2_PASSWORD, CUSTOMER2_EMAIL);

       }//setUp()

       public void tearDown() throws Exception {
          deleteAccounts();
          session.invalidate();
       }//tearDown()

       /**
        * Set up parameters to be used in testAddCustomer()
        */
       public void beginAddCustomer(WebRequest request) throws Exception {
          request.addParameter("firstName", CUSTOMER1_FIRSTNAME);
          request.addParameter("lastName", CUSTOMER1_LASTNAME);
          request.addParameter("address", CUSTOMER1_ADDRESS);
          request.addParameter("userName", CUSTOMER1_USERNAME);
          request.addParameter("password", CUSTOMER1_PASSWORD);
          request.addParameter("email", CUSTOMER1_EMAIL);
          request.addParameter("action","newAccount2");
       }
       /**
        * Test 1
        *
        * Test adding of customer
        *
        */
       public void testAddCustomer() throws Exception{
          DispatcherServlet dispatcher = new DispatcherServlet();

          dispatcher.init(config);
          dispatcher.doPost(request, response);

          //Check if the customer is added
          findUser(CUSTOMER1_USERNAME);
          if(list!=null){
             Iterator it = list.iterator();
             AccountDetails acc = (AccountDetails)it.next();
             assertEquals("Customer first name wrong",
                          CUSTOMER1_FIRSTNAME,
                          acc.getFirstName());
             assertEquals("Customer last name wrong",
                          CUSTOMER1_LASTNAME,
                          acc.getLastName());
             assertEquals("Customer address wrong",
                          CUSTOMER1_ADDRESS,
                          acc.getAddress());
          } else {
             fail("Account not added!");
          }
       }//testAddCustomer()

       public void endAddCustomer(WebResponse response) throws Exception {

       }

        /**
        * Set up parameters to be used in testLogin()
        */
       public void beginTestLogin(WebRequest request) throws Exception {
          request.addParameter("userName", CUSTOMER2_USERNAME);
          request.addParameter("password", CUSTOMER2_PASSWORD);
          request.addParameter("action", "login1");
       }//beginTestLogin()

      
       public void testLogin() throws Exception {

          System.out.println("User Name: "+request.getParameter("userName"));
          System.out.println("Password: "+request.getParameter("password"));
          System.out.println("Action: "+request.getParameter("action"));
          System.out.println("login1: "+config.getInitParameter("login1"));

       }//testLogin()

       public void endTestLogin(WebResponse response) throws Exception {

       }
  Regards,
  Ronnie
    ----- Original Message ----- 
    From: Martin 
    To: Cactus Users List 
    Sent: Sunday, 06 April, 2003 1:40 PM
    Subject: Re: WebRequest Disappears?


    Ok-
    setUp is like init as it is called only once before the Test case is executed
    In fact if your initialisation code was moved from setUp to the constructor the initialasation
code would be executed on every invocation
    leaving the setUp to handle just the setup for the test case.
    Hth,
    Martin



Mime
View raw message