Created
June 10, 2009 19:25
-
-
Save arockwell/127436 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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