01: package com.mockrunner.example.struts;
02:
03: import javax.servlet.http.HttpServletRequest;
04: import javax.servlet.http.HttpServletResponse;
05:
06: import org.apache.struts.action.Action;
07: import org.apache.struts.action.ActionForm;
08: import org.apache.struts.action.ActionForward;
09: import org.apache.struts.action.ActionMapping;
10:
11: /**
12: * This example action does the same as
13: * {@link com.mockrunner.example.servlet.LogoutServlet}.
14: * It is used to demonstrate the testing of actions with
15: * specified filters since {@link com.mockrunner.struts.ActionTestModule}
16: * does not provide any filter methods. Please note that usually it's not
17: * necessary to test actions in conjunction with filters. You can
18: * add the filtered values directly to the request.
19: * This action uses the custom action mapping {@link LogoutActionMapping}
20: * to get the request parameter name.
21: */
22: public class LogoutAction extends Action {
23: public ActionForward execute(ActionMapping mapping,
24: ActionForm form, HttpServletRequest request,
25: HttpServletResponse response) throws Exception {
26: LogoutActionMapping logoutMapping = (LogoutActionMapping) mapping;
27: String logout = request.getParameter(logoutMapping
28: .getRequestParameterName());
29: if (null != logout) {
30: request.getSession().invalidate();
31: request.getRequestDispatcher("/html/goodbye.html").forward(
32: request, response);
33: }
34: return mapping.findForward("success");
35: }
36: }
|