Hi I had an authentication service which works on Request (some Header-Data and Cookie), Response (to set or delete a cookie) and session (Store userId and rememberMe-inform
It's possible to do it similar to play1.x. The central point is the Context
. Furthermore you must create a DummyRequest
which implements the methods you need. Then it's possible to create the following
final Request request = new DummyRequest();
Context.current.set(new Context(request, new HashMap <String, String>(),
new HashMap <String, String>()));
in your test you can get Context.current().session()
, Context.current().response()
or Context.current().request()
.
You can see here an test-example.
It was not ready for Play 2.0, but in Play 2.1 (and in current master) you’ll be able to write:
fakeRequest(GET, "/foo")
.withSession("bar", "baz")
.withCookies(cookie("bah", "toto"));