0
我想知道請求傳遞給方法並拉動HttpSession?EasyMock - HttpSession設置會話 - 方法通過請求傳遞
從JUnit的經過:
@Test
public void testSessionPass(){
HttpServletRequest request = createMock(HttpServletRequest.class);
HttpSession session = createMock(HttpSession.class);
expect(session.getAttribute("testAttribute")).andReturn("testValue").anyTimes();
replay(request);
replay(session);
CAction cAction = new CAction();
cAction.test(request);
}
在CAction:
public void test (HttpServletRequest request){
HttpSession session = request.getSession();
if(session.getAttribute("testAttribute")!=null){
System.out.println((String)session.getAttribute("testAttribute"));
}
}
UPDATE:
爲什麼我失去從線HttpSession的會議傳遞的請求值會話= request.getSession(); ??
什麼是你的問題? – dkatzel
當我傳遞請求參數時,我失去了testAttribute的會話值。它實際上在HttpSession session = request.getSession()上死亡;線。 – ogottwald