sandy
sandy

Reputation: 243

How do I setup FitNesse for use with struts based applications?

I basically need to call the execute() method of the Struts action class. Is this even possible. if yes how can i load the ActionMapping, ActionForm, HttpServletRequest and HttpServletResponse objects for the execute call.

Loading of the Spring Config:

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

Test trying to execute:

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

Upvotes: 0

Views: 221

Answers (1)

sandy
sandy

Reputation: 243

Finally solved the problem. I had to put all websphere jars for the JAXRPC to be initialized and also changed my code to the below. This has helped me in resolving the problem.

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

Now i want the experts to drop by and let me know if the standard i am using in a Fixture code is fine or if i need to follow a different approach.

Upvotes: 0

Related Questions