1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts.action;
22
23 import junit.framework.Test;
24 import junit.framework.TestCase;
25 import junit.framework.TestSuite;
26
27
28
29
30
31
32
33
34 public class TestActionMessage extends TestCase {
35 protected ActionMessage amWithNoValue = null;
36 protected ActionMessage amWithOneValue = null;
37 protected ActionMessage amWithTwoValues = null;
38 protected ActionMessage amWithThreeValues = null;
39 protected ActionMessage amWithFourValues = null;
40 protected ActionMessage amWithArrayValues = null;
41 protected ActionMessage amWithTwoIntegerValues = null;
42 protected ActionMessage amNoResource = null;
43 protected Object[] test_values =
44 new Object[] {
45 "stringValue1", "stringValue2", "stringValue3", "stringValue4"
46 };
47
48
49
50
51
52
53 public TestActionMessage(String theName) {
54 super(theName);
55 }
56
57
58
59
60
61
62 public static void main(String[] theArgs) {
63 junit.awtui.TestRunner.main(new String[] {
64 TestActionMessage.class.getName()
65 });
66 }
67
68
69
70
71
72 public static Test suite() {
73
74 return new TestSuite(TestActionMessage.class);
75 }
76
77 public void setUp() {
78 amWithNoValue = new ActionMessage("amWithNoValue");
79 amWithOneValue =
80 new ActionMessage("amWithOneValue", new String("stringValue"));
81 amWithTwoValues =
82 new ActionMessage("amWithTwoValues", new String("stringValue1"),
83 new String("stringValue2"));
84 amWithThreeValues =
85 new ActionMessage("amWithThreeValues", new String("stringValue1"),
86 new String("stringValue2"), new String("stringValue3"));
87 amWithFourValues =
88 new ActionMessage("amWithFourValues", new String("stringValue1"),
89 new String("stringValue2"), new String("stringValue3"),
90 new String("stringValue4"));
91 amWithArrayValues = new ActionMessage("amWithArrayValues", test_values);
92 amWithTwoIntegerValues =
93 new ActionMessage("amWithTwoIntegerValues", new Integer(5),
94 new Integer(10));
95 amNoResource = new ActionMessage("amNoResource", false);
96 }
97
98 public void tearDown() {
99 amWithNoValue = null;
100 amWithOneValue = null;
101 amWithTwoValues = null;
102 amWithThreeValues = null;
103 amWithFourValues = null;
104 amWithArrayValues = null;
105 amWithTwoIntegerValues = null;
106 amNoResource = null;
107 }
108
109 public void testActionMessageWithNoValue() {
110 assertTrue(amWithNoValue.getValues() == null);
111 assertTrue(amWithNoValue.isResource());
112 assertTrue(amWithNoValue.getKey() == "amWithNoValue");
113 assertTrue(amWithNoValue.toString().equals("amWithNoValue[]"));
114 }
115
116 public void testActionMessageWithAStringValue() {
117 Object[] values = amWithOneValue.getValues();
118
119 assertTrue(values != null);
120 assertTrue(values.length == 1);
121 assertTrue(values[0].equals("stringValue"));
122 assertTrue(amWithOneValue.isResource());
123 assertTrue(amWithOneValue.getKey() == "amWithOneValue");
124 assertTrue(amWithOneValue.toString().equals("amWithOneValue[stringValue]"));
125 }
126
127 public void testActionMessageWithTwoValues() {
128 Object[] values = amWithTwoValues.getValues();
129
130 assertTrue(values != null);
131 assertTrue(values.length == 2);
132 assertTrue(values[0].equals("stringValue1"));
133 assertTrue(values[1].equals("stringValue2"));
134 assertTrue(amWithTwoValues.isResource());
135 assertTrue(amWithTwoValues.getKey() == "amWithTwoValues");
136 assertTrue(amWithTwoValues.toString().equals("amWithTwoValues[stringValue1, stringValue2]"));
137 }
138
139 public void testActionMessageWithThreeValues() {
140 Object[] values = amWithThreeValues.getValues();
141
142 assertTrue(values != null);
143 assertTrue(values.length == 3);
144 assertTrue(values[0].equals("stringValue1"));
145 assertTrue(values[1].equals("stringValue2"));
146 assertTrue(values[2].equals("stringValue3"));
147 assertTrue(amWithThreeValues.getKey() == "amWithThreeValues");
148 assertTrue(amWithThreeValues.isResource());
149 assertTrue(amWithThreeValues.toString().equals("amWithThreeValues[stringValue1, stringValue2, stringValue3]"));
150 }
151
152 public void testActionMessageWithFourValues() {
153 Object[] values = amWithFourValues.getValues();
154
155 assertTrue(values != null);
156 assertTrue(values.length == 4);
157 assertTrue(values[0].equals("stringValue1"));
158 assertTrue(values[1].equals("stringValue2"));
159 assertTrue(values[2].equals("stringValue3"));
160 assertTrue(values[3].equals("stringValue4"));
161 assertTrue(amWithFourValues.isResource());
162 assertTrue(amWithFourValues.getKey() == "amWithFourValues");
163 assertTrue(amWithFourValues.toString().equals("amWithFourValues[stringValue1, stringValue2, stringValue3, stringValue4]"));
164 }
165
166 public void testActionMessageWithArrayValues() {
167 Object[] values = amWithArrayValues.getValues();
168
169 assertTrue(values != null);
170 assertTrue(values.length == test_values.length);
171
172 for (int i = 0; i < values.length; i++) {
173 assertTrue(values[i] == test_values[i]);
174 }
175
176 assertTrue(amWithArrayValues.isResource());
177 assertTrue(amWithArrayValues.getKey() == "amWithArrayValues");
178 assertTrue(amWithArrayValues.toString().equals("amWithArrayValues[stringValue1, stringValue2, stringValue3, stringValue4]"));
179 }
180
181 public void testActionWithTwoIntegers() {
182 Object[] values = amWithTwoIntegerValues.getValues();
183
184 assertTrue(values != null);
185 assertTrue(values.length == 2);
186 assertTrue(values[0] instanceof Integer);
187 assertTrue(values[0].toString().equals("5"));
188 assertTrue(values[1] instanceof Integer);
189 assertTrue(values[1].toString().equals("10"));
190 assertTrue(amWithTwoIntegerValues.isResource());
191 assertTrue(amWithTwoIntegerValues.getKey() == "amWithTwoIntegerValues");
192 assertTrue(amWithTwoIntegerValues.toString().equals("amWithTwoIntegerValues[5, 10]"));
193 }
194
195 public void testActionNoResource() {
196 assertTrue(amNoResource.getValues() == null);
197 assertTrue(amNoResource.isResource() == false);
198 assertTrue(amNoResource.getKey() == "amNoResource");
199 assertTrue(amNoResource.toString().equals("amNoResource[]"));
200 }
201 }