Thanks for the tip Greg. I quickly went through the debugger based on the example here: http://depressedprogrammer.wordpress.com/2007/06/18/unit-testing-struts-2-actions-spring-junit/

and I learned two things.

1. execute() does call getSettings(). All that CRUD nonsense was me not being sure it was actually calling the method I wanted because it threw an exception upon execution.

2. It looks like adding the following to the createAction(..) method fixed my first problem. I had an interceptor putting a variable on the session, but no session was set, triggering a NullPointerException.

proxy.getInvocation().getInvocationContext().setSession(new HashMap());

Now I'm just running into a problem where the TilesAccess.getContainer(servletContext) is returning a null. This is in the org.apache.struts2.views.tiles.TilesResult class.

public void doExecute(String location, ActionInvocation invocation) throws Exception {
       setLocation(location);

ServletContext servletContext = ServletActionContext.getServletContext();
       TilesContainer container = TilesAccess.getContainer(servletContext);

       HttpServletRequest request = ServletActionContext.getRequest();
       HttpServletResponse response = ServletActionContext.getResponse();

// fails because the container is null
       container.render(location, request, response);
   }

I will post my final results when I get that part figured out. If someone can offer a tip, I'd appreciate it. I'm learning as I go here.

Tim


Greg Lindholm wrote:
You can take a look at this:

http://glindholm.wordpress.com/2008/06/30/unit-testing-struts-2-actions/

I've used it to unit test actions all the way through interceptors,
validation, actions, and results including freemarker result types.


Timothy Astle wrote:
I had tried using proxy.execute(), which will use Struts. Maybe that's where I'm a bit lost. I don't implement execute() because of my CRUD approach.

Can someone point me to some appropriate struts 2 junit tests so I can figure this out?




Reply via email to