You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cactus-user@jakarta.apache.org by "White, Melissa" <mw...@triactive.com> on 2003/03/14 23:03:36 UTC

Simple test for my login JSP

I am trying to use Cactus to unit test our JSPs, but am having difficulty
getting a simple test to work. I have a test case defined as follows:

public class LoginWebTest extends ServletTestCase
{
  private static Cookie jsessionid = null;

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

  public static void main(String[] args)
  {
    junit.textui.TestRunner.run(suite());
  }

  public static Test suite()
  {
    final TestSuite suite = new TestSuite();
    suite.addTest(new LoginWebTest("testGetJsessionid"));
    suite.addTest(new LoginWebTest("testLogin"));
    return suite;
  }
  public void beginGetJsessionid(WebRequest webRequest)
  {
    webRequest.setURL("localhost:8101", "", "/portal/login.jsp", null,
null);
  }

  public void testGetJsessionid() {}

  public void endGetJsessionid(WebResponse webResponse)
  {
    Cookie c = webResponse.getCookieIgnoreCase("jsessionid");
    assertNotNull(c);
    this.jsessionid = c;
  }

  public void beginLogin(WebRequest webRequest)
  {
    webRequest.setURL("localhost:8101", "", "/portal/doLogin.jsp", null,
null);
    webRequest.addParameter("company", "mwhite");
    webRequest.addParameter("username", "admin");
    webRequest.addParameter("password", "adminpwd");
  }

  public void testLogin()
  {
    assertEquals("mwhite", request.getParameter("company"));
    SpecialistValue sv =
(SpecialistValue)session.getAttribute(SpecialistKeys.CURRENT);
    assertNotNull("SpecialistValue not found in session", sv);
  }
}

The assertNotNull in testLogin fails, but it is not clear to me that
doLogin.jsp is ever being reached. If it is, there should be some output in
my JRun log, but there is none. After doLogin.jsp is executed, I should be
able to retrieve the SpecialistValue object from the session. Am I missing
something?

I'm using JRun 3.1.  Any help would be greatly appreciated.

-- Melissa

Re: Simple test for my login JSP

Posted by Jason Arndt <ja...@yahoo.com>.
Have you LoginWebTest extend JspTestCase instead of
ServletTestCase.

--- "White, Melissa" <mw...@triactive.com> wrote:
> I am trying to use Cactus to unit test our JSPs, but
> am having difficulty
> getting a simple test to work. I have a test case
> defined as follows:
> 
> public class LoginWebTest extends ServletTestCase
> {
>   private static Cookie jsessionid = null;
> 
>   public LoginWebTest(String name)
>   {
>     super(name);
>   }
> 
>   public static void main(String[] args)
>   {
>     junit.textui.TestRunner.run(suite());
>   }
> 
>   public static Test suite()
>   {
>     final TestSuite suite = new TestSuite();
>     suite.addTest(new
> LoginWebTest("testGetJsessionid"));
>     suite.addTest(new LoginWebTest("testLogin"));
>     return suite;
>   }
>   public void beginGetJsessionid(WebRequest
> webRequest)
>   {
>     webRequest.setURL("localhost:8101", "",
> "/portal/login.jsp", null,
> null);
>   }
> 
>   public void testGetJsessionid() {}
> 
>   public void endGetJsessionid(WebResponse
> webResponse)
>   {
>     Cookie c =
> webResponse.getCookieIgnoreCase("jsessionid");
>     assertNotNull(c);
>     this.jsessionid = c;
>   }
> 
>   public void beginLogin(WebRequest webRequest)
>   {
>     webRequest.setURL("localhost:8101", "",
> "/portal/doLogin.jsp", null,
> null);
>     webRequest.addParameter("company", "mwhite");
>     webRequest.addParameter("username", "admin");
>     webRequest.addParameter("password", "adminpwd");
>   }
> 
>   public void testLogin()
>   {
>     assertEquals("mwhite",
> request.getParameter("company"));
>     SpecialistValue sv =
>
(SpecialistValue)session.getAttribute(SpecialistKeys.CURRENT);
>     assertNotNull("SpecialistValue not found in
> session", sv);
>   }
> }
> 
> The assertNotNull in testLogin fails, but it is not
> clear to me that
> doLogin.jsp is ever being reached. If it is, there
> should be some output in
> my JRun log, but there is none. After doLogin.jsp is
> executed, I should be
> able to retrieve the SpecialistValue object from the
> session. Am I missing
> something?
> 
> I'm using JRun 3.1.  Any help would be greatly
> appreciated.
> 
> -- Melissa
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail:
> cactus-user-help@jakarta.apache.org
> 


__________________________________________________
Do you Yahoo!?
Yahoo! Web Hosting - establish your business online
http://webhosting.yahoo.com