Skip to content

Instantly share code, notes, and snippets.

@MoriTanosuke
Created October 5, 2010 09:58
Show Gist options
  • Save MoriTanosuke/611307 to your computer and use it in GitHub Desktop.
Save MoriTanosuke/611307 to your computer and use it in GitHub Desktop.
-Dcactus.contextURL=http://localhost:8080/test
-Dcactus.jetty.resourceDir=./WebContent
-Dcactus.jetty.config=./test/jetty.xml
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 StringReverseAction extends Action {
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
// reverse parameter 'value'
final String value = new StringBuilder(request.getParameter("value")).reverse().toString();
request.setAttribute("result", value.toString());
return mapping.findForward("success");
}
}
import junit.framework.Test;
import junit.framework.TestSuite;
import org.apache.cactus.ServletTestCase;
import org.apache.cactus.extension.jetty.Jetty6xTestSetup;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForward;
public class StringReverseActionTest extends ServletTestCase {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTestSuite(StringReverseActionTest.class);
return new Jetty6xTestSetup(suite);
}
public void testExecute() throws Exception {
Action action = new StringReverseAction();
ActionForward forward = action.execute(null, null, request, response);
assertNotNull(forward);
assertEquals("/success.jsp", forward.getPath());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment