01: // StrutsTestCase - a JUnit extension for testing Struts actions
02: // within the context of the ActionServlet.
03: // Copyright (C) 2002 Deryl Seale
04: //
05: // This library is free software; you can redistribute it and/or
06: // modify it under the terms of the Apache Software License as
07: // published by the Apache Software Foundation; either version 1.1
08: // of the License, or (at your option) any later version.
09: //
10: // This library is distributed in the hope that it will be useful,
11: // but WITHOUT ANY WARRANTY; without even the implied warranty of
12: // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13: // Apache Software Foundation Licens for more details.
14: // test
15: // You may view the full text here: http://www.apache.org/LICENSE.txt
16:
17: package servletunit.struts.tests.cactus;
18:
19: import servletunit.struts.CactusStrutsTestCase;
20: import junit.framework.AssertionFailedError;
21:
22: public class TestMessageAction extends CactusStrutsTestCase {
23:
24: public TestMessageAction(String testName) {
25: super (testName);
26: }
27:
28: public void testNoMessages() {
29: addRequestParameter("username", "deryl");
30: addRequestParameter("password", "radar");
31: setRequestPathInfo("/login");
32: actionPerform();
33: verifyForward("success");
34: verifyForwardPath("/main/success.jsp");
35: assertEquals("deryl", getSession().getAttribute(
36: "authentication"));
37: verifyNoActionMessages();
38: }
39:
40: public void testMessageExists() {
41: setRequestPathInfo("test", "/testActionMessages");
42: actionPerform();
43: verifyForward("success");
44: verifyActionMessages(new String[] { "test.message" });
45: }
46:
47: public void testMessageExistsExpectedNone() {
48: setRequestPathInfo("test", "/testActionMessages");
49: actionPerform();
50: verifyForward("success");
51: try {
52: verifyNoActionMessages();
53: } catch (AssertionFailedError afe) {
54: return;
55: }
56: fail("Expected an AssertionFailedError!");
57: }
58:
59: public void testMessageMismatch() {
60: setRequestPathInfo("test", "/testActionMessages");
61: actionPerform();
62: verifyForward("success");
63: try {
64: verifyActionMessages(new String[] { "error.password.mismatch" });
65: } catch (AssertionFailedError afe) {
66: return;
67: }
68: fail("Expected an AssertionFailedError!");
69: }
70:
71: public void testExpectedMessagesNoneExist() {
72: addRequestParameter("username", "deryl");
73: addRequestParameter("password", "radar");
74: setRequestPathInfo("/login");
75: actionPerform();
76: verifyForward("success");
77: verifyForwardPath("/main/success.jsp");
78: assertEquals("deryl", getSession().getAttribute(
79: "authentication"));
80: try {
81: verifyActionMessages(new String[] { "test.message" });
82: } catch (AssertionFailedError afe) {
83: return;
84: }
85: fail("Expected AssertionFailedError!");
86: }
87:
88: public static void main(String[] args) {
89: junit.textui.TestRunner.run(TestMessageAction.class);
90: }
91:
92: }
|