KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > servletunit > struts > tests > cactus > TestMessageAction


1 // StrutsTestCase - a JUnit extension for testing Struts actions
2
// within the context of the ActionServlet.
3
// Copyright (C) 2002 Deryl Seale
4
//
5
// This library is free software; you can redistribute it and/or
6
// modify it under the terms of the Apache Software License as
7
// published by the Apache Software Foundation; either version 1.1
8
// of the License, or (at your option) any later version.
9
//
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 JavaDoc 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("authentication"));
36         verifyNoActionMessages();
37     }
38
39     public void testMessageExists() {
40         setRequestPathInfo("test","/testActionMessages");
41         actionPerform();
42         verifyForward("success");
43         verifyActionMessages(new String JavaDoc[] {"test.message"});
44     }
45
46     public void testMessageExistsExpectedNone() {
47         setRequestPathInfo("test","/testActionMessages");
48         actionPerform();
49         verifyForward("success");
50         try {
51             verifyNoActionMessages();
52         } catch (AssertionFailedError afe) {
53             return;
54         }
55         fail("Expected an AssertionFailedError!");
56     }
57
58     public void testMessageMismatch() {
59         setRequestPathInfo("test","/testActionMessages");
60         actionPerform();
61         verifyForward("success");
62         try {
63             verifyActionMessages(new String JavaDoc[] {"error.password.mismatch"});
64         } catch (AssertionFailedError afe) {
65             return;
66         }
67         fail("Expected an AssertionFailedError!");
68     }
69
70     public void testExpectedMessagesNoneExist() {
71         addRequestParameter("username","deryl");
72         addRequestParameter("password","radar");
73         setRequestPathInfo("/login");
74         actionPerform();
75         verifyForward("success");
76         verifyForwardPath("/main/success.jsp");
77         assertEquals("deryl",getSession().getAttribute("authentication"));
78         try {
79         verifyActionMessages(new String JavaDoc[] {"test.message"});
80         } catch (AssertionFailedError afe) {
81             return;
82         }
83         fail("Expected AssertionFailedError!");
84     }
85
86     public static void main(String JavaDoc[] args) {
87         junit.textui.TestRunner.run(TestMessageAction.class);
88     }
89
90
91 }
92
93
Popular Tags