Thanks a lot for any guidance!
The SecureSocial plugin works fine when I run it from the browser, but I would like to be able to test the rest of my Play app now.
Here's how I solved this problem. I am simulating a login (kind of) by directly adding to the Authenticator that's in memory. That returns a cookie which I include in the fake request. I'm doing this with an implicit conversion for some syntactic sugar. You can easily extend it for your particular case. My application only uses the user/pass provider, but you should be able to extend to use the other plugins.
object TestUtils {
@inline implicit def loggedInFakeRequestWrapper[T](x: FakeRequest[T]) = new LoggedInFakeRequest(x)
final class LoggedInFakeRequest[T](val self: FakeRequest[T]) extends AnyVal {
def withLoggedInUser(id: Long) = {
val userToLogInAs:Identity = ??? //get this from your database using whatever you have in Global
val cookie = Authenticator.create(userToLogInAs) match {
case Right(authenticator) => authenticator.toCookie
}
self.withCookies(cookie)
}
}
}
And the spec:
"render the index page" in {
val home = route(FakeRequest(GET, "/").withLoggedInUser(1L)).get
status(home) must equalTo(OK)
//etc.
}