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 08:55:07 GMT


> -----Original Message-----
> From: Matt Raible [mailto:matt@raibledesigns.com]
> Sent: 08 January 2004 01:48
> To: Cactus Users List
> Subject: Re: Login once using (FormAuthentication) for all tests in a
> class
> 
> A visual might be better.  In my BaseStrutsTestCase class I have a
> login method that is designed so all subclasses can use it.
> 
> 
>      public void login(WebRequest request) {
>          request.setRedirectorName("ServletRedirectorSecure");
>          request.setAuthentication(new FormAuthentication(
>                  login.getString("username"),
>                  login.getString("encryptedPassword")));
>      }
> 
> And in my ContactActionTest, I have to login for each method - below
is
> a trimmed down version of all my begin/test methods:
> 
>      public void beginEdit(WebRequest wr) { login(wr); }
> 
>      public void testEdit() throws Exception {
>          ...
>      }
> 
>      public void beginSave(WebRequest wr) { login(wr); }
> 
>      public void testSave() throws Exception {
>          ...
>      }
> 
>      public void beginSearch(WebRequest wr) { login(wr); }
> 
>      public void testSearch() throws Exception {
>          ...
>      }
> 
>      public void beginDisplayContactsForPosition(WebRequest wr) {
> login(wr); }
> 
>      public void testDisplayContactsForPosition() throws Exception {
>          ...
>      }
> 
>      public void beginPostJobs(WebRequest wr) { login(wr); }
> 
>      public void testPostJobs() throws Exception {
> 	...
>      }
> 
>      public void beginRemove(WebRequest wr) { login(wr); }
> 
>      public void testRemove() throws Exception {
> 	....
>      }
> 
> I'd like to get rid of all the beginXX methods, or a confirmation that
> this is the easiest way to do this.

Why not use the global begin(WebRequest) method (or setUp() on the
server side)?

Thanks
-Vincent

> 
> Thanks,
> 
> Matt
> 
> On Jan 7, 2004, at 5:21 PM, Matt Raible wrote:
> 
> > Quick and dirty question:
> >
> > Is it possible to login once (using FormAuthentication) for a class,
> > rather than adding a beginXXTestName befor every testXXTestName
> > method?
> >
> > Longer explanation:
> >
> > I have a number of tests in my ContactActionTest - this test extends
> > CactusStrutsTestCase, which extends ServletTestCase - nothing is
> > really Struts specific in this scenario.
> >
> > In order to simulate logging in, I've simply retrieved a user object
> > in by setUp() method and stuffed it into the session - this seems to
> > simulate a login good enough.  However, today, I started logging
down
> > my Actions/Servlets with roles.  So now this doesn't work - do I
have
> > to have a beginXX before each testXX that logs the user in (with
> > FormAuthentication)?
> >
> > Thanks,
> >
> > Matt
> >
> >
> >
> >
> >
> >
> >
---------------------------------------------------------------------
> > To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: cactus-user-help@jakarta.apache.org
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: cactus-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: cactus-user-help@jakarta.apache.org



Mime
View raw message