2
* $Header: /home/cvs/jakarta-struts/src/test/org/apache/struts/action/TestActionMessages.java,v 1.7 2004/03/14 06:23:51 sraeburn Exp $
4
* $Date: 2004/03/14 06:23:51 $
6
* Copyright 1999-2004 The Apache Software Foundation.
8
* Licensed under the Apache License, Version 2.0 (the "License");
9
* you may not use this file except in compliance with the License.
10
* You may obtain a copy of the License at
12
* http://www.apache.org/licenses/LICENSE-2.0
14
* Unless required by applicable law or agreed to in writing, software
15
* distributed under the License is distributed on an "AS IS" BASIS,
16
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
* See the License for the specific language governing permissions and
18
* limitations under the License.
21
package org.apache.struts.action;
23
import java.util.Iterator;
25
import junit.framework.Test;
26
import junit.framework.TestCase;
27
import junit.framework.TestSuite;
30
* Unit tests for the <code>org.apache.struts.action.ActionMessages</code> class.
32
* @version $Revision: 1.7 $ $Date: 2004/03/14 06:23:51 $
35
public class TestActionMessages extends TestCase {
36
protected ActionMessages aMsgs = null;
37
protected ActionMessages anMsgs = null;
38
protected ActionMessage msg1 = null;
39
protected ActionMessage msg2 = null;
40
protected ActionMessage msg3 = null;
41
protected ActionMessage msg4 = null;
42
protected ActionMessage msg5 = null;
45
* Defines the testcase name for JUnit.
47
* @param theName the testcase's name.
49
public TestActionMessages(String theName) {
56
* @param theArgs the arguments. Not used
58
public static void main(String[] theArgs) {
59
junit.awtui.TestRunner.main(new String[] { TestActionMessages.class.getName()});
63
* @return a test suite (<code>TestSuite</code>) that includes all methods
64
* starting with "test"
66
public static Test suite() {
67
// All methods starting with "test" will be executed in the test suite.
68
return new TestSuite(TestActionMessages.class);
72
aMsgs = new ActionMessages();
73
anMsgs = new ActionMessages();
74
Object[] objs1 = new Object[] { "a", "b", "c", "d", "e" };
75
Object[] objs2 = new Object[] { "f", "g", "h", "i", "j" };
76
msg1 = new ActionMessage("aMessage", objs1);
77
msg2 = new ActionMessage("anMessage", objs2);
78
msg3 = new ActionMessage("msg3", "value1");
79
msg4 = new ActionMessage("msg4", "value2");
80
msg5 = new ActionMessage("msg5", "value3", "value4");
83
public void tearDown() {
87
public void testEmpty() {
88
assertTrue("aMsgs is not empty!", aMsgs.isEmpty());
91
public void testNotEmpty() {
92
aMsgs.add("myProp", msg1);
93
assertTrue("aMsgs is empty!", aMsgs.isEmpty() == false);
96
public void testSizeWithOneProperty() {
97
aMsgs.add("myProp", msg1);
98
aMsgs.add("myProp", msg2);
99
assertTrue("number of mesages is not 2", aMsgs.size("myProp") == 2);
102
public void testSizeWithManyProperties() {
103
aMsgs.add("myProp1", msg1);
104
aMsgs.add("myProp2", msg2);
105
aMsgs.add("myProp3", msg3);
106
aMsgs.add("myProp3", msg4);
107
aMsgs.add("myProp4", msg5);
108
assertTrue("number of messages for myProp1 is not 1", aMsgs.size("myProp1") == 1);
109
assertTrue("number of messages", aMsgs.size() == 5);
112
public void testSizeAndEmptyAfterClear() {
113
testSizeWithOneProperty();
116
assertTrue("number of meesages is not 0", aMsgs.size("myProp") == 0);
119
public void testGetWithNoProperty() {
120
Iterator it = aMsgs.get("myProp");
121
assertTrue("iterator is not empty!", it.hasNext() == false);
124
public void testGetForAProperty() {
125
testSizeWithOneProperty();
126
Iterator it = aMsgs.get("myProp");
127
assertTrue("iterator is empty!", it.hasNext() == true);
131
* Tests adding an ActionMessages object to an ActionMessages object.
133
public void testAddMessages() {
134
ActionMessage msg1 = new ActionMessage("key");
135
ActionMessage msg2 = new ActionMessage("key2");
136
ActionMessage msg3 = new ActionMessage("key3");
137
ActionMessages msgs = new ActionMessages();
138
ActionMessages add = new ActionMessages();
140
msgs.add("prop1", msg1);
141
add.add("prop1", msg2);
142
add.add("prop3", msg3);
145
assertTrue(msgs.size() == 3);
146
assertTrue(msgs.size("prop1") == 2);
148
// test message order
149
Iterator props = msgs.get();
151
while (props.hasNext()) {
152
ActionMessage msg = (ActionMessage) props.next();
154
assertTrue(msg.getKey().equals("key"));
155
} else if (count == 2) {
156
assertTrue(msg.getKey().equals("key2"));
158
assertTrue(msg.getKey().equals("key3"));