KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > struts > action > TestDynaActionForm


1 /*
2  * $Id: TestDynaActionForm.java 54929 2004-10-16 16:38:42Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.struts.action;
19
20
21 import java.util.ArrayList JavaDoc;
22 import java.util.HashMap JavaDoc;
23 import java.util.List JavaDoc;
24 import java.util.Map JavaDoc;
25
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.apache.commons.beanutils.DynaProperty;
30 import org.apache.commons.logging.Log;
31 import org.apache.commons.logging.LogFactory;
32 import org.apache.struts.config.FormBeanConfig;
33 import org.apache.struts.config.ModuleConfig;
34 import org.apache.struts.config.impl.ModuleConfigImpl;
35
36
37 /**
38  * Suite of unit tests for the
39  * <code>org.apache.struts.action.DynaActionForm</code> class.
40  */

41 public class TestDynaActionForm extends TestDynaActionFormClass {
42
43
44     /**
45      * Defines the testcase name for JUnit.
46      *
47      * @param theName the testcase's name.
48      */

49     public TestDynaActionForm(String JavaDoc theName)
50     {
51         super(theName);
52     }
53
54
55     /**
56      * Start the tests.
57      *
58      * @param theArgs the arguments. Not used
59      */

60     public static void main(String JavaDoc[] theArgs)
61     {
62         junit.awtui.TestRunner.main
63             (new String JavaDoc[] {TestDynaActionForm.class.getName()});
64     }
65
66
67     /**
68      * @return a test suite (<code>TestSuite</code>) that includes all methods
69      * starting with "test"
70      */

71     public static Test suite()
72     {
73         // All methods starting with "test" will be executed in the test suite.
74
return new TestSuite(TestDynaActionForm.class);
75     }
76
77
78     // ----------------------------------------------------- Instance Variables
79

80
81     /**
82      * Dummy ModuleConfig for calls to reset() and validate().
83      */

84     protected ModuleConfig moduleConfig = null;
85
86
87     /**
88      * The basic <code>DynaActionForm</code> to use for testing.
89      */

90     protected DynaActionForm dynaForm = null;
91
92
93     /**
94      * Dummy ActionMapping for calls to reset() and validate().
95      */

96     protected ActionMapping mapping = null;
97
98
99     protected Log log = null;
100
101     /**
102      * The set of property names we expect to have returned when calling
103      * <code>getDynaProperties()</code>. You should update this list
104      * when new properties are added to TestBean.
105      */

106     protected final static String JavaDoc[] properties = {
107         "booleanProperty",
108         "booleanSecond",
109         "doubleProperty",
110         "floatProperty",
111         "intArray",
112         "intIndexed",
113         "intProperty",
114         "listIndexed",
115         "longProperty",
116         "mappedProperty",
117         "mappedIntProperty",
118         // "nullProperty",
119
"shortProperty",
120         "stringArray",
121         "stringIndexed",
122         "stringProperty",
123     };
124
125
126     // ----------------------------------------------------- Setup and Teardown
127

128
129     public void setUp() {
130
131         super.setUp();
132         try {
133             dynaForm = (DynaActionForm) dynaClass.newInstance();
134         } catch (IllegalAccessException JavaDoc e) {
135             throw new RuntimeException JavaDoc(e.getMessage());
136         } catch (InstantiationException JavaDoc e) {
137             throw new RuntimeException JavaDoc(e.getMessage());
138         }
139         setupComplexProperties();
140         moduleConfig = new DynaActionFormConfig(beanConfig);
141         mapping = new DynaActionFormMapping(moduleConfig);
142         log = LogFactory.getLog(this.getClass().getName() + "." + this.getName());
143
144     }
145
146
147     public void tearDown() {
148
149         super.tearDown();
150         moduleConfig = null;
151         dynaForm = null;
152         mapping = null;
153
154     }
155
156
157     // --------------------------------------------- Create New DynaActionForms
158

159
160     // Test basic form bean properties on creation
161
public void testBeanCreate() {
162
163         assertEquals("booleanProperty", Boolean.TRUE,
164                      (Boolean JavaDoc) dynaForm.get("booleanProperty"));
165         assertEquals("booleanSecond", Boolean.TRUE,
166                      (Boolean JavaDoc) dynaForm.get("booleanSecond"));
167         assertEquals("doubleProperty", new Double JavaDoc(321.0),
168                      (Double JavaDoc) dynaForm.get("doubleProperty"));
169         assertEquals("floatProperty", new Float JavaDoc((float) 123.0),
170                      (Float JavaDoc) dynaForm.get("floatProperty"));
171         assertEquals("intProperty", new Integer JavaDoc(123),
172                      (Integer JavaDoc) dynaForm.get("intProperty"));
173         // FIXME - listIndexed
174
assertEquals("longProperty", new Long JavaDoc((long) 321),
175                      (Long JavaDoc) dynaForm.get("longProperty"));
176         // FIXME - mappedProperty
177
// FIXME - mappedIntProperty
178
// assertEquals("nullProperty", (String) null,
179
// (String) dynaForm.get("nullProperty"));
180
assertEquals("shortProperty", new Short JavaDoc((short) 987),
181                      (Short JavaDoc) dynaForm.get("shortProperty"));
182         assertEquals("stringProperty", "This is a string",
183                      (String JavaDoc) dynaForm.get("stringProperty"));
184
185     }
186
187
188     // Test initialize() method on indexed values to ensure that the
189
// result returned by FormPropertyConfig().initial() is never clobbered
190
public void testIndexedInitialize() {
191
192         // Update some values in the indexed properties
193
dynaForm.set("intArray", 1, new Integer JavaDoc(111));
194         assertEquals("intArray[1]", new Integer JavaDoc(111),
195                      (Integer JavaDoc) dynaForm.get("intArray", 1));
196         dynaForm.set("intIndexed", 2, new Integer JavaDoc(222));
197         assertEquals("intIndexed[2]", new Integer JavaDoc(222),
198                      (Integer JavaDoc) dynaForm.get("intIndexed", 2));
199         dynaForm.set("stringArray", 3, "New String 3");
200         assertEquals("stringArray[3]", "New String 3",
201                      (String JavaDoc) dynaForm.get("stringArray", 3));
202         dynaForm.set("stringIndexed", 4, "New String 4");
203         assertEquals("stringIndexed[4]", "New String 4",
204                      (String JavaDoc) dynaForm.get("stringIndexed", 4));
205
206         // Perform initialize() and revalidate the original values
207
// while ensuring our initial values did not get corrupted
208
dynaForm.initialize(mapping);
209         setupComplexProperties();
210         testGetIndexedValues();
211
212     }
213
214
215     // Test initialize() method going back to initial values
216
public void testScalarInitialize() {
217
218         // Update a bunch of scalar properties to new values
219
dynaForm.set("booleanProperty", Boolean.FALSE);
220         assertEquals("booleanProperty", Boolean.FALSE,
221                      (Boolean JavaDoc) dynaForm.get("booleanProperty"));
222         dynaForm.set("booleanSecond", Boolean.FALSE);
223         dynaForm.set("doubleProperty", new Double JavaDoc(654.0));
224         dynaForm.set("floatProperty", new Float JavaDoc((float) 543.0));
225         dynaForm.set("intProperty", new Integer JavaDoc(555));
226         dynaForm.set("longProperty", new Long JavaDoc((long) 777));
227         dynaForm.set("shortProperty", new Short JavaDoc((short) 222));
228         dynaForm.set("stringProperty", "New String Value");
229         assertEquals("stringProperty", "New String Value",
230                      (String JavaDoc) dynaForm.get("stringProperty"));
231
232         // Perform initialize() and revalidate the original values
233
dynaForm.initialize(mapping);
234         setupComplexProperties();
235         testBeanCreate();
236
237     }
238
239
240     // --------------------------------------- Tests from BasicDynaBeanTestCase
241

242
243     /**
244      * Corner cases on getDynaProperty invalid arguments.
245      */

246     public void testGetDescriptorArguments() {
247
248         DynaProperty descriptor =
249             dynaForm.getDynaClass().getDynaProperty("unknown");
250         assertNull("Unknown property descriptor should be null",
251             descriptor);
252
253         try {
254             dynaForm.getDynaClass().getDynaProperty(null);
255             fail("Should throw IllegalArgumentException");
256         } catch (IllegalArgumentException JavaDoc e) {
257             ; // Expected response
258
}
259
260     }
261
262
263     /**
264      * Positive getDynaProperty on property <code>booleanProperty</code>.
265      */

266     public void testGetDescriptorBoolean() {
267
268         testGetDescriptorBase("booleanProperty", Boolean.TYPE);
269
270     }
271
272
273     /**
274      * Positive getDynaProperty on property <code>doubleProperty</code>.
275      */

276     public void testGetDescriptorDouble() {
277
278         testGetDescriptorBase("doubleProperty", Double.TYPE);
279
280     }
281
282
283     /**
284      * Positive getDynaProperty on property <code>floatProperty</code>.
285      */

286     public void testGetDescriptorFloat() {
287
288         testGetDescriptorBase("floatProperty", Float.TYPE);
289
290     }
291
292
293     /**
294      * Positive getDynaProperty on property <code>intProperty</code>.
295      */

296     public void testGetDescriptorInt() {
297
298         testGetDescriptorBase("intProperty", Integer.TYPE);
299
300     }
301
302
303     /**
304      * Positive getDynaProperty on property <code>longProperty</code>.
305      */

306     public void testGetDescriptorLong() {
307
308         testGetDescriptorBase("longProperty", Long.TYPE);
309
310     }
311
312
313     /**
314      * Positive getDynaProperty on property <code>booleanSecond</code>
315      * that uses an "is" method as the getter.
316      */

317     public void testGetDescriptorSecond() {
318
319         testGetDescriptorBase("booleanSecond", Boolean.TYPE);
320
321     }
322
323
324     /**
325      * Positive getDynaProperty on property <code>shortProperty</code>.
326      */

327     public void testGetDescriptorShort() {
328
329         testGetDescriptorBase("shortProperty", Short.TYPE);
330
331     }
332
333
334     /**
335      * Positive getDynaProperty on property <code>stringProperty</code>.
336      */

337     public void testGetDescriptorString() {
338
339         testGetDescriptorBase("stringProperty", String JavaDoc.class);
340
341     }
342
343
344     /**
345      * Positive test for getDynaPropertys(). Each property name
346      * listed in <code>properties</code> should be returned exactly once.
347      */

348     public void testGetDescriptors() {
349
350         DynaProperty pd[] = dynaForm.getDynaClass().getDynaProperties();
351         assertNotNull("Got descriptors", pd);
352         int count[] = new int[properties.length];
353         for (int i = 0; i < pd.length; i++) {
354             String JavaDoc name = pd[i].getName();
355             for (int j = 0; j < properties.length; j++) {
356                 if (name.equals(properties[j]))
357                     count[j]++;
358             }
359         }
360         for (int j = 0; j < properties.length; j++) {
361             if (count[j] < 0)
362                 fail("Missing property " + properties[j]);
363             else if (count[j] > 1)
364                 fail("Duplicate property " + properties[j]);
365         }
366
367     }
368
369
370     /**
371      * Corner cases on getIndexedProperty invalid arguments.
372      */

373     public void testGetIndexedArguments() {
374
375         try {
376             dynaForm.get("intArray", -1);
377             fail("Should throw IndexOutOfBoundsException");
378         } catch (IndexOutOfBoundsException JavaDoc e) {
379             ; // Expected response
380
}
381
382     }
383
384
385     /**
386      * Positive and negative tests on getIndexedProperty valid arguments.
387      */

388     public void testGetIndexedValues() {
389
390         Object JavaDoc value = null;
391
392         for (int i = 0; i < 5; i++) {
393
394             value = dynaForm.get("intArray", i);
395             assertNotNull("intArray returned value " + i, value);
396             assertTrue("intArray returned Integer " + i,
397                     value instanceof Integer JavaDoc);
398             assertEquals("intArray returned correct " + i, i * 10,
399                     ((Integer JavaDoc) value).intValue());
400
401             value = dynaForm.get("intIndexed", i);
402             assertNotNull("intIndexed returned value " + i, value);
403             assertTrue("intIndexed returned Integer " + i,
404                     value instanceof Integer JavaDoc);
405             assertEquals("intIndexed returned correct " + i, i * 100,
406                     ((Integer JavaDoc) value).intValue());
407
408             value = dynaForm.get("listIndexed", i);
409             assertNotNull("listIndexed returned value " + i, value);
410             assertTrue("list returned String " + i,
411                     value instanceof String JavaDoc);
412             assertEquals("listIndexed returned correct " + i,
413                     "String " + i, (String JavaDoc) value);
414
415             value = dynaForm.get("stringArray", i);
416             assertNotNull("stringArray returned value " + i, value);
417             assertTrue("stringArray returned String " + i,
418                     value instanceof String JavaDoc);
419             assertEquals("stringArray returned correct " + i,
420                     "String " + i, (String JavaDoc) value);
421
422             value = dynaForm.get("stringIndexed", i);
423             assertNotNull("stringIndexed returned value " + i, value);
424             assertTrue("stringIndexed returned String " + i,
425                     value instanceof String JavaDoc);
426             assertEquals("stringIndexed returned correct " + i,
427                     "String " + i, (String JavaDoc) value);
428
429         }
430
431
432     }
433
434
435     /**
436      * Corner cases on getMappedProperty invalid arguments.
437      */

438     public void testGetMappedArguments() {
439         Object JavaDoc value = dynaForm.get("mappedProperty", "unknown");
440         assertNull("Should not return a value", value);
441     }
442
443
444     /**
445      * Positive and negative tests on getMappedProperty valid arguments.
446      */

447     public void testGetMappedValues() {
448
449         Object JavaDoc value = null;
450
451         value = dynaForm.get("mappedProperty", "First Key");
452         assertEquals("Can find first value", "First Value", value);
453
454         value = dynaForm.get("mappedProperty", "Second Key");
455         assertEquals("Can find second value", "Second Value", value);
456
457         value = dynaForm.get("mappedProperty", "Third Key");
458         assertNull("Can not find third value", value);
459
460     }
461
462
463     /**
464      * Corner cases on getSimpleProperty invalid arguments.
465      */

466     public void testGetSimpleArguments() {
467
468         try {
469             dynaForm.get(null);
470             fail("Should throw IllegalArgumentException");
471         } catch (IllegalArgumentException JavaDoc e) {
472             ; // Expected response
473
}
474
475     }
476
477
478     /**
479      * Test getSimpleProperty on a boolean property.
480      */

481     public void testGetSimpleBoolean() {
482
483         Object JavaDoc value = dynaForm.get("booleanProperty");
484         assertNotNull("Got a value", value);
485         assertTrue("Got correct type", (value instanceof Boolean JavaDoc));
486         assertTrue("Got correct value",
487                 ((Boolean JavaDoc) value).booleanValue() == true);
488     }
489
490
491     /**
492      * Test getSimpleProperty on a double property.
493      */

494     public void testGetSimpleDouble() {
495
496             Object JavaDoc value = dynaForm.get("doubleProperty");
497             assertNotNull("Got a value", value);
498             assertTrue("Got correct type", (value instanceof Double JavaDoc));
499             assertEquals("Got correct value",
500                     ((Double JavaDoc) value).doubleValue(),
501                     (double) 321.0,
502                     (double) 0.005);
503
504     }
505
506
507     /**
508      * Test getSimpleProperty on a float property.
509      */

510     public void testGetSimpleFloat() {
511
512         Object JavaDoc value = dynaForm.get("floatProperty");
513         assertNotNull("Got a value", value);
514         assertTrue("Got correct type", (value instanceof Float JavaDoc));
515         assertEquals("Got correct value",
516                 ((Float JavaDoc) value).floatValue(),
517                 (float) 123.0,
518                 (float) 0.005);
519
520     }
521
522
523     /**
524      * Test getSimpleProperty on a int property.
525      */

526     public void testGetSimpleInt() {
527
528         Object JavaDoc value = dynaForm.get("intProperty");
529         assertNotNull("Got a value", value);
530         assertTrue("Got correct type", (value instanceof Integer JavaDoc));
531         assertEquals("Got correct value",
532                 ((Integer JavaDoc) value).intValue(),
533                 (int) 123);
534
535     }
536
537
538     /**
539      * Test getSimpleProperty on a long property.
540      */

541     public void testGetSimpleLong() {
542
543         Object JavaDoc value = dynaForm.get("longProperty");
544         assertNotNull("Got a value", value);
545         assertTrue("Got correct type", (value instanceof Long JavaDoc));
546         assertEquals("Got correct value",
547                 ((Long JavaDoc) value).longValue(),
548                 (long) 321);
549
550     }
551
552
553     /**
554      * Test getSimpleProperty on a short property.
555      */

556     public void testGetSimpleShort() {
557
558         Object JavaDoc value = dynaForm.get("shortProperty");
559         assertNotNull("Got a value", value);
560         assertTrue("Got correct type", (value instanceof Short JavaDoc));
561         assertEquals("Got correct value",
562                 ((Short JavaDoc) value).shortValue(),
563                 (short) 987);
564
565     }
566
567
568     /**
569      * Test getSimpleProperty on a String property.
570      */

571     public void testGetSimpleString() {
572
573         Object JavaDoc value = dynaForm.get("stringProperty");
574         assertNotNull("Got a value", value);
575         assertTrue("Got correct type", (value instanceof String JavaDoc));
576         assertEquals("Got correct value",
577                 (String JavaDoc) value,
578                 "This is a string");
579
580     }
581
582
583     /**
584      * Test <code>contains()</code> method for mapped properties.
585      */

586     public void testMappedContains() {
587
588         assertTrue("Can see first key",
589                 dynaForm.contains("mappedProperty", "First Key"));
590
591         assertTrue("Can not see unknown key",
592                 !dynaForm.contains("mappedProperty", "Unknown Key"));
593
594     }
595
596
597     /**
598      * Test <code>remove()</code> method for mapped properties.
599      */

600     public void testMappedRemove() {
601
602         assertTrue("Can see first key",
603                 dynaForm.contains("mappedProperty", "First Key"));
604         dynaForm.remove("mappedProperty", "First Key");
605         assertTrue("Can not see first key",
606                 !dynaForm.contains("mappedProperty", "First Key"));
607
608         assertTrue("Can not see unknown key",
609                 !dynaForm.contains("mappedProperty", "Unknown Key"));
610         dynaForm.remove("mappedProperty", "Unknown Key");
611         assertTrue("Can not see unknown key",
612                 !dynaForm.contains("mappedProperty", "Unknown Key"));
613
614     }
615
616
617     /**
618      * Corner cases on setIndexedProperty invalid arguments.
619      */

620     public void testSetIndexedArguments() {
621
622         try {
623             dynaForm.set("intArray", -1, new Integer JavaDoc(0));
624             fail("Should throw IndexOutOfBoundsException");
625         } catch (IndexOutOfBoundsException JavaDoc e) {
626             ; // Expected response
627
}
628
629     }
630
631
632     /**
633      * Positive and negative tests on setIndexedProperty valid arguments.
634      */

635     public void testSetIndexedValues() {
636
637         Object JavaDoc value = null;
638
639         dynaForm.set("intArray", 0, new Integer JavaDoc(1));
640         value = (Integer JavaDoc) dynaForm.get("intArray", 0);
641         assertNotNull("Returned new value 0", value);
642         assertTrue("Returned Integer new value 0",
643                 value instanceof Integer JavaDoc);
644         assertEquals("Returned correct new value 0", 1,
645                 ((Integer JavaDoc) value).intValue());
646
647         dynaForm.set("intIndexed", 1, new Integer JavaDoc(11));
648         value = (Integer JavaDoc) dynaForm.get("intIndexed", 1);
649         assertNotNull("Returned new value 1", value);
650         assertTrue("Returned Integer new value 1",
651                 value instanceof Integer JavaDoc);
652         assertEquals("Returned correct new value 1", 11,
653                 ((Integer JavaDoc) value).intValue());
654         dynaForm.set("listIndexed", 2, "New Value 2");
655         value = (String JavaDoc) dynaForm.get("listIndexed", 2);
656         assertNotNull("Returned new value 2", value);
657         assertTrue("Returned String new value 2",
658                 value instanceof String JavaDoc);
659         assertEquals("Returned correct new value 2", "New Value 2",
660                 (String JavaDoc) value);
661
662         dynaForm.set("stringArray", 3, "New Value 3");
663         value = (String JavaDoc) dynaForm.get("stringArray", 3);
664         assertNotNull("Returned new value 3", value);
665         assertTrue("Returned String new value 3",
666                 value instanceof String JavaDoc);
667         assertEquals("Returned correct new value 3", "New Value 3",
668                 (String JavaDoc) value);
669
670         dynaForm.set("stringIndexed", 4, "New Value 4");
671         value = (String JavaDoc) dynaForm.get("stringIndexed", 4);
672         assertNotNull("Returned new value 4", value);
673         assertTrue("Returned String new value 4",
674                 value instanceof String JavaDoc);
675         assertEquals("Returned correct new value 4", "New Value 4",
676                 (String JavaDoc) value);
677
678
679     }
680
681
682     /**
683      * Positive and negative tests on setMappedProperty valid arguments.
684      */

685     public void testSetMappedValues() {
686
687
688         dynaForm.set("mappedProperty", "First Key", "New First Value");
689         assertEquals("Can replace old value",
690                 "New First Value",
691                 (String JavaDoc) dynaForm.get("mappedProperty", "First Key"));
692
693         dynaForm.set("mappedProperty", "Fourth Key", "Fourth Value");
694         assertEquals("Can set new value",
695                 "Fourth Value",
696                 (String JavaDoc) dynaForm.get("mappedProperty", "Fourth Key"));
697
698
699     }
700
701
702     /**
703      * Test setSimpleProperty on a boolean property.
704      */

705     public void testSetSimpleBoolean() {
706
707         boolean oldValue =
708                 ((Boolean JavaDoc) dynaForm.get("booleanProperty")).booleanValue();
709         boolean newValue = !oldValue;
710         dynaForm.set("booleanProperty", new Boolean JavaDoc(newValue));
711         assertTrue("Matched new value",
712                 newValue ==
713                 ((Boolean JavaDoc) dynaForm.get("booleanProperty")).booleanValue());
714
715     }
716
717
718     /**
719      * Test setSimpleProperty on a double property.
720      */

721     public void testSetSimpleDouble() {
722
723         double oldValue =
724                 ((Double JavaDoc) dynaForm.get("doubleProperty")).doubleValue();
725         double newValue = oldValue + 1.0;
726         dynaForm.set("doubleProperty", new Double JavaDoc(newValue));
727         assertEquals("Matched new value",
728                 newValue,
729                 ((Double JavaDoc) dynaForm.get("doubleProperty")).doubleValue(),
730                 (double) 0.005);
731
732     }
733
734
735     /**
736      * Test setSimpleProperty on a float property.
737      */

738     public void testSetSimpleFloat() {
739
740         float oldValue =
741                 ((Float JavaDoc) dynaForm.get("floatProperty")).floatValue();
742         float newValue = oldValue + (float) 1.0;
743         dynaForm.set("floatProperty", new Float JavaDoc(newValue));
744         assertEquals("Matched new value",
745                 newValue,
746                 ((Float JavaDoc) dynaForm.get("floatProperty")).floatValue(),
747                 (float) 0.005);
748
749     }
750
751
752     /**
753      * Test setSimpleProperty on a int property.
754      */

755     public void testSetSimpleInt() {
756
757         int oldValue =
758                 ((Integer JavaDoc) dynaForm.get("intProperty")).intValue();
759         int newValue = oldValue + 1;
760         dynaForm.set("intProperty", new Integer JavaDoc(newValue));
761         assertEquals("Matched new value",
762                 newValue,
763                 ((Integer JavaDoc) dynaForm.get("intProperty")).intValue());
764     }
765
766
767     /**
768      * Test setSimpleProperty on a long property.
769      */

770     public void testSetSimpleLong() {
771
772         long oldValue =
773                 ((Long JavaDoc) dynaForm.get("longProperty")).longValue();
774         long newValue = oldValue + 1;
775         dynaForm.set("longProperty", new Long JavaDoc(newValue));
776         assertEquals("Matched new value",
777                 newValue,
778                 ((Long JavaDoc) dynaForm.get("longProperty")).longValue());
779
780     }
781
782
783     /**
784      * Test setSimpleProperty on a short property.
785      */

786     public void testSetSimpleShort() {
787
788         short oldValue =
789                 ((Short JavaDoc) dynaForm.get("shortProperty")).shortValue();
790         short newValue = (short) (oldValue + 1);
791         dynaForm.set("shortProperty", new Short JavaDoc(newValue));
792         assertEquals("Matched new value",
793                 newValue,
794                 ((Short JavaDoc) dynaForm.get("shortProperty")).shortValue());
795
796     }
797
798
799     /**
800      * Test setSimpleProperty on a String property.
801      */

802     public void testSetSimpleString() {
803
804         String JavaDoc oldValue = (String JavaDoc) dynaForm.get("stringProperty");
805         String JavaDoc newValue = oldValue + " Extra Value";
806         dynaForm.set("stringProperty", newValue);
807         assertEquals("Matched new value",
808                 newValue,
809                 (String JavaDoc) dynaForm.get("stringProperty"));
810
811     }
812
813
814     // ------------------------------------------------------ Protected Methods
815

816
817     /**
818      * Set up the complex properties that cannot be configured from the
819      * initial value expression.
820      */

821     protected void setupComplexProperties() {
822
823         List JavaDoc listIndexed = new ArrayList JavaDoc();
824         listIndexed.add("String 0");
825         listIndexed.add("String 1");
826         listIndexed.add("String 2");
827         listIndexed.add("String 3");
828         listIndexed.add("String 4");
829         dynaForm.set("listIndexed", listIndexed);
830
831         Map JavaDoc mappedProperty = new HashMap JavaDoc();
832         mappedProperty.put("First Key", "First Value");
833         mappedProperty.put("Second Key", "Second Value");
834         dynaForm.set("mappedProperty", mappedProperty);
835
836         Map JavaDoc mappedIntProperty = new HashMap JavaDoc();
837         mappedIntProperty.put("One", new Integer JavaDoc(1));
838         mappedIntProperty.put("Two", new Integer JavaDoc(2));
839         dynaForm.set("mappedIntProperty", mappedIntProperty);
840
841     }
842
843
844
845     /**
846      * Base for testGetDescriptorXxxxx() series of tests.
847      *
848      * @param name Name of the property to be retrieved
849      * @param type Expected class type of this property
850      */

851     protected void testGetDescriptorBase(String JavaDoc name, Class JavaDoc type) {
852
853         DynaProperty descriptor =
854                 dynaForm.getDynaClass().getDynaProperty(name);
855         assertNotNull("Got descriptor", descriptor);
856         assertEquals("Got correct type", type, descriptor.getType());
857
858     }
859
860
861 }
862
863
864 class DynaActionFormMapping extends ActionMapping {
865
866     public DynaActionFormMapping(ModuleConfig appConfig) {
867         this.appConfig = appConfig;
868     }
869
870     private ModuleConfig appConfig = null;
871
872     public ModuleConfig getModuleConfig() {
873         return (this.appConfig);
874     }
875
876     public String JavaDoc getName() {
877         return ("dynaForm");
878     }
879
880 }
881
882
883
884 class DynaActionFormConfig extends ModuleConfigImpl {
885
886     public DynaActionFormConfig(FormBeanConfig beanConfig) {
887         super("");
888         this.beanConfig = beanConfig;
889     }
890
891     private FormBeanConfig beanConfig = null;
892
893     public FormBeanConfig findFormBeanConfig(String JavaDoc name) {
894         return (this.beanConfig);
895     }
896
897
898 }
899
900
901
Popular Tags