1
votes

I'm testing my Java/GWT/GAE based servlets. One of my servlets accesses the datastore (CRUD type methods) that would normally be called from the client over RPC.

The flow works like this: I launch testServlet1. If I'm not logged in, it generates the login url and returns this to the user. I click it. (now I'm logged in.)

testServlet1 runs, testing my DAO, and verifies the final database state.

testServlet2 now wants to add objects to the datastore using a different logged in user to ensure that there is no interference between user1 and user2.

My question is: how can I programmatically 'switch' logged in users from within a servlet without manually clicking the logout/login links, or automating this on the client side?

There doesn't seem to be an api for this.

Anyone doing this?

Thanks Rob

2
What're using for integration testing? Selenium? isn't it starts an new clean session for every test?Igor Artamonov
No, I'm not using Selenium. I am simply calling my servlets from other servlets that I write. The login is handled by the normal GAE federated login servlets. You generate login and logout urls and the user accesses them to log in and log out. In the end, I simply call these urls from my servlet when I need to continue a test as different user.Rob Mitchell

2 Answers

1
votes

Every request should do its own authentication. You can achieve this nicely with filters. Basically, they intercept every request and can do arbitrary computation before passing the request along to the eventually-intended servlet. You could make a filter say "if the user is not logged in, return login screen; else, go to the servlet as intended, with the logged in user as a parameter."

1
votes

Given that there does not seem to be an api specifically for this, I simply invoke the login and logout urls gae provides directly from my servlet.