浏览 1988 次
锁定老帖子 主题:请教关于interceptor的测试方法
该帖已经被评为新手帖
|
|
---|---|
作者 | 正文 |
发表时间:2008-03-10
我想写关于拦截器的测试代码
以下是拦截器的代码 public String intercept(ActionInvocation actioninvocation) throws Exception { HttpServletRequest request=ServletActionContext.getRequest(); String username=request.getParameter("username"); String password=request.getParameter("password"); user=userdaoimpl.findByCredentials(username ,password); if(user==null){ System.out.println("user is null"); return Action.LOGIN; }else{ Action action=(Action)actioninvocation.getAction(); if(action instanceof UserAware){ ((UserAware)action).setUser(user); } } return actioninvocation.invoke(); } 以下是测试的代码 public void setUp()throws Exception{ actioninvocation=EasyMock.createMock(ActionInvocation.class); } public void testInterceptor() throws Exception{ MockControl mockcontrol=MockControl.createControl(HttpServletRequest.class); HttpServletRequest request=(HttpServletRequest)mockcontrol.getMock(); request.getParameter("username"); mockcontrol.setReturnValue("a", 1); request.getParameter("password"); mockcontrol.setReturnValue("a", 1); mockcontrol.replay(); InterceptorLogin interceptor=new InterceptorLogin(); assertEquals("Login failed.", interceptor.intercept(actioninvocation)); } 请问这样以上代码写有什么不妥 测试显示结果String username=request.getParameter("username");是空值 请问request.getParameter("username");的测试环境如何搭建? 谢谢 声明:ITeye文章版权属于作者,受法律保护。没有作者书面许可不得转载。
推荐链接
|
|
返回顶楼 | |