【问题标题】:How do I setup FitNesse for use with struts based applications?如何设置 FitNesse 以用于基于 struts 的应用程序?
【发布时间】:2013-02-27 11:32:35
【问题描述】:

我基本上需要调用Struts动作类的execute()方法。这甚至可能吗。如果是,我如何加载 ActionMapping、ActionForm、HttpServletRequest 和 HttpServletResponse 对象以进行执行调用。

加载 Spring Config:

public class SpringColumnFixture extends ColumnFixture { 
    private static final ApplicationContext appContext = 
         new GenericXmlApplicationContext(new String[]{"classpath:spring/*.xml"});
}

尝试执行的测试:

ActionForm form = new IncidentDetailsForm(); 
ActionMapping mapping = new ActionMapping();
HttpServletResponse response = new MockHttpServletResponse(); 

MockHttpServletRequest request = new MockHttpServletRequest() { 
   @Override public String getMethod() { 
       return "GET"; }
}; 

request.setAttribute("userName","****"); 
request.setParameter("userName","****"); 
forward = appContext.getBean(AppLandingAction.class).execute(mapping, form, request, response);

【问题讨论】:

  • 我能够以某种方式将所有需要的 spring 配置放到类路径中,并从我现有的 pom.xml 中调用 Fitnesse 进程作为任务。我加载了所有的 xml 文件。我还尝试创建请求、响应、actionMapping 和 actionform(都是虚拟的)。我什至在请求中设置了一些参数,但是在调用之后设置的参数在请求中不可用。我总是收到一个空请求。谁能帮我解决这个问题。
  • 你能发布你的代码吗?
  • @ekims - 感谢您编辑问题。忘记了那个功能。你能告诉我我在做什么错吗,因为我总是收到一个空请求,有时甚至是 MockHttpServletRequest 的 classNotFoundException,尽管 jar 存在于类路径中。
  • 我加载了请求和响应参数,但无法初始化我的 JAXRPC。我总是收到说明“创建 JAXRPC 服务接口时出错:null”的消息。欢迎任何帮助。同时,我也会及时发布我的更新。

标签: struts automated-tests integration-testing fitnesse


【解决方案1】:

终于解决了问题。我必须将所有 websphere jar 放入 JAXRPC 进行初始化,并将我的代码更改为以下内容。这有助于我解决问题。

ActionForm form = new ActionForm() {};

        In******Form form1 = new In******Form();
        form1.setActionType("View");

        ActionMapping mapping = new ActionMapping();
        mapping.addForwardConfig(new ActionForward("success","/action/viewCeraHome", false));
        mapping.addForwardConfig(new ActionForward("noLogin","/loginError.jsp", false));

        HttpServletResponse response = new MockHttpServletResponse();
        MockHttpServletRequest request = new MockHttpServletRequest(){
            @Override
            public String getMethod() {
                return "GET"; 
            }

            @Override
            public HttpSession getSession(boolean create) {
                return super.getSession(true);
            }

        };

        request.setAttribute("userName","*****");
        request.setParameter("userName","*****");

        //forward = appContext.getBean(Ap*****Action.class).execute(mapping, form, request, response);
        appContext.getBean(Ap*****Action.class).execute(mapping, form, request, response);
        forward = appContext.getBean(Inc******Action.class).execute(mapping, (ActionForm)form1, request, response);

现在我希望专家过来让我知道我在 Fixture 代码中使用的标准是否合适,或者我是否需要采用不同的方法。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-02-15
    • 1970-01-01
    • 1970-01-01
    • 2013-08-26
    • 2017-08-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多