Skip to content

Instantly share code, notes, and snippets.

@arockwell
Created June 10, 2009 19:25
Show Gist options
  • Select an option

  • Save arockwell/127436 to your computer and use it in GitHub Desktop.

Select an option

Save arockwell/127436 to your computer and use it in GitHub Desktop.
package edu.ufl.housing.contract.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
public class FooAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)throws Exception {
String attribute = (String) request.getSession().getAttribute("bar");
assert(attribute == "bar");
return mapping.findForward("test");
}
}
package edu.ufl.housing.contract.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.config.ForwardConfig;
import servletunit.HttpServletRequestSimulator;
import junit.framework.TestCase;
public class TestFooAction extends TestCase {
public void testExecute() throws Exception {
Action fooAction = new FooAction();
ActionMapping mapping = new ActionMapping();
ForwardConfig config = new ActionForward();
config.setName("test");
HttpServletRequest request = new HttpServletRequestSimulator(null);
HttpSession session = request.getSession();
session.setAttribute("bar", "bar");
mapping.addForwardConfig(config);
ActionForward result = fooAction.execute(mapping, null, request, null);
assertEquals("test", result.getName());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment