在web工程中 是从request里获得session 然后在从session里得到值
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
// session取得
HttpSession session = request.getSession();
//
if (!LoginCheck.isLogin(session)) {
return (mapping.findForward(MAPPING_FINDFORWARD_TIMEOUT));
}
// code
String brandCode = (String) session
.getAttribute(Const.SESSION_KEY_BRAND_CD);
请问在junit 里怎么写呢?我在网上看的是都往request里放值
可是session里有很多值 怎么把session值放入request里
我的junit 代码如下
public class ReferStrgSituationLogicTest extends MockStrutsTestCase{
@Test
public void testExecSearch() {
//ReferStrgSituationSearchForm from = null ;
//from.setClaimCd("1000000001");
//HttpClient cl;
//HttpServletRequest request;
setRequestPathInfo("/ReferStrgSituationSearchServlet");
//setActionForm(from);
//addRequestParameter("searchInfo", from);
// Map fef = new HashMap();
// fef.put("brandCd", "TEST1");
// fef.put("loginId", "admin00001");
// fef.put("pageFlg", "search");
// addRequestParameter("session", fef);
// addRequestParameter("brandCd", "TEST1");
// addRequestParameter("pageFlg", "search");
actionPerform();
verifyForward("fail");
}
各位大侠帮帮 怎么修改junit 代码
------解决方案--------------------
request = createStrictMock(HttpServletRequest.class);
session = createStrictMock(HttpSession.class);
expect(request.getSession()).andStubReturn(session);
expect(session.getAttribute("name")).andReturn("xxxx");