Source Code Cross Referenced for DefaultConfigurationTestCase.java in  » Inversion-of-Control » DNA » org » codehaus » dna » impl » 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 » Inversion of Control » DNA » org.codehaus.dna.impl 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright (C) The DNA Group. All rights reserved.
003:         *
004:         * This software is published under the terms of the DNA
005:         * Software License version 1.1, a copy of which has been included
006:         * with this distribution in the LICENSE.txt file.
007:         */
008:        package org.codehaus.dna.impl;
009:
010:        import java.util.Map;
011:        import junit.framework.TestCase;
012:
013:        import org.codehaus.dna.Configuration;
014:        import org.codehaus.dna.ConfigurationException;
015:        import org.codehaus.dna.impl.DefaultConfiguration;
016:
017:        public class DefaultConfigurationTestCase extends TestCase {
018:            public void testBasicConfigurationElement() throws Exception {
019:                final String name = "myElement";
020:                final String location = "file.xml:20";
021:                final String path = "";
022:                final DefaultConfiguration configuration = new DefaultConfiguration(
023:                        name, location, path);
024:                assertEquals("name", name, configuration.getName());
025:                assertEquals("location", location, configuration.getLocation());
026:                assertEquals("path", path, configuration.getPath());
027:            }
028:
029:            public void testNullNameInCtor() throws Exception {
030:                final String name = null;
031:                final String location = "file.xml:20";
032:                final String path = "";
033:                try {
034:                    new DefaultConfiguration(name, location, path);
035:                } catch (final NullPointerException npe) {
036:                    assertEquals("name", npe.getMessage());
037:                    return;
038:                }
039:                fail("Expected null pointer exception as passed in null to ctor.");
040:            }
041:
042:            public void testNullLocationInCtor() throws Exception {
043:                final String name = "name";
044:                final String location = null;
045:                final String path = "";
046:                try {
047:                    new DefaultConfiguration(name, location, path);
048:                } catch (final NullPointerException npe) {
049:                    assertEquals("location", npe.getMessage());
050:                    return;
051:                }
052:                fail("Expected null pointer exception as passed in null to ctor.");
053:            }
054:
055:            public void testNullPathInCtor() throws Exception {
056:                final String name = "name";
057:                final String location = "";
058:                final String path = null;
059:                try {
060:                    new DefaultConfiguration(name, location, path);
061:                } catch (final NullPointerException npe) {
062:                    assertEquals("path", npe.getMessage());
063:                    return;
064:                }
065:                fail("Expected null pointer exception as passed in null to ctor.");
066:            }
067:
068:            public void testNullNameInSetAttribute() throws Exception {
069:                final DefaultConfiguration configuration = new DefaultConfiguration(
070:                        "name", "", "");
071:                try {
072:                    configuration.setAttribute(null, "");
073:                } catch (final NullPointerException npe) {
074:                    assertEquals("key", npe.getMessage());
075:                    return;
076:                }
077:                fail("Expected null pointer exception as passed in null to setAttribute.");
078:            }
079:
080:            public void testNullValueInSetAttribute() throws Exception {
081:                final DefaultConfiguration configuration = new DefaultConfiguration(
082:                        "name", "", "");
083:                try {
084:                    configuration.setAttribute("", null);
085:                } catch (final NullPointerException npe) {
086:                    assertEquals("value", npe.getMessage());
087:                    return;
088:                }
089:                fail("Expected null pointer exception as passed in null to setAttribute.");
090:            }
091:
092:            public void testNullValueInSetValue() throws Exception {
093:                final DefaultConfiguration configuration = new DefaultConfiguration(
094:                        "name", "", "");
095:                try {
096:                    configuration.setValue(null);
097:                } catch (final NullPointerException npe) {
098:                    assertEquals("value", npe.getMessage());
099:                    return;
100:                }
101:                fail("Expected null pointer exception as passed in null to setValue.");
102:            }
103:
104:            public void testNullChildinAddChild() throws Exception {
105:                final DefaultConfiguration configuration = new DefaultConfiguration(
106:                        "name", "", "");
107:                try {
108:                    configuration.addChild(null);
109:                } catch (final NullPointerException npe) {
110:                    assertEquals("configuration", npe.getMessage());
111:                    return;
112:                }
113:                fail("Expected null pointer exception as passed in null to addChild.");
114:            }
115:
116:            public void testNullNameInGetAttribute() throws Exception {
117:                final DefaultConfiguration configuration = new DefaultConfiguration(
118:                        "name", "", "");
119:                try {
120:                    configuration.getAttribute(null);
121:                } catch (final NullPointerException npe) {
122:                    assertEquals("name", npe.getMessage());
123:                    return;
124:                }
125:                fail("Expected null pointer exception as passed in null to getAttribute.");
126:            }
127:
128:            public void testNullNameInGetChild() throws Exception {
129:                final DefaultConfiguration configuration = new DefaultConfiguration(
130:                        "name", "", "");
131:                try {
132:                    configuration.getChild(null, false);
133:                } catch (final NullPointerException npe) {
134:                    assertEquals("name", npe.getMessage());
135:                    return;
136:                }
137:                fail("Expected null pointer exception as passed in null to getChild.");
138:            }
139:
140:            public void testNullNameInGetChildren() throws Exception {
141:                final DefaultConfiguration configuration = new DefaultConfiguration(
142:                        "name", "", "");
143:                try {
144:                    configuration.getChildren(null);
145:                } catch (final NullPointerException npe) {
146:                    assertEquals("name", npe.getMessage());
147:                    return;
148:                }
149:                fail("Expected null pointer exception as passed in null to getChildren.");
150:            }
151:
152:            public void testGetValueAsText() throws Exception {
153:                final DefaultConfiguration configuration = new DefaultConfiguration(
154:                        "myElement", "file.xml:20", "");
155:                final String value = "blah";
156:                configuration.setValue(value);
157:                assertEquals("getValue()", value, configuration.getValue());
158:                assertEquals("getValue('test')", value, configuration
159:                        .getValue("test"));
160:            }
161:
162:            public void testGetNullValueAsText() throws Exception {
163:                final DefaultConfiguration configuration = new DefaultConfiguration(
164:                        "myElement", "file.xml:20", "");
165:                assertEquals("getValue('test')", "test", configuration
166:                        .getValue("test"));
167:                try {
168:                    configuration.getValue();
169:                } catch (ConfigurationException e) {
170:                    return;
171:                }
172:                fail("Expected getValue() to throw an exception");
173:            }
174:
175:            public void testGetValueAsBoolean() throws Exception {
176:                final DefaultConfiguration configuration = new DefaultConfiguration(
177:                        "myElement", "file.xml:20", "");
178:                configuration.setValue("true");
179:                assertEquals("getValue()", true, configuration
180:                        .getValueAsBoolean());
181:                assertEquals("getValue('false')", true, configuration
182:                        .getValueAsBoolean(false));
183:            }
184:
185:            public void testGetNullValueAsBoolean() throws Exception {
186:                final DefaultConfiguration configuration = new DefaultConfiguration(
187:                        "myElement", "file.xml:20", "");
188:                assertEquals("getValue('false')", false, configuration
189:                        .getValueAsBoolean(false));
190:                try {
191:                    configuration.getValueAsBoolean();
192:                } catch (ConfigurationException e) {
193:                    return;
194:                }
195:                fail("Expected getValue() to throw an exception");
196:            }
197:
198:            public void testGetValueAsInteger() throws Exception {
199:                final DefaultConfiguration configuration = new DefaultConfiguration(
200:                        "myElement", "file.xml:20", "");
201:                configuration.setValue("3");
202:                assertEquals("getValue()", 3, configuration.getValueAsInteger());
203:                assertEquals("getValue('1')", 3, configuration
204:                        .getValueAsInteger(1));
205:            }
206:
207:            public void testGetNullValueAsInteger() throws Exception {
208:                final DefaultConfiguration configuration = new DefaultConfiguration(
209:                        "myElement", "file.xml:20", "");
210:                assertEquals("getValue('1')", 1, configuration
211:                        .getValueAsInteger(1));
212:                try {
213:                    configuration.getValueAsInteger();
214:                } catch (ConfigurationException e) {
215:                    return;
216:                }
217:                fail("Expected getValue() to throw an exception");
218:            }
219:
220:            public void testGetMalformedValueAsInteger() throws Exception {
221:                final DefaultConfiguration configuration = new DefaultConfiguration(
222:                        "myElement", "file.xml:20", "");
223:                configuration.setValue("malformed");
224:                assertEquals("getValue('1')", 1, configuration
225:                        .getValueAsInteger(1));
226:                try {
227:                    configuration.getValueAsInteger();
228:                } catch (ConfigurationException e) {
229:                    return;
230:                }
231:                fail("Expected getValue() to throw an exception");
232:            }
233:
234:            public void testGetValueAsLong() throws Exception {
235:                final DefaultConfiguration configuration = new DefaultConfiguration(
236:                        "myElement", "file.xml:20", "");
237:                configuration.setValue("3");
238:                assertEquals("getValue()", 3, configuration.getValueAsLong());
239:                assertEquals("getValue('1')", 3, configuration
240:                        .getValueAsLong(1));
241:            }
242:
243:            public void testGetNullValueAsLong() throws Exception {
244:                final DefaultConfiguration configuration = new DefaultConfiguration(
245:                        "myElement", "file.xml:20", "");
246:                assertEquals("getValue('1')", 1, configuration
247:                        .getValueAsLong(1));
248:                try {
249:                    configuration.getValueAsLong();
250:                } catch (ConfigurationException e) {
251:                    return;
252:                }
253:                fail("Expected getValue() to throw an exception");
254:            }
255:
256:            public void testGetMalformedValueAsLong() throws Exception {
257:                final DefaultConfiguration configuration = new DefaultConfiguration(
258:                        "myElement", "file.xml:20", "");
259:                configuration.setValue("malformed");
260:                assertEquals("getValue('1')", 1, configuration
261:                        .getValueAsLong(1));
262:                try {
263:                    configuration.getValueAsLong();
264:                } catch (ConfigurationException e) {
265:                    return;
266:                }
267:                fail("Expected getValue() to throw an exception");
268:            }
269:
270:            public void testGetValueAsFloat() throws Exception {
271:                final DefaultConfiguration configuration = new DefaultConfiguration(
272:                        "myElement", "file.xml:20", "");
273:                configuration.setValue("3.0");
274:                assertTrue("getValue()", 3.0 == configuration.getValueAsFloat());
275:                assertTrue("getValue('1')", 3.0 == configuration
276:                        .getValueAsFloat(1));
277:            }
278:
279:            public void testGetNullValueAsFloat() throws Exception {
280:                final DefaultConfiguration configuration = new DefaultConfiguration(
281:                        "myElement", "file.xml:20", "");
282:                assertTrue("getValue('1')", 1.0 == configuration
283:                        .getValueAsFloat(1));
284:                try {
285:                    configuration.getValueAsFloat();
286:                } catch (ConfigurationException e) {
287:                    return;
288:                }
289:                fail("Expected getValue() to throw an exception");
290:            }
291:
292:            public void testGetMalformedValueAsFloat() throws Exception {
293:                final DefaultConfiguration configuration = new DefaultConfiguration(
294:                        "myElement", "file.xml:20", "");
295:                configuration.setValue("malformed");
296:                assertTrue("getValue('1')", 1.0 == configuration
297:                        .getValueAsFloat(1));
298:                try {
299:                    configuration.getValueAsFloat();
300:                } catch (ConfigurationException e) {
301:                    return;
302:                }
303:                fail("Expected getValue() to throw an exception");
304:            }
305:
306:            public void testGetAttributeAsText() throws Exception {
307:                final DefaultConfiguration configuration = new DefaultConfiguration(
308:                        "myElement", "file.xml:20", "");
309:                final String key = "key";
310:                final String value = "value";
311:                configuration.setAttribute(key, value);
312:                assertEquals("getAttribute('key')", value, configuration
313:                        .getAttribute(key));
314:                assertEquals("getAttribute('key','defaultValue')", value,
315:                        configuration.getAttribute(key, "defaultValue"));
316:            }
317:
318:            public void testGetMissingAttributeAsText() throws Exception {
319:                final DefaultConfiguration configuration = new DefaultConfiguration(
320:                        "myElement", "file.xml:20", "");
321:                final String key = "key";
322:                configuration.setAttribute("AnotherKey", "someValue");
323:                assertEquals("getAttribute('key','defaultValue')",
324:                        "defaultValue", configuration.getAttribute(key,
325:                                "defaultValue"));
326:
327:                try {
328:                    configuration.getAttribute(key);
329:                } catch (ConfigurationException e) {
330:                    return;
331:                }
332:                fail("Expected to fail with getAttribute for non existent key");
333:            }
334:
335:            public void testGetAttributeAsBoolean() throws Exception {
336:                final DefaultConfiguration configuration = new DefaultConfiguration(
337:                        "myElement", "file.xml:20", "");
338:                final String key = "key";
339:                final String value = "true";
340:                configuration.setAttribute(key, value);
341:                assertEquals("getAttribute('key')", true, configuration
342:                        .getAttributeAsBoolean(key));
343:                assertEquals("getAttribute('key','false')", true, configuration
344:                        .getAttributeAsBoolean(key, false));
345:            }
346:
347:            public void testGetMissingAttributeAsBoolean() throws Exception {
348:                final DefaultConfiguration configuration = new DefaultConfiguration(
349:                        "myElement", "file.xml:20", "");
350:                final String key = "key";
351:                assertEquals("getAttribute('key','false')", false,
352:                        configuration.getAttributeAsBoolean(key, false));
353:                try {
354:                    configuration.getAttribute(key);
355:                } catch (ConfigurationException e) {
356:                    return;
357:                }
358:                fail("Expected to fail with getAttribute for non existent key");
359:            }
360:
361:            public void testGetAttributeAsInteger() throws Exception {
362:                final DefaultConfiguration configuration = new DefaultConfiguration(
363:                        "myElement", "file.xml:20", "");
364:                final String key = "key";
365:                final String value = "3";
366:                configuration.setAttribute(key, value);
367:                assertEquals("getAttribute('key')", 3, configuration
368:                        .getAttributeAsInteger(key));
369:                assertEquals("getAttribute('key','1')", 3, configuration
370:                        .getAttributeAsInteger(key, 1));
371:            }
372:
373:            public void testGetMissingAttributeAsInteger() throws Exception {
374:                final DefaultConfiguration configuration = new DefaultConfiguration(
375:                        "myElement", "file.xml:20", "");
376:                final String key = "key";
377:                assertEquals("getAttribute('key','defaultValue')", 1,
378:                        configuration.getAttributeAsInteger(key, 1));
379:
380:                try {
381:                    configuration.getAttributeAsInteger(key);
382:                } catch (ConfigurationException e) {
383:                    return;
384:                }
385:                fail("Expected to fail with getAttribute for non existent key");
386:            }
387:
388:            public void testGetMalformedAttributeAsInteger() throws Exception {
389:                final DefaultConfiguration configuration = new DefaultConfiguration(
390:                        "myElement", "file.xml:20", "");
391:                final String key = "key";
392:                final String value = "malformed";
393:                configuration.setAttribute(key, value);
394:                assertEquals("getAttribute('key','defaultValue')", 1,
395:                        configuration.getAttributeAsInteger(key, 1));
396:
397:                try {
398:                    configuration.getAttributeAsInteger(key);
399:                } catch (ConfigurationException e) {
400:                    return;
401:                }
402:                fail("Expected to fail with getAttribute for malformed attribute");
403:            }
404:
405:            public void testGetAttributeAsLong() throws Exception {
406:                final DefaultConfiguration configuration = new DefaultConfiguration(
407:                        "myElement", "file.xml:20", "");
408:                final String key = "key";
409:                final String value = "3";
410:                configuration.setAttribute(key, value);
411:                assertEquals("getAttribute('key')", 3, configuration
412:                        .getAttributeAsLong(key));
413:                assertEquals("getAttribute('key','1')", 3, configuration
414:                        .getAttributeAsLong(key, 1));
415:            }
416:
417:            public void testGetMissingAttributeAsLong() throws Exception {
418:                final DefaultConfiguration configuration = new DefaultConfiguration(
419:                        "myElement", "file.xml:20", "");
420:                final String key = "key";
421:                assertEquals("getAttribute('key','1')", 1, configuration
422:                        .getAttributeAsLong(key, 1));
423:
424:                try {
425:                    configuration.getAttributeAsLong(key);
426:                } catch (ConfigurationException e) {
427:                    return;
428:                }
429:                fail("Expected to fail with getAttribute for non existent key");
430:            }
431:
432:            public void testGetMalformedAttributeAsLong() throws Exception {
433:                final DefaultConfiguration configuration = new DefaultConfiguration(
434:                        "myElement", "file.xml:20", "");
435:                final String key = "key";
436:                final String value = "malformed";
437:                configuration.setAttribute(key, value);
438:                assertEquals("getAttribute('key','1')", 1, configuration
439:                        .getAttributeAsLong(key, 1));
440:
441:                try {
442:                    configuration.getAttributeAsLong(key);
443:                } catch (ConfigurationException e) {
444:                    return;
445:                }
446:                fail("Expected to fail with getAttribute for malformed attribute");
447:            }
448:
449:            public void testGetAttributeAsFloat() throws Exception {
450:                final DefaultConfiguration configuration = new DefaultConfiguration(
451:                        "myElement", "file.xml:20", "");
452:                final String key = "key";
453:                final String value = "3";
454:                configuration.setAttribute(key, value);
455:                assertTrue("getAttribute('key')", 3.0 == configuration
456:                        .getAttributeAsFloat(key));
457:                assertTrue("getAttribute('key','1')", 3.0 == configuration
458:                        .getAttributeAsFloat(key, 1));
459:            }
460:
461:            public void testGetMissingAttributeAsFloat() throws Exception {
462:                final DefaultConfiguration configuration = new DefaultConfiguration(
463:                        "myElement", "file.xml:20", "");
464:                final String key = "key";
465:                assertTrue("getAttribute('key','defaultValue')",
466:                        1.0 == configuration.getAttributeAsFloat(key, 1));
467:
468:                try {
469:                    configuration.getAttributeAsFloat(key);
470:                } catch (ConfigurationException e) {
471:                    return;
472:                }
473:                fail("Expected to fail with getAttribute for non existent key");
474:            }
475:
476:            public void testGetMalformedAttributeAsFloat() throws Exception {
477:                final DefaultConfiguration configuration = new DefaultConfiguration(
478:                        "myElement", "file.xml:20", "");
479:                final String key = "key";
480:                final String value = "malformed";
481:                configuration.setAttribute(key, value);
482:                assertTrue("getAttribute('key','defaultValue')",
483:                        1.0 == configuration.getAttributeAsFloat(key, 1));
484:
485:                try {
486:                    configuration.getAttributeAsFloat(key);
487:                } catch (ConfigurationException e) {
488:                    return;
489:                }
490:                fail("Expected to fail with getAttribute for malformed attribute");
491:            }
492:
493:            public void testGetAttributes() throws Exception {
494:                final DefaultConfiguration configuration = new DefaultConfiguration(
495:                        "myElement", "file.xml:20", "");
496:                configuration.setAttribute("key1", "value1");
497:                configuration.setAttribute("key2", "value2");
498:
499:                final String[] names = configuration.getAttributeNames();
500:                assertEquals("names.length", 2, names.length);
501:            }
502:
503:            public void testGetAttributesWithNoAttributesSet() throws Exception {
504:                final DefaultConfiguration configuration = new DefaultConfiguration(
505:                        "myElement", "file.xml:20", "");
506:
507:                final String[] names = configuration.getAttributeNames();
508:                assertEquals("names.length", 0, names.length);
509:            }
510:
511:            public void testGetChildren() throws Exception {
512:                final DefaultConfiguration configuration = new DefaultConfiguration(
513:                        "myElement", "file.xml:20", "");
514:                final DefaultConfiguration child = new DefaultConfiguration(
515:                        "mychild", "file.xml:20", "/myElement");
516:
517:                configuration.addChild(child);
518:
519:                final Configuration[] children = configuration.getChildren();
520:                assertEquals("children.length", 1, children.length);
521:                assertEquals("children[0]", child, children[0]);
522:            }
523:
524:            public void testGetChildrenWithNoChildren() throws Exception {
525:                final DefaultConfiguration configuration = new DefaultConfiguration(
526:                        "myElement", "file.xml:20", "");
527:
528:                final Configuration[] children = configuration.getChildren();
529:                assertEquals("children.length", 0, children.length);
530:            }
531:
532:            public void testGetChild() throws Exception {
533:                final DefaultConfiguration configuration = new DefaultConfiguration(
534:                        "myElement", "file.xml:20", "");
535:                final DefaultConfiguration child = new DefaultConfiguration(
536:                        "mychild", "file.xml:20", "/myElement");
537:                configuration.addChild(child);
538:
539:                final Configuration test = configuration.getChild("mychild");
540:                assertEquals(child, test);
541:            }
542:
543:            public void testGetNotExistentChildWithNoAutoCreateButOtherChildren()
544:                    throws Exception {
545:                final DefaultConfiguration configuration = new DefaultConfiguration(
546:                        "myElement", "file.xml:20", "");
547:
548:                final DefaultConfiguration child = new DefaultConfiguration(
549:                        "meep", "file.xml:20", "/myElement");
550:                configuration.addChild(child);
551:
552:                final Configuration test = configuration.getChild("mychild",
553:                        false);
554:                assertEquals(null, test);
555:            }
556:
557:            public void testGetNotExistentChildWithNoAutoCreate()
558:                    throws Exception {
559:                final DefaultConfiguration configuration = new DefaultConfiguration(
560:                        "myElement", "file.xml:20", "");
561:
562:                final Configuration test = configuration.getChild("mychild",
563:                        false);
564:                assertEquals(null, test);
565:            }
566:
567:            public void testGetNotExistentChildWithAutoCreate()
568:                    throws Exception {
569:                final DefaultConfiguration configuration = new DefaultConfiguration(
570:                        "myElement", "file.xml:20", "");
571:
572:                final Configuration test = configuration.getChild("mychild",
573:                        true);
574:                assertNotNull(test);
575:                assertEquals("mychild", test.getName());
576:            }
577:
578:            public void testGuardAgainstMixedContentWhenAddingValue()
579:                    throws Exception {
580:                final DefaultConfiguration configuration = new DefaultConfiguration(
581:                        "myElement", "file.xml:20", "");
582:                final DefaultConfiguration child = new DefaultConfiguration(
583:                        "mychild", "file.xml:20", "/myElement");
584:                configuration.addChild(child);
585:
586:                try {
587:                    configuration.setValue("blah");
588:                } catch (IllegalStateException e) {
589:                    return;
590:                }
591:                fail("Expected to fail setting mixed content for configuration");
592:            }
593:
594:            public void testGuardAgainstMixedContentWhenAddingChild()
595:                    throws Exception {
596:                final DefaultConfiguration configuration = new DefaultConfiguration(
597:                        "myElement", "file.xml:20", "");
598:                final DefaultConfiguration child = new DefaultConfiguration(
599:                        "mychild", "file.xml:20", "/myElement");
600:                configuration.setValue("blah");
601:
602:                try {
603:                    configuration.addChild(child);
604:                } catch (IllegalStateException e) {
605:                    return;
606:                }
607:                fail("Expected to fail setting mixed content for configuration");
608:            }
609:
610:            public void testGetChildrenWithName() throws Exception {
611:                final DefaultConfiguration configuration = new DefaultConfiguration(
612:                        "myElement", "file.xml:20", "");
613:                final DefaultConfiguration child1 = new DefaultConfiguration(
614:                        "mychild", "file.xml:20", "/myElement");
615:                final DefaultConfiguration child2 = new DefaultConfiguration(
616:                        "blah", "file.xml:20", "/myElement");
617:                final DefaultConfiguration child3 = new DefaultConfiguration(
618:                        "myOtherChild", "file.xml:20", "/myElement");
619:
620:                configuration.addChild(child1);
621:                configuration.addChild(child2);
622:                configuration.addChild(child3);
623:
624:                final Configuration[] children = configuration
625:                        .getChildren("mychild");
626:                assertEquals("children.length", 1, children.length);
627:            }
628:
629:            public void testGetChildrenWithNameAndNoExistingChildren()
630:                    throws Exception {
631:                final DefaultConfiguration configuration = new DefaultConfiguration(
632:                        "myElement", "file.xml:20", "");
633:
634:                final Configuration[] children = configuration
635:                        .getChildren("mychild");
636:                assertEquals("children.length", 0, children.length);
637:            }
638:
639:            public void testAutogeneratePath() throws Exception {
640:                final DefaultConfiguration configuration = new DefaultConfiguration(
641:                        "myElement", "file.xml:20", "");
642:
643:                final Configuration child = configuration.getChild("test")
644:                        .getChild("blah");
645:                assertEquals("child.path", "/myElement/test", child.getPath());
646:                assertTrue("child.location", child.getLocation().endsWith(
647:                        "<autogen>"));
648:            }
649:
650:            public void testMakeReadOnlyWithNoChildren() throws Exception {
651:                final DefaultConfiguration configuration = new DefaultConfiguration(
652:                        "myElement", "file.xml:20", "");
653:                configuration.makeReadOnly();
654:                assertTrue("configuration.isReadOnly()", configuration
655:                        .isReadOnly());
656:            }
657:
658:            public void testMakeReadOnlyWithChildren() throws Exception {
659:                final DefaultConfiguration configuration = new DefaultConfiguration(
660:                        "myElement", "file.xml:20", "");
661:
662:                final DefaultConfiguration child = new DefaultConfiguration(
663:                        "child", "file.xml:20", "/myElement");
664:                configuration.addChild(child);
665:
666:                configuration.makeReadOnly();
667:                assertTrue("configuration.isReadOnly()", configuration
668:                        .isReadOnly());
669:                assertTrue("child.isReadOnly()", child.isReadOnly());
670:            }
671:
672:            public void testMakeReadOnlyWithNonFreezableChildren()
673:                    throws Exception {
674:                final DefaultConfiguration configuration = new DefaultConfiguration(
675:                        "myElement", "file.xml:20", "");
676:
677:                configuration.addChild(new MockConfiguration());
678:
679:                configuration.makeReadOnly();
680:                assertTrue("configuration.isReadOnly()", configuration
681:                        .isReadOnly());
682:            }
683:
684:            public void testToString() throws Exception {
685:                final DefaultConfiguration configuration = new DefaultConfiguration(
686:                        "myElement", "file.xml:20", "");
687:
688:                final String expected = "[Configuration name='myElement']";
689:                final String string = configuration.toString();
690:                assertEquals(expected, string);
691:            }
692:
693:            public void testToStringWithAttributes() throws Exception {
694:                final DefaultConfiguration configuration = new DefaultConfiguration(
695:                        "myElement", "file.xml:20", "");
696:                configuration.setAttribute("key", "value");
697:                final Map attributeMap = configuration.getAttributeMap();
698:
699:                final String expected = "[Configuration name='myElement' attributes="
700:                        + attributeMap + "]";
701:                final String string = configuration.toString();
702:                assertEquals(expected, string);
703:            }
704:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.