Source Code Cross Referenced for TestOverrideCombiner.java in  » Library » Apache-commons-configuration-1.4-src » org » apache » commons » configuration » tree » 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 » Library » Apache commons configuration 1.4 src » org.apache.commons.configuration.tree 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Licensed to the Apache Software Foundation (ASF) under one or more
003:         * contributor license agreements.  See the NOTICE file distributed with
004:         * this work for additional information regarding copyright ownership.
005:         * The ASF licenses this file to You under the Apache License, Version 2.0
006:         * (the "License"); you may not use this file except in compliance with
007:         * the License.  You may obtain a copy of the License at
008:         *
009:         *     http://www.apache.org/licenses/LICENSE-2.0
010:         *
011:         * Unless required by applicable law or agreed to in writing, software
012:         * distributed under the License is distributed on an "AS IS" BASIS,
013:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014:         * See the License for the specific language governing permissions and
015:         * limitations under the License.
016:         */
017:        package org.apache.commons.configuration.tree;
018:
019:        import java.util.List;
020:
021:        import org.apache.commons.configuration.ConfigurationException;
022:        import org.apache.commons.configuration.HierarchicalConfiguration;
023:
024:        /**
025:         * Test class for OverrideCombiner.
026:         *
027:         * @version $Id: TestOverrideCombiner.java 439648 2006-09-02 20:42:10Z oheger $
028:         */
029:        public class TestOverrideCombiner extends AbstractCombinerTest {
030:            /**
031:             * Creates the combiner.
032:             *
033:             * @return the combiner
034:             */
035:            protected NodeCombiner createCombiner() {
036:                return new OverrideCombiner();
037:            }
038:
039:            /**
040:             * Tests combination of simple elements.
041:             */
042:            public void testSimpleValues() throws ConfigurationException {
043:                HierarchicalConfiguration config = createCombinedConfiguration();
044:                assertEquals("Wrong number of bgcolors", 0, config
045:                        .getMaxIndex("gui.bgcolor"));
046:                assertEquals("Wrong bgcolor", "green", config
047:                        .getString("gui.bgcolor"));
048:                assertEquals("Wrong selcolor", "yellow", config
049:                        .getString("gui.selcolor"));
050:                assertEquals("Wrong fgcolor", "blue", config
051:                        .getString("gui.fgcolor"));
052:                assertEquals("Wrong level", 1, config.getInt("gui.level"));
053:            }
054:
055:            /**
056:             * Tests combination of attributes.
057:             */
058:            public void testAttributes() throws ConfigurationException {
059:                HierarchicalConfiguration config = createCombinedConfiguration();
060:                assertEquals("Wrong value of min attribute", 1, config
061:                        .getInt("gui.level[@min]"));
062:                assertEquals("Wrong value of default attribute", 2, config
063:                        .getInt("gui.level[@default]"));
064:                assertEquals("Wrong number of id attributes", 0, config
065:                        .getMaxIndex("database.tables.table(0)[@id]"));
066:                assertEquals("Wrong value of table id", 1, config
067:                        .getInt("database.tables.table(0)[@id]"));
068:            }
069:
070:            /**
071:             * Tests whether property values are correctly overridden.
072:             */
073:            public void testOverrideValues() throws ConfigurationException {
074:                HierarchicalConfiguration config = createCombinedConfiguration();
075:                assertEquals("Wrong user", "Admin", config
076:                        .getString("base.services.security.login.user"));
077:                assertEquals("Wrong user type", "default", config
078:                        .getString("base.services.security.login.user[@type]"));
079:                assertEquals("Wrong password", "BeamMeUp", config
080:                        .getString("base.services.security.login.passwd"));
081:                assertEquals(
082:                        "Wrong password type",
083:                        "secret",
084:                        config
085:                                .getString("base.services.security.login.passwd[@type]"));
086:            }
087:
088:            /**
089:             * Tests if a list from the first node structure overrides a list in the
090:             * second structure.
091:             */
092:            public void testListFromFirstStructure()
093:                    throws ConfigurationException {
094:                HierarchicalConfiguration config = createCombinedConfiguration();
095:                assertEquals("Wrong number of services", 0, config
096:                        .getMaxIndex("net.service.url"));
097:                assertEquals("Wrong service", "http://service1.org", config
098:                        .getString("net.service.url"));
099:                assertFalse("Type attribute available", config
100:                        .containsKey("net.service.url[@type]"));
101:            }
102:
103:            /**
104:             * Tests if a list from the second structure is added if it is not defined
105:             * in the first structure.
106:             */
107:            public void testListFromSecondStructure()
108:                    throws ConfigurationException {
109:                HierarchicalConfiguration config = createCombinedConfiguration();
110:                assertEquals("Wrong number of servers", 3, config
111:                        .getMaxIndex("net.server.url"));
112:                assertEquals("Wrong server", "http://testsvr.com", config
113:                        .getString("net.server.url(2)"));
114:            }
115:
116:            /**
117:             * Tests the combination of the table structure. Because the table node is
118:             * not declared as a list node the structures will be combined. But this
119:             * won't make any difference because the values in the first table override
120:             * the values in the second table. Only the node for the table element will
121:             * be a ViewNode.
122:             */
123:            public void testCombinedTableNoList() throws ConfigurationException {
124:                ConfigurationNode tabNode = checkTable(createCombinedConfiguration());
125:                assertTrue("Node is not a view node",
126:                        tabNode instanceof  ViewNode);
127:            }
128:
129:            /**
130:             * Tests the combination of the table structure when the table node is
131:             * declared as a list node. In this case the first table structure
132:             * completely overrides the second and will be directly added to the
133:             * resulting structure.
134:             */
135:            public void testCombinedTableList() throws ConfigurationException {
136:                combiner.addListNode("table");
137:                ConfigurationNode tabNode = checkTable(createCombinedConfiguration());
138:                assertFalse("Node is a view node", tabNode instanceof  ViewNode);
139:            }
140:
141:            /**
142:             * Helper method for checking the combined table structure.
143:             *
144:             * @param config the config
145:             * @return the node for the table element
146:             */
147:            private ConfigurationNode checkTable(
148:                    HierarchicalConfiguration config) {
149:                assertEquals("Wrong number of tables", 0, config
150:                        .getMaxIndex("database.tables.table"));
151:                HierarchicalConfiguration c = config
152:                        .configurationAt("database.tables.table");
153:                assertEquals("Wrong table name", "documents", c
154:                        .getString("name"));
155:                assertEquals("Wrong number of fields", 2, c
156:                        .getMaxIndex("fields.field.name"));
157:                assertEquals("Wrong field", "docname", c
158:                        .getString("fields.field(1).name"));
159:
160:                List nds = config.getExpressionEngine().query(config.getRoot(),
161:                        "database.tables.table");
162:                assertFalse("No node found", nds.isEmpty());
163:                return (ConfigurationNode) nds.get(0);
164:            }
165:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.