Source Code Cross Referenced for TestDynaActionForm.java in  » Web-Framework » struts-1.3.8 » org » apache » struts » action » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Web Framework » struts 1.3.8 » org.apache.struts.action 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * $Id: TestDynaActionForm.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.TestSuite;
025:
026:        import org.apache.commons.beanutils.DynaProperty;
027:        import org.apache.commons.logging.Log;
028:        import org.apache.commons.logging.LogFactory;
029:        import org.apache.struts.config.FormBeanConfig;
030:        import org.apache.struts.config.ModuleConfig;
031:        import org.apache.struts.config.impl.ModuleConfigImpl;
032:        import org.apache.struts.mock.MockHttpServletRequest;
033:
034:        import java.util.ArrayList;
035:        import java.util.HashMap;
036:        import java.util.List;
037:        import java.util.Map;
038:
039:        /**
040:         * Suite of unit tests for the <code>org.apache.struts.action.DynaActionForm</code>
041:         * class.
042:         */
043:        public class TestDynaActionForm extends TestDynaActionFormClass {
044:            /**
045:             * The set of property names we expect to have returned when calling
046:             * <code>getDynaProperties()</code>.  You should update this list when new
047:             * properties are added to TestBean.
048:             */
049:            protected final static String[] properties = { "booleanProperty",
050:                    "booleanSecond", "doubleProperty", "floatProperty",
051:                    "intArray", "intIndexed", "intProperty", "listIndexed",
052:                    "longProperty", "mappedProperty", "mappedIntProperty",
053:
054:                    //        "nullProperty",
055:                    "shortProperty", "stringArray", "stringIndexed",
056:                    "stringProperty", };
057:
058:            // ----------------------------------------------------- Instance Variables
059:
060:            /**
061:             * Dummy ModuleConfig for calls to reset() and validate().
062:             */
063:            protected ModuleConfig moduleConfig = null;
064:
065:            /**
066:             * The basic <code>DynaActionForm</code> to use for testing.
067:             */
068:            protected DynaActionForm dynaForm = null;
069:
070:            /**
071:             * Dummy ActionMapping for calls to reset() and validate().
072:             */
073:            protected ActionMapping mapping = null;
074:            protected Log log = null;
075:
076:            /**
077:             * Defines the testcase name for JUnit.
078:             *
079:             * @param theName the testcase's name.
080:             */
081:            public TestDynaActionForm(String theName) {
082:                super (theName);
083:            }
084:
085:            /**
086:             * Start the tests.
087:             *
088:             * @param theArgs the arguments. Not used
089:             */
090:            public static void main(String[] theArgs) {
091:                junit.awtui.TestRunner
092:                        .main(new String[] { TestDynaActionForm.class.getName() });
093:            }
094:
095:            /**
096:             * @return a test suite (<code>TestSuite</code>) that includes all methods
097:             *         starting with "test"
098:             */
099:            public static Test suite() {
100:                // All methods starting with "test" will be executed in the test suite.
101:                return new TestSuite(TestDynaActionForm.class);
102:            }
103:
104:            // ----------------------------------------------------- Setup and Teardown
105:            public void setUp() {
106:                super .setUp();
107:
108:                try {
109:                    dynaForm = (DynaActionForm) dynaClass.newInstance();
110:                } catch (IllegalAccessException e) {
111:                    throw new RuntimeException(e.getMessage());
112:                } catch (InstantiationException e) {
113:                    throw new RuntimeException(e.getMessage());
114:                }
115:
116:                setupComplexProperties();
117:                moduleConfig = new DynaActionFormConfig(beanConfig);
118:                mapping = new DynaActionFormMapping(moduleConfig);
119:                log = LogFactory.getLog(this .getClass().getName() + "."
120:                        + this .getName());
121:            }
122:
123:            public void tearDown() {
124:                super .tearDown();
125:                moduleConfig = null;
126:                dynaForm = null;
127:                mapping = null;
128:            }
129:
130:            // --------------------------------------------- Create New DynaActionForms
131:            // Test basic form bean properties on creation
132:            public void testBeanCreate() {
133:                assertEquals("booleanProperty", Boolean.TRUE,
134:                        (Boolean) dynaForm.get("booleanProperty"));
135:                assertEquals("booleanSecond", Boolean.TRUE, (Boolean) dynaForm
136:                        .get("booleanSecond"));
137:                assertEquals("doubleProperty", new Double(321.0),
138:                        (Double) dynaForm.get("doubleProperty"));
139:                assertEquals("floatProperty", new Float((float) 123.0),
140:                        (Float) dynaForm.get("floatProperty"));
141:                assertEquals("intProperty", new Integer(123),
142:                        (Integer) dynaForm.get("intProperty"));
143:
144:                // FIXME - listIndexed
145:                assertEquals("longProperty", new Long((long) 321),
146:                        (Long) dynaForm.get("longProperty"));
147:
148:                // FIXME - mappedProperty
149:                // FIXME - mappedIntProperty
150:                //        assertEquals("nullProperty", (String) null,
151:                //                     (String) dynaForm.get("nullProperty"));
152:                assertEquals("shortProperty", new Short((short) 987),
153:                        (Short) dynaForm.get("shortProperty"));
154:                assertEquals("stringProperty", "This is a string",
155:                        (String) dynaForm.get("stringProperty"));
156:            }
157:
158:            // Test initialize() method on indexed values to ensure that the
159:            // result returned by FormPropertyConfig().initial() is never clobbered
160:            public void testIndexedInitialize() {
161:                // Update some values in the indexed properties
162:                dynaForm.set("intArray", 1, new Integer(111));
163:                assertEquals("intArray[1]", new Integer(111),
164:                        (Integer) dynaForm.get("intArray", 1));
165:                dynaForm.set("intIndexed", 2, new Integer(222));
166:                assertEquals("intIndexed[2]", new Integer(222),
167:                        (Integer) dynaForm.get("intIndexed", 2));
168:                dynaForm.set("stringArray", 3, "New String 3");
169:                assertEquals("stringArray[3]", "New String 3",
170:                        (String) dynaForm.get("stringArray", 3));
171:                dynaForm.set("stringIndexed", 4, "New String 4");
172:                assertEquals("stringIndexed[4]", "New String 4",
173:                        (String) dynaForm.get("stringIndexed", 4));
174:
175:                // Perform initialize() and revalidate the original values
176:                // while ensuring our initial values did not get corrupted
177:                dynaForm.initialize(mapping);
178:                setupComplexProperties();
179:                testGetIndexedValues();
180:            }
181:
182:            // Test initialize() method going back to initial values
183:            public void testScalarInitialize() {
184:                // Update a bunch of scalar properties to new values
185:                dynaForm.set("booleanProperty", Boolean.FALSE);
186:                assertEquals("booleanProperty", Boolean.FALSE,
187:                        (Boolean) dynaForm.get("booleanProperty"));
188:                dynaForm.set("booleanSecond", Boolean.FALSE);
189:                dynaForm.set("doubleProperty", new Double(654.0));
190:                dynaForm.set("floatProperty", new Float((float) 543.0));
191:                dynaForm.set("intProperty", new Integer(555));
192:                dynaForm.set("longProperty", new Long((long) 777));
193:                dynaForm.set("shortProperty", new Short((short) 222));
194:                dynaForm.set("stringProperty", "New String Value");
195:                assertEquals("stringProperty", "New String Value",
196:                        (String) dynaForm.get("stringProperty"));
197:
198:                // Perform initialize() and revalidate the original values
199:                dynaForm.initialize(mapping);
200:                setupComplexProperties();
201:                testBeanCreate();
202:            }
203:
204:            // --------------------------------------- Tests from BasicDynaBeanTestCase
205:
206:            /**
207:             * Corner cases on getDynaProperty invalid arguments.
208:             */
209:            public void testGetDescriptorArguments() {
210:                DynaProperty descriptor = dynaForm.getDynaClass()
211:                        .getDynaProperty("unknown");
212:
213:                assertNull("Unknown property descriptor should be null",
214:                        descriptor);
215:
216:                try {
217:                    dynaForm.getDynaClass().getDynaProperty(null);
218:                    fail("Should throw IllegalArgumentException");
219:                } catch (IllegalArgumentException e) {
220:                    ; // Expected response
221:                }
222:            }
223:
224:            /**
225:             * Positive getDynaProperty on property <code>booleanProperty</code>.
226:             */
227:            public void testGetDescriptorBoolean() {
228:                testGetDescriptorBase("booleanProperty", Boolean.TYPE);
229:            }
230:
231:            /**
232:             * Positive getDynaProperty on property <code>doubleProperty</code>.
233:             */
234:            public void testGetDescriptorDouble() {
235:                testGetDescriptorBase("doubleProperty", Double.TYPE);
236:            }
237:
238:            /**
239:             * Positive getDynaProperty on property <code>floatProperty</code>.
240:             */
241:            public void testGetDescriptorFloat() {
242:                testGetDescriptorBase("floatProperty", Float.TYPE);
243:            }
244:
245:            /**
246:             * Positive getDynaProperty on property <code>intProperty</code>.
247:             */
248:            public void testGetDescriptorInt() {
249:                testGetDescriptorBase("intProperty", Integer.TYPE);
250:            }
251:
252:            /**
253:             * Positive getDynaProperty on property <code>longProperty</code>.
254:             */
255:            public void testGetDescriptorLong() {
256:                testGetDescriptorBase("longProperty", Long.TYPE);
257:            }
258:
259:            /**
260:             * Positive getDynaProperty on property <code>booleanSecond</code> that
261:             * uses an "is" method as the getter.
262:             */
263:            public void testGetDescriptorSecond() {
264:                testGetDescriptorBase("booleanSecond", Boolean.TYPE);
265:            }
266:
267:            /**
268:             * Positive getDynaProperty on property <code>shortProperty</code>.
269:             */
270:            public void testGetDescriptorShort() {
271:                testGetDescriptorBase("shortProperty", Short.TYPE);
272:            }
273:
274:            /**
275:             * Positive getDynaProperty on property <code>stringProperty</code>.
276:             */
277:            public void testGetDescriptorString() {
278:                testGetDescriptorBase("stringProperty", String.class);
279:            }
280:
281:            /**
282:             * Positive test for getDynaPropertys().  Each property name listed in
283:             * <code>properties</code> should be returned exactly once.
284:             */
285:            public void testGetDescriptors() {
286:                DynaProperty[] pd = dynaForm.getDynaClass().getDynaProperties();
287:
288:                assertNotNull("Got descriptors", pd);
289:
290:                int[] count = new int[properties.length];
291:
292:                for (int i = 0; i < pd.length; i++) {
293:                    String name = pd[i].getName();
294:
295:                    for (int j = 0; j < properties.length; j++) {
296:                        if (name.equals(properties[j])) {
297:                            count[j]++;
298:                        }
299:                    }
300:                }
301:
302:                for (int j = 0; j < properties.length; j++) {
303:                    if (count[j] < 0) {
304:                        fail("Missing property " + properties[j]);
305:                    } else if (count[j] > 1) {
306:                        fail("Duplicate property " + properties[j]);
307:                    }
308:                }
309:            }
310:
311:            /**
312:             * Corner cases on getIndexedProperty invalid arguments.
313:             */
314:            public void testGetIndexedArguments() {
315:                try {
316:                    dynaForm.get("intArray", -1);
317:                    fail("Should throw IndexOutOfBoundsException");
318:                } catch (IndexOutOfBoundsException e) {
319:                    ; // Expected response
320:                }
321:            }
322:
323:            /**
324:             * Positive and negative tests on getIndexedProperty valid arguments.
325:             */
326:            public void testGetIndexedValues() {
327:                Object value = null;
328:
329:                for (int i = 0; i < 5; i++) {
330:                    value = dynaForm.get("intArray", i);
331:                    assertNotNull("intArray returned value " + i, value);
332:                    assertTrue("intArray returned Integer " + i,
333:                            value instanceof  Integer);
334:                    assertEquals("intArray returned correct " + i, i * 10,
335:                            ((Integer) value).intValue());
336:
337:                    value = dynaForm.get("intIndexed", i);
338:                    assertNotNull("intIndexed returned value " + i, value);
339:                    assertTrue("intIndexed returned Integer " + i,
340:                            value instanceof  Integer);
341:                    assertEquals("intIndexed returned correct " + i, i * 100,
342:                            ((Integer) value).intValue());
343:
344:                    value = dynaForm.get("listIndexed", i);
345:                    assertNotNull("listIndexed returned value " + i, value);
346:                    assertTrue("list returned String " + i,
347:                            value instanceof  String);
348:                    assertEquals("listIndexed returned correct " + i, "String "
349:                            + i, (String) value);
350:
351:                    value = dynaForm.get("stringArray", i);
352:                    assertNotNull("stringArray returned value " + i, value);
353:                    assertTrue("stringArray returned String " + i,
354:                            value instanceof  String);
355:                    assertEquals("stringArray returned correct " + i, "String "
356:                            + i, (String) value);
357:
358:                    value = dynaForm.get("stringIndexed", i);
359:                    assertNotNull("stringIndexed returned value " + i, value);
360:                    assertTrue("stringIndexed returned String " + i,
361:                            value instanceof  String);
362:                    assertEquals("stringIndexed returned correct " + i,
363:                            "String " + i, (String) value);
364:                }
365:            }
366:
367:            /**
368:             * Corner cases on getMappedProperty invalid arguments.
369:             */
370:            public void testGetMappedArguments() {
371:                Object value = dynaForm.get("mappedProperty", "unknown");
372:
373:                assertNull("Should not return a value", value);
374:            }
375:
376:            /**
377:             * Positive and negative tests on getMappedProperty valid arguments.
378:             */
379:            public void testGetMappedValues() {
380:                Object value = null;
381:
382:                value = dynaForm.get("mappedProperty", "First Key");
383:                assertEquals("Can find first value", "First Value", value);
384:
385:                value = dynaForm.get("mappedProperty", "Second Key");
386:                assertEquals("Can find second value", "Second Value", value);
387:
388:                value = dynaForm.get("mappedProperty", "Third Key");
389:                assertNull("Can not find third value", value);
390:            }
391:
392:            /**
393:             * Corner cases on getSimpleProperty invalid arguments.
394:             */
395:            public void testGetSimpleArguments() {
396:                try {
397:                    dynaForm.get(null);
398:                    fail("Should throw IllegalArgumentException");
399:                } catch (IllegalArgumentException e) {
400:                    ; // Expected response
401:                }
402:            }
403:
404:            /**
405:             * Test getSimpleProperty on a boolean property.
406:             */
407:            public void testGetSimpleBoolean() {
408:                Object value = dynaForm.get("booleanProperty");
409:
410:                assertNotNull("Got a value", value);
411:                assertTrue("Got correct type", (value instanceof  Boolean));
412:                assertTrue("Got correct value", ((Boolean) value)
413:                        .booleanValue() == true);
414:            }
415:
416:            /**
417:             * Test getSimpleProperty on a double property.
418:             */
419:            public void testGetSimpleDouble() {
420:                Object value = dynaForm.get("doubleProperty");
421:
422:                assertNotNull("Got a value", value);
423:                assertTrue("Got correct type", (value instanceof  Double));
424:                assertEquals("Got correct value", ((Double) value)
425:                        .doubleValue(), (double) 321.0, (double) 0.005);
426:            }
427:
428:            /**
429:             * Test getSimpleProperty on a float property.
430:             */
431:            public void testGetSimpleFloat() {
432:                Object value = dynaForm.get("floatProperty");
433:
434:                assertNotNull("Got a value", value);
435:                assertTrue("Got correct type", (value instanceof  Float));
436:                assertEquals("Got correct value", ((Float) value).floatValue(),
437:                        (float) 123.0, (float) 0.005);
438:            }
439:
440:            /**
441:             * Test getSimpleProperty on a int property.
442:             */
443:            public void testGetSimpleInt() {
444:                Object value = dynaForm.get("intProperty");
445:
446:                assertNotNull("Got a value", value);
447:                assertTrue("Got correct type", (value instanceof  Integer));
448:                assertEquals("Got correct value", ((Integer) value).intValue(),
449:                        (int) 123);
450:            }
451:
452:            /**
453:             * Test getSimpleProperty on a long property.
454:             */
455:            public void testGetSimpleLong() {
456:                Object value = dynaForm.get("longProperty");
457:
458:                assertNotNull("Got a value", value);
459:                assertTrue("Got correct type", (value instanceof  Long));
460:                assertEquals("Got correct value", ((Long) value).longValue(),
461:                        (long) 321);
462:            }
463:
464:            /**
465:             * Test getSimpleProperty on a short property.
466:             */
467:            public void testGetSimpleShort() {
468:                Object value = dynaForm.get("shortProperty");
469:
470:                assertNotNull("Got a value", value);
471:                assertTrue("Got correct type", (value instanceof  Short));
472:                assertEquals("Got correct value", ((Short) value).shortValue(),
473:                        (short) 987);
474:            }
475:
476:            /**
477:             * Test getSimpleProperty on a String property.
478:             */
479:            public void testGetSimpleString() {
480:                Object value = dynaForm.get("stringProperty");
481:
482:                assertNotNull("Got a value", value);
483:                assertTrue("Got correct type", (value instanceof  String));
484:                assertEquals("Got correct value", (String) value,
485:                        "This is a string");
486:            }
487:
488:            /**
489:             * Test <code>contains()</code> method for mapped properties.
490:             */
491:            public void testMappedContains() {
492:                assertTrue("Can see first key", dynaForm.contains(
493:                        "mappedProperty", "First Key"));
494:
495:                assertTrue("Can not see unknown key", !dynaForm.contains(
496:                        "mappedProperty", "Unknown Key"));
497:            }
498:
499:            /**
500:             * Test <code>remove()</code> method for mapped properties.
501:             */
502:            public void testMappedRemove() {
503:                assertTrue("Can see first key", dynaForm.contains(
504:                        "mappedProperty", "First Key"));
505:                dynaForm.remove("mappedProperty", "First Key");
506:                assertTrue("Can not see first key", !dynaForm.contains(
507:                        "mappedProperty", "First Key"));
508:
509:                assertTrue("Can not see unknown key", !dynaForm.contains(
510:                        "mappedProperty", "Unknown Key"));
511:                dynaForm.remove("mappedProperty", "Unknown Key");
512:                assertTrue("Can not see unknown key", !dynaForm.contains(
513:                        "mappedProperty", "Unknown Key"));
514:            }
515:
516:            /**
517:             * Test the reset method when the request method is GET.
518:             */
519:            public void testResetGet() {
520:                // set a choice set of props with non-initial values
521:                dynaForm.set("booleanProperty", Boolean.FALSE);
522:                dynaForm.set("booleanSecond", Boolean.FALSE);
523:                dynaForm.set("doubleProperty", new Double(456.0));
524:                dynaForm.set("floatProperty", new Float((float) 456.0));
525:                dynaForm.set("intProperty", new Integer(456));
526:
527:                MockHttpServletRequest request = new MockHttpServletRequest();
528:
529:                request.setMethod("GET");
530:                dynaForm.reset(mapping, request);
531:
532:                assertEquals("booleanProperty should be reset", Boolean.TRUE,
533:                        (Boolean) dynaForm.get("booleanProperty"));
534:                assertEquals("booleanSecond should be reset", Boolean.TRUE,
535:                        (Boolean) dynaForm.get("booleanSecond"));
536:                assertEquals("doubleProperty should be reset",
537:                        new Double(321.0), (Double) dynaForm
538:                                .get("doubleProperty"));
539:                assertEquals("floatProperty should NOT be reset", new Float(
540:                        (float) 456.0), (Float) dynaForm.get("floatProperty"));
541:                assertEquals("intProperty should NOT be reset",
542:                        new Integer(456), (Integer) dynaForm.get("intProperty"));
543:            }
544:
545:            /**
546:             * Test the reset method when the request method is GET.
547:             */
548:            public void testResetPost() {
549:                // set a choice set of props with non-initial values
550:                dynaForm.set("booleanProperty", Boolean.FALSE);
551:                dynaForm.set("booleanSecond", Boolean.FALSE);
552:                dynaForm.set("doubleProperty", new Double(456.0));
553:                dynaForm.set("floatProperty", new Float((float) 456.0));
554:                dynaForm.set("intProperty", new Integer(456));
555:
556:                MockHttpServletRequest request = new MockHttpServletRequest();
557:
558:                request.setMethod("POST");
559:                dynaForm.reset(mapping, request);
560:
561:                assertEquals("booleanProperty should be reset", Boolean.TRUE,
562:                        (Boolean) dynaForm.get("booleanProperty"));
563:                assertEquals("booleanSecond should be reset", Boolean.TRUE,
564:                        (Boolean) dynaForm.get("booleanSecond"));
565:                assertEquals("doubleProperty should NOT be reset", new Double(
566:                        456), (Double) dynaForm.get("doubleProperty"));
567:                assertEquals("floatProperty should be reset", new Float(
568:                        (float) 123.0), (Float) dynaForm.get("floatProperty"));
569:                assertEquals("intProperty should NOT be reset",
570:                        new Integer(456), (Integer) dynaForm.get("intProperty"));
571:            }
572:
573:            /**
574:             * Corner cases on setIndexedProperty invalid arguments.
575:             */
576:            public void testSetIndexedArguments() {
577:                try {
578:                    dynaForm.set("intArray", -1, new Integer(0));
579:                    fail("Should throw IndexOutOfBoundsException");
580:                } catch (IndexOutOfBoundsException e) {
581:                    ; // Expected response
582:                }
583:            }
584:
585:            /**
586:             * Positive and negative tests on setIndexedProperty valid arguments.
587:             */
588:            public void testSetIndexedValues() {
589:                Object value = null;
590:
591:                dynaForm.set("intArray", 0, new Integer(1));
592:                value = (Integer) dynaForm.get("intArray", 0);
593:                assertNotNull("Returned new value 0", value);
594:                assertTrue("Returned Integer new value 0",
595:                        value instanceof  Integer);
596:                assertEquals("Returned correct new value 0", 1,
597:                        ((Integer) value).intValue());
598:
599:                dynaForm.set("intIndexed", 1, new Integer(11));
600:                value = (Integer) dynaForm.get("intIndexed", 1);
601:                assertNotNull("Returned new value 1", value);
602:                assertTrue("Returned Integer new value 1",
603:                        value instanceof  Integer);
604:                assertEquals("Returned correct new value 1", 11,
605:                        ((Integer) value).intValue());
606:                dynaForm.set("listIndexed", 2, "New Value 2");
607:                value = (String) dynaForm.get("listIndexed", 2);
608:                assertNotNull("Returned new value 2", value);
609:                assertTrue("Returned String new value 2",
610:                        value instanceof  String);
611:                assertEquals("Returned correct new value 2", "New Value 2",
612:                        (String) value);
613:
614:                dynaForm.set("stringArray", 3, "New Value 3");
615:                value = (String) dynaForm.get("stringArray", 3);
616:                assertNotNull("Returned new value 3", value);
617:                assertTrue("Returned String new value 3",
618:                        value instanceof  String);
619:                assertEquals("Returned correct new value 3", "New Value 3",
620:                        (String) value);
621:
622:                dynaForm.set("stringIndexed", 4, "New Value 4");
623:                value = (String) dynaForm.get("stringIndexed", 4);
624:                assertNotNull("Returned new value 4", value);
625:                assertTrue("Returned String new value 4",
626:                        value instanceof  String);
627:                assertEquals("Returned correct new value 4", "New Value 4",
628:                        (String) value);
629:            }
630:
631:            /**
632:             * Positive and negative tests on setMappedProperty valid arguments.
633:             */
634:            public void testSetMappedValues() {
635:                dynaForm.set("mappedProperty", "First Key", "New First Value");
636:                assertEquals("Can replace old value", "New First Value",
637:                        (String) dynaForm.get("mappedProperty", "First Key"));
638:
639:                dynaForm.set("mappedProperty", "Fourth Key", "Fourth Value");
640:                assertEquals("Can set new value", "Fourth Value",
641:                        (String) dynaForm.get("mappedProperty", "Fourth Key"));
642:            }
643:
644:            /**
645:             * Test setSimpleProperty on a boolean property.
646:             */
647:            public void testSetSimpleBoolean() {
648:                boolean oldValue = ((Boolean) dynaForm.get("booleanProperty"))
649:                        .booleanValue();
650:                boolean newValue = !oldValue;
651:
652:                dynaForm.set("booleanProperty", new Boolean(newValue));
653:                assertTrue("Matched new value", newValue == ((Boolean) dynaForm
654:                        .get("booleanProperty")).booleanValue());
655:            }
656:
657:            /**
658:             * Test setSimpleProperty on a double property.
659:             */
660:            public void testSetSimpleDouble() {
661:                double oldValue = ((Double) dynaForm.get("doubleProperty"))
662:                        .doubleValue();
663:                double newValue = oldValue + 1.0;
664:
665:                dynaForm.set("doubleProperty", new Double(newValue));
666:                assertEquals("Matched new value", newValue, ((Double) dynaForm
667:                        .get("doubleProperty")).doubleValue(), (double) 0.005);
668:            }
669:
670:            /**
671:             * Test setSimpleProperty on a float property.
672:             */
673:            public void testSetSimpleFloat() {
674:                float oldValue = ((Float) dynaForm.get("floatProperty"))
675:                        .floatValue();
676:                float newValue = oldValue + (float) 1.0;
677:
678:                dynaForm.set("floatProperty", new Float(newValue));
679:                assertEquals("Matched new value", newValue, ((Float) dynaForm
680:                        .get("floatProperty")).floatValue(), (float) 0.005);
681:            }
682:
683:            /**
684:             * Test setSimpleProperty on a int property.
685:             */
686:            public void testSetSimpleInt() {
687:                int oldValue = ((Integer) dynaForm.get("intProperty"))
688:                        .intValue();
689:                int newValue = oldValue + 1;
690:
691:                dynaForm.set("intProperty", new Integer(newValue));
692:                assertEquals("Matched new value", newValue, ((Integer) dynaForm
693:                        .get("intProperty")).intValue());
694:            }
695:
696:            /**
697:             * Test setSimpleProperty on a long property.
698:             */
699:            public void testSetSimpleLong() {
700:                long oldValue = ((Long) dynaForm.get("longProperty"))
701:                        .longValue();
702:                long newValue = oldValue + 1;
703:
704:                dynaForm.set("longProperty", new Long(newValue));
705:                assertEquals("Matched new value", newValue, ((Long) dynaForm
706:                        .get("longProperty")).longValue());
707:            }
708:
709:            /**
710:             * Test setSimpleProperty on a short property.
711:             */
712:            public void testSetSimpleShort() {
713:                short oldValue = ((Short) dynaForm.get("shortProperty"))
714:                        .shortValue();
715:                short newValue = (short) (oldValue + 1);
716:
717:                dynaForm.set("shortProperty", new Short(newValue));
718:                assertEquals("Matched new value", newValue, ((Short) dynaForm
719:                        .get("shortProperty")).shortValue());
720:            }
721:
722:            /**
723:             * Test setSimpleProperty on a String property.
724:             */
725:            public void testSetSimpleString() {
726:                String oldValue = (String) dynaForm.get("stringProperty");
727:                String newValue = oldValue + " Extra Value";
728:
729:                dynaForm.set("stringProperty", newValue);
730:                assertEquals("Matched new value", newValue, (String) dynaForm
731:                        .get("stringProperty"));
732:            }
733:
734:            // ------------------------------------------------------ Protected Methods
735:
736:            /**
737:             * Set up the complex properties that cannot be configured from the
738:             * initial value expression.
739:             */
740:            protected void setupComplexProperties() {
741:                List listIndexed = new ArrayList();
742:
743:                listIndexed.add("String 0");
744:                listIndexed.add("String 1");
745:                listIndexed.add("String 2");
746:                listIndexed.add("String 3");
747:                listIndexed.add("String 4");
748:                dynaForm.set("listIndexed", listIndexed);
749:
750:                Map mappedProperty = new HashMap();
751:
752:                mappedProperty.put("First Key", "First Value");
753:                mappedProperty.put("Second Key", "Second Value");
754:                dynaForm.set("mappedProperty", mappedProperty);
755:
756:                Map mappedIntProperty = new HashMap();
757:
758:                mappedIntProperty.put("One", new Integer(1));
759:                mappedIntProperty.put("Two", new Integer(2));
760:                dynaForm.set("mappedIntProperty", mappedIntProperty);
761:            }
762:
763:            /**
764:             * Base for testGetDescriptorXxxxx() series of tests.
765:             *
766:             * @param name Name of the property to be retrieved
767:             * @param type Expected class type of this property
768:             */
769:            protected void testGetDescriptorBase(String name, Class type) {
770:                DynaProperty descriptor = dynaForm.getDynaClass()
771:                        .getDynaProperty(name);
772:
773:                assertNotNull("Got descriptor", descriptor);
774:                assertEquals("Got correct type", type, descriptor.getType());
775:            }
776:        }
777:
778:        class DynaActionFormMapping extends ActionMapping {
779:            private ModuleConfig appConfig = null;
780:
781:            public DynaActionFormMapping(ModuleConfig appConfig) {
782:                this .appConfig = appConfig;
783:            }
784:
785:            public ModuleConfig getModuleConfig() {
786:                return (this .appConfig);
787:            }
788:
789:            public String getName() {
790:                return ("dynaForm");
791:            }
792:        }
793:
794:        class DynaActionFormConfig extends ModuleConfigImpl {
795:            private FormBeanConfig beanConfig = null;
796:
797:            public DynaActionFormConfig(FormBeanConfig beanConfig) {
798:                super ("");
799:                this .beanConfig = beanConfig;
800:            }
801:
802:            public FormBeanConfig findFormBeanConfig(String name) {
803:                return (this.beanConfig);
804:            }
805:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.