jakarta-cactus-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vincent Massol" <vmas...@pivolis.com>
Subject RE: Login once using (FormAuthentication) for all tests in a class
Date Thu, 08 Jan 2004 14:05:31 GMT
Matt,

> -----Original Message-----
> From: Matt Raible [mailto:matt@raibledesigns.com]
> Sent: 08 January 2004 14:21
> To: Cactus Users List
> Subject: Re: Login once using (FormAuthentication) for all tests in a
> class
> 
> > Thinking more about it, I'm not so sure that the solution is a
method
> > that is called only once... Each test must set its own fixture. So
you
> > should group test using the same fixture (i.e. user being logging
in)
> > in
> > the same TestCase class. Then simply use either begin() or even
better
> > setUp() (it has direct access to the session) to log the user in
before
> > *each* test.
> >
> 
> Ah ha - the begin() method is exactly what I was looking for.  Of
> course, I'd prefer to use setUp() because then my test looks more like
> JUnit than Cactus (making it easier to understand for those familiar
> with JUnit).  However, I'm unsure of how to get the WebRequest (in
> order to set authorization) in the setUp() method.

begin() is executed on the client side and setUp() on the server side.
Thus setup cannot have access to the WebRequest. However it has access
to the HttpServletRequest and other container objects.

> 
> I tried removing all my beginXX() methods and just using one begin()
> method and this worked great - thanks!
> 
> So the question is - is it possible to combine the following 2
methods?
> 
>      public void begin(WebRequest request) {
>          request.setRedirectorName("ServletRedirectorSecure");
>          request.setAuthentication(new FormAuthentication(
>                  login.getString("username"),
>                  login.getString("encryptedPassword")));
>      }
> 
>      public void setUp() throws Exception {
>          super.setUp();
> 
>          conn = ServiceLocator.getConnection();
>          // populate the userForm and place into session
>          String username = login.getString("username");
>          UserManager userMgr = new UserManagerImpl(conn);
>          userForm = (UserForm) userMgr.getUser(username);
>          session.setAttribute(Constants.USER_KEY, userForm);
>      }
> 

I don't think so. The begin method is used to connect to the server
side, whereas the setup is used to set up server side objects. They are
executed in different JVM (client and server side).

Thanks
-Vincent


Mime
View raw message