开发者

PUT method in playframework FunctionalTest

I wrote a little application using GAE and the playframework.

I am trying to test the PUT method (used for updates) and when called from a Functi开发者_如何学GoonalTest it always returns with the login page even though I login at the beginning of the test, that can be confirmed by all the other method working fine.

It looks like when using the PUT method the session is lost

Anybody had similar problems?

I'm using play 1.1.1


It looks like there is a bug in FunctionalTest. In all the methods (POST, GET, DELETE) there is the following line that carries over the cookies

if (savedCookies != null) request.cookies = savedCookies;

This line is missing in PUT. Also because savedCookies is private you can't access it in your tests.

The work around is to define the cookies map in your test as a private variable, set it to the login response cookies and then call POST with a new request using this cookies.

Here is my code

private static Map<String, Http.Cookie> lastCookies;

public void login(){
    String postUrl = Router.reverse("GAEActions.doLogin").url;
    Map<String, String> map = Maps.newHashMap();
    map.put("email", "as@gmail.com");
    map.put("url", "/");
    map.put("isAdmin", "true");
    Map<String, File> fileMap = Maps.newHashMap();
    Response post = POST(postUrl, map, fileMap);
    lastCookies = post.cookies;
}
public void test(){
....
    Request request = newRequest();
    request.cookies = lastCookies;
    Response post = PUT(request, url,"application/json",json);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜