001: /*
002: * $Id: TestActionMessage.java 471754 2006-11-06 14:55:09Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts.action;
022:
023: import junit.framework.Test;
024: import junit.framework.TestCase;
025: import junit.framework.TestSuite;
026:
027: /**
028: * Unit tests for the <code>org.apache.struts.action.ActionMessage</code>
029: * class.
030: *
031: * @version $Rev: 471754 $ $Date: 2005-05-19 23:50:06 -0400 (Thu, 19 May 2005)
032: * $
033: */
034: public class TestActionMessage extends TestCase {
035: protected ActionMessage amWithNoValue = null;
036: protected ActionMessage amWithOneValue = null;
037: protected ActionMessage amWithTwoValues = null;
038: protected ActionMessage amWithThreeValues = null;
039: protected ActionMessage amWithFourValues = null;
040: protected ActionMessage amWithArrayValues = null;
041: protected ActionMessage amWithTwoIntegerValues = null;
042: protected ActionMessage amNoResource = null;
043: protected Object[] test_values = new Object[] { "stringValue1",
044: "stringValue2", "stringValue3", "stringValue4" };
045:
046: /**
047: * Defines the testcase name for JUnit.
048: *
049: * @param theName the testcase's name.
050: */
051: public TestActionMessage(String theName) {
052: super (theName);
053: }
054:
055: /**
056: * Start the tests.
057: *
058: * @param theArgs the arguments. Not used
059: */
060: public static void main(String[] theArgs) {
061: junit.awtui.TestRunner
062: .main(new String[] { TestActionMessage.class.getName() });
063: }
064:
065: /**
066: * @return a test suite (<code>TestSuite</code>) that includes all methods
067: * starting with "test"
068: */
069: public static Test suite() {
070: // All methods starting with "test" will be executed in the test suite.
071: return new TestSuite(TestActionMessage.class);
072: }
073:
074: public void setUp() {
075: amWithNoValue = new ActionMessage("amWithNoValue");
076: amWithOneValue = new ActionMessage("amWithOneValue",
077: new String("stringValue"));
078: amWithTwoValues = new ActionMessage("amWithTwoValues",
079: new String("stringValue1"), new String("stringValue2"));
080: amWithThreeValues = new ActionMessage("amWithThreeValues",
081: new String("stringValue1"), new String("stringValue2"),
082: new String("stringValue3"));
083: amWithFourValues = new ActionMessage("amWithFourValues",
084: new String("stringValue1"), new String("stringValue2"),
085: new String("stringValue3"), new String("stringValue4"));
086: amWithArrayValues = new ActionMessage("amWithArrayValues",
087: test_values);
088: amWithTwoIntegerValues = new ActionMessage(
089: "amWithTwoIntegerValues", new Integer(5), new Integer(
090: 10));
091: amNoResource = new ActionMessage("amNoResource", false);
092: }
093:
094: public void tearDown() {
095: amWithNoValue = null;
096: amWithOneValue = null;
097: amWithTwoValues = null;
098: amWithThreeValues = null;
099: amWithFourValues = null;
100: amWithArrayValues = null;
101: amWithTwoIntegerValues = null;
102: amNoResource = null;
103: }
104:
105: public void testActionMessageWithNoValue() {
106: assertTrue(amWithNoValue.getValues() == null);
107: assertTrue(amWithNoValue.isResource());
108: assertTrue(amWithNoValue.getKey() == "amWithNoValue");
109: assertTrue(amWithNoValue.toString().equals("amWithNoValue[]"));
110: }
111:
112: public void testActionMessageWithAStringValue() {
113: Object[] values = amWithOneValue.getValues();
114:
115: assertTrue(values != null);
116: assertTrue(values.length == 1);
117: assertTrue(values[0].equals("stringValue"));
118: assertTrue(amWithOneValue.isResource());
119: assertTrue(amWithOneValue.getKey() == "amWithOneValue");
120: assertTrue(amWithOneValue.toString().equals(
121: "amWithOneValue[stringValue]"));
122: }
123:
124: public void testActionMessageWithTwoValues() {
125: Object[] values = amWithTwoValues.getValues();
126:
127: assertTrue(values != null);
128: assertTrue(values.length == 2);
129: assertTrue(values[0].equals("stringValue1"));
130: assertTrue(values[1].equals("stringValue2"));
131: assertTrue(amWithTwoValues.isResource());
132: assertTrue(amWithTwoValues.getKey() == "amWithTwoValues");
133: assertTrue(amWithTwoValues.toString().equals(
134: "amWithTwoValues[stringValue1, stringValue2]"));
135: }
136:
137: public void testActionMessageWithThreeValues() {
138: Object[] values = amWithThreeValues.getValues();
139:
140: assertTrue(values != null);
141: assertTrue(values.length == 3);
142: assertTrue(values[0].equals("stringValue1"));
143: assertTrue(values[1].equals("stringValue2"));
144: assertTrue(values[2].equals("stringValue3"));
145: assertTrue(amWithThreeValues.getKey() == "amWithThreeValues");
146: assertTrue(amWithThreeValues.isResource());
147: assertTrue(amWithThreeValues
148: .toString()
149: .equals(
150: "amWithThreeValues[stringValue1, stringValue2, stringValue3]"));
151: }
152:
153: public void testActionMessageWithFourValues() {
154: Object[] values = amWithFourValues.getValues();
155:
156: assertTrue(values != null);
157: assertTrue(values.length == 4);
158: assertTrue(values[0].equals("stringValue1"));
159: assertTrue(values[1].equals("stringValue2"));
160: assertTrue(values[2].equals("stringValue3"));
161: assertTrue(values[3].equals("stringValue4"));
162: assertTrue(amWithFourValues.isResource());
163: assertTrue(amWithFourValues.getKey() == "amWithFourValues");
164: assertTrue(amWithFourValues
165: .toString()
166: .equals(
167: "amWithFourValues[stringValue1, stringValue2, stringValue3, stringValue4]"));
168: }
169:
170: public void testActionMessageWithArrayValues() {
171: Object[] values = amWithArrayValues.getValues();
172:
173: assertTrue(values != null);
174: assertTrue(values.length == test_values.length);
175:
176: for (int i = 0; i < values.length; i++) {
177: assertTrue(values[i] == test_values[i]);
178: }
179:
180: assertTrue(amWithArrayValues.isResource());
181: assertTrue(amWithArrayValues.getKey() == "amWithArrayValues");
182: assertTrue(amWithArrayValues
183: .toString()
184: .equals(
185: "amWithArrayValues[stringValue1, stringValue2, stringValue3, stringValue4]"));
186: }
187:
188: public void testActionWithTwoIntegers() {
189: Object[] values = amWithTwoIntegerValues.getValues();
190:
191: assertTrue(values != null);
192: assertTrue(values.length == 2);
193: assertTrue(values[0] instanceof Integer);
194: assertTrue(values[0].toString().equals("5"));
195: assertTrue(values[1] instanceof Integer);
196: assertTrue(values[1].toString().equals("10"));
197: assertTrue(amWithTwoIntegerValues.isResource());
198: assertTrue(amWithTwoIntegerValues.getKey() == "amWithTwoIntegerValues");
199: assertTrue(amWithTwoIntegerValues.toString().equals(
200: "amWithTwoIntegerValues[5, 10]"));
201: }
202:
203: public void testActionNoResource() {
204: assertTrue(amNoResource.getValues() == null);
205: assertTrue(amNoResource.isResource() == false);
206: assertTrue(amNoResource.getKey() == "amNoResource");
207: assertTrue(amNoResource.toString().equals("amNoResource[]"));
208: }
209: }
|