我想在junit测试中创建一个假会话,但我不能......
我有一些方法可以保护@With以保护每个方法,访问受@With保护的方法的值在会话中,
在会话上,如果" member_running = 1"和 " project_running = 1"函数addBacklog工作,http状态为200,ifelse http状态为401(Unauthorized)
在这个例子上我想创建一个会话测试
@Test
public void testSession() {
running(fakeApplication(), new Runnable() {
public void run() {
session.put("member_running","1");
session.put("project_running","1");
Result res = route(fakeRequest("GET", "/")
.method("POST")
//.session("member_running","1")
//.session("project_running","1")
.session(session)
.uri(routes.ProductBacklogController.addBacklog("MyName","MyPriority","MyFirstEstimate","MyDescription").url()));
assertEquals("This is not the page addBacklog","/projectus/backlog/add/MyName/MyPriority/MyFirstEstimate/MyDescription", request.uri());
assertEquals("The page should be work", 200, res.status());
}
});
}
在我的研究中,我找到了方法.withSession(" key"," value")并且他没有工作,我试图用只是.session("键,"值)(如上面的例子)
现在我尝试使用res的se会话:
res.session();
但它返回:{}
并且
res.status();
返回:401 因为没有使用会话。
会话包含:
{connected=true, lastName=Crenn, firstName=Thomas, nav=open, member_running=1, project=[{"project":"ProjectUS","project_id":1,"members":[{"member":"DEVELOPER","member_id":2},{"member":"ADMINISTRATOR","member_id":3},{"member":"PRODUCT_OWNER","member_id":4},{"member":"SCRUM_MASTER","member_id":5}]},{"project":"ScrumBadass","project_id":2,"members":[{"member":"SCRUM_MASTER","member_id":9},{"member":"DEVELOPER","member_id":10}]}], cip=2, project_running=1}
有关信息,播放框架的版本是2.5