~ubuntu-branches/ubuntu/trusty/libstruts1.2-java/trusty-proposed

« back to all changes in this revision

Viewing changes to src/test/org/apache/struts/action/TestActionMessages.java

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Vandyck
  • Date: 2004-11-19 15:35:25 UTC
  • Revision ID: james.westby@ubuntu.com-20041119153525-mdu08a76z4zo67xt
Tags: upstream-1.2.4
ImportĀ upstreamĀ versionĀ 1.2.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
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 $
 
3
 * $Revision: 1.7 $
 
4
 * $Date: 2004/03/14 06:23:51 $
 
5
 *
 
6
 * Copyright 1999-2004 The Apache Software Foundation.
 
7
 * 
 
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
 
11
 * 
 
12
 *      http://www.apache.org/licenses/LICENSE-2.0
 
13
 * 
 
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.
 
19
 */
 
20
 
 
21
package org.apache.struts.action;
 
22
 
 
23
import java.util.Iterator;
 
24
 
 
25
import junit.framework.Test;
 
26
import junit.framework.TestCase;
 
27
import junit.framework.TestSuite;
 
28
 
 
29
/**
 
30
 * Unit tests for the <code>org.apache.struts.action.ActionMessages</code> class.
 
31
 *
 
32
 * @version $Revision: 1.7 $ $Date: 2004/03/14 06:23:51 $
 
33
 */
 
34
 
 
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;
 
43
 
 
44
        /**
 
45
         * Defines the testcase name for JUnit.
 
46
         *
 
47
         * @param theName the testcase's name.
 
48
         */
 
49
        public TestActionMessages(String theName) {
 
50
                super(theName);
 
51
        }
 
52
 
 
53
        /**
 
54
         * Start the tests.
 
55
         *
 
56
         * @param theArgs the arguments. Not used
 
57
         */
 
58
        public static void main(String[] theArgs) {
 
59
                junit.awtui.TestRunner.main(new String[] { TestActionMessages.class.getName()});
 
60
        }
 
61
 
 
62
        /**
 
63
         * @return a test suite (<code>TestSuite</code>) that includes all methods
 
64
         *         starting with "test"
 
65
         */
 
66
        public static Test suite() {
 
67
                // All methods starting with "test" will be executed in the test suite.
 
68
                return new TestSuite(TestActionMessages.class);
 
69
        }
 
70
 
 
71
        public void setUp() {
 
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");
 
81
        }
 
82
 
 
83
        public void tearDown() {
 
84
                aMsgs = null;
 
85
        }
 
86
 
 
87
        public void testEmpty() {
 
88
                assertTrue("aMsgs is not empty!", aMsgs.isEmpty());
 
89
        }
 
90
 
 
91
        public void testNotEmpty() {
 
92
                aMsgs.add("myProp", msg1);
 
93
                assertTrue("aMsgs is empty!", aMsgs.isEmpty() == false);
 
94
        }
 
95
 
 
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);
 
100
        }
 
101
 
 
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);
 
110
        }
 
111
 
 
112
        public void testSizeAndEmptyAfterClear() {
 
113
                testSizeWithOneProperty();
 
114
                aMsgs.clear();
 
115
                testEmpty();
 
116
                assertTrue("number of meesages is not 0", aMsgs.size("myProp") == 0);
 
117
        }
 
118
 
 
119
        public void testGetWithNoProperty() {
 
120
                Iterator it = aMsgs.get("myProp");
 
121
                assertTrue("iterator is not empty!", it.hasNext() == false);
 
122
        }
 
123
 
 
124
        public void testGetForAProperty() {
 
125
                testSizeWithOneProperty();
 
126
                Iterator it = aMsgs.get("myProp");
 
127
                assertTrue("iterator is empty!", it.hasNext() == true);
 
128
        }
 
129
 
 
130
        /**
 
131
         * Tests adding an ActionMessages object to an ActionMessages object.
 
132
         */
 
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();
 
139
 
 
140
                msgs.add("prop1", msg1);
 
141
                add.add("prop1", msg2);
 
142
                add.add("prop3", msg3);
 
143
 
 
144
                msgs.add(add);
 
145
                assertTrue(msgs.size() == 3);
 
146
                assertTrue(msgs.size("prop1") == 2);
 
147
 
 
148
                // test message order
 
149
                Iterator props = msgs.get();
 
150
                int count = 1;
 
151
                while (props.hasNext()) {
 
152
                        ActionMessage msg = (ActionMessage) props.next();
 
153
                        if (count == 1) {
 
154
                                assertTrue(msg.getKey().equals("key"));
 
155
                        } else if (count == 2) {
 
156
                                assertTrue(msg.getKey().equals("key2"));
 
157
                        } else {
 
158
                                assertTrue(msg.getKey().equals("key3"));
 
159
                        }
 
160
 
 
161
                        count++;
 
162
                }
 
163
        }
 
164
}