论坛首页 Java企业应用论坛

请教一个关于webwork测试的问题

浏览 5094 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2004-11-02  
在测试webwork中的Action时
可以使用
Map params = new HashMap();;
params.put(String, String);;
......
Map extraContext = new HashMap();;
extraContext.put(ActionContext.PARAMETERS,params);;


的方法来模拟request中提交的参数
我想问的是如何模拟HttpSession中的数据呢
我使用
extraContext.put("session",Object);;

以及
extraContext.put(ActionContext.SESSION,Object);;

这两种方法都不行
还请各位给以解答
   发表时间:2004-11-02  
楼主说的是不是这个
ActionContext ctx = ActionContext.getContext();;
Map session = ctx.getSession();;
0 请登录后投票
   发表时间:2004-11-02  
我想也许你用webwork用得有点问题,要模拟提交的参数是不需要动用actioncontext的,直接从action的setter放进去就行了。不妨参考moxie写的webwork教程。
0 请登录后投票
   发表时间:2004-11-02  
应该这样:

Map session = new HashMap();;
session.put("foo", "bar");;
extraContext.put(ActionContext.SESSION, session);;
0 请登录后投票
   发表时间:2004-11-03  
Readonly 写道
应该这样:

Map session = new HashMap();;
session.put("foo", "bar");;
extraContext.put(ActionContext.SESSION, session);;


我就是这样做的呀,代码如下:
Map session = new HashMap();;
UserInf user = new User("aaa");;
session.put("USER",user);;
Map extraContext = new HashMap();;
extraContext.put(ActionContext.SESSION, session);;


是不是我获得session的代码有问题呢?
代码如下:
HttpSession session = ServletActionContext.getRequest();.getSession();;
session.getAttribute("USER");;

是不是这样写就造成了ServletActionContext.getRequest()时取得的是一个空值呢
请问
ServletActionContext.getRequest();.getSession();;


Map session = ActionContext.getContext();.getSession();;

两个方法或得的session,除了对象类型不同之外,其内容是否相同呢
0 请登录后投票
   发表时间:2004-11-03  
ServletActionContext?? 偶从来没有用过......

偶的unit test向来是用:
Map session = ActionContext.getContext().getSession();

WebWork已经帮你隔离了servlet容器一堆恶心的东西了, 你还捣鼓ServletActionContext干啥呀??
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics