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.

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: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to