01: package servletunit.struts.tests.cactus;
02:
03: import servletunit.struts.CactusStrutsTestCase;
04: import org.apache.cactus.WebResponse;
05:
06: public class TestProcessResults extends CactusStrutsTestCase {
07:
08: public void testSuccessfulLogin() {
09: processRequest(true);
10: addRequestParameter("username", "deryl");
11: addRequestParameter("password", "radar");
12: setRequestPathInfo("/login");
13: actionPerform();
14: verifyForward("success");
15: verifyForwardPath("/main/success.jsp");
16: assertEquals("deryl", getSession().getAttribute(
17: "authentication"));
18: verifyNoActionErrors();
19: }
20:
21: public void endSuccessfulLogin(WebResponse response) {
22: assertEquals("unexpected response code", 200, response
23: .getStatusCode());
24: String[] text = response.getTextAsArray();
25: for (int i = 0; i < text.length; i++) {
26: String line = text[i];
27: if (line != null
28: && !line
29: .equals("<h2>You have successfully logged in!</h2>")
30: && !line
31: .equals("<a href=\"/test/login/login.jsp\">Go back</a>")
32: && !line.equals(""))
33: fail("unexpected text: " + line);
34:
35: }
36: }
37: }
|