0

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

加载 Spring 配置:

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);
4

1 回答 1

0

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

ActionForm 表单 = 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);

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

于 2013-03-28T10:54:43.890 回答