How to manipulate Session, Request and Response for test in play2.0

后端 未结 2 691
一个人的身影
一个人的身影 2020-12-16 04:51

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

2条回答
  •  天涯浪人
    2020-12-16 05:13

    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 (), 
            new HashMap ()));
    

    in your test you can get Context.current().session(), Context.current().response() or Context.current().request().

    You can see here an test-example.

提交回复
热议问题