Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
393 views
in Technique[技术] by (71.8m points)

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

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-information).

In play 1.x it was easy to fake Request, Response, Cookie and Session. It could be easily set with Session.current().set(new Session()). In play 2.0 this doesn't work anymore.

How can I add a cookie to a request? How could I manipulate the session? I saw there exists FakeApplication and FakeRequest but I didn't get it, how to work with them.

Any hint is appreciated.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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"));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...