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


001:        package org.apache.commons.configuration;
002:
003:        /*
004:         * Licensed to the Apache Software Foundation (ASF) under one or more
005:         * contributor license agreements.  See the NOTICE file distributed with
006:         * this work for additional information regarding copyright ownership.
007:         * The ASF licenses this file to You under the Apache License, Version 2.0
008:         * (the "License"); you may not use this file except in compliance with
009:         * the License.  You may obtain a copy of the License at
010:         *
011:         *     http://www.apache.org/licenses/LICENSE-2.0
012:         *
013:         * Unless required by applicable law or agreed to in writing, software
014:         * distributed under the License is distributed on an "AS IS" BASIS,
015:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016:         * See the License for the specific language governing permissions and
017:         * limitations under the License.
018:         */
019:
020:        import java.io.File;
021:        import java.util.Iterator;
022:        import java.util.List;
023:
024:        import junit.framework.TestCase;
025:
026:        /**
027:         * Compare the behaviour of various methods between CompositeConfiguration
028:         * and normal (Properties) Configuration
029:         * 
030:         * @version $Id: TestEqualBehaviour.java 439648 2006-09-02 20:42:10Z oheger $
031:         */
032:        public class TestEqualBehaviour extends TestCase {
033:            private Configuration setupSimpleConfiguration() throws Exception {
034:                String simpleConfigurationFile = new File(
035:                        "conf/testEqual.properties").getAbsolutePath();
036:                return new PropertiesConfiguration(simpleConfigurationFile);
037:            }
038:
039:            private Configuration setupCompositeConfiguration()
040:                    throws Exception {
041:                String compositeConfigurationFile = new File(
042:                        "conf/testEqualDigester.xml").getAbsolutePath();
043:
044:                ConfigurationFactory configurationFactory = new ConfigurationFactory();
045:                configurationFactory
046:                        .setConfigurationFileName(compositeConfigurationFile);
047:                return configurationFactory.getConfiguration();
048:            }
049:
050:            /**
051:             * Checks whether two configurations have the same size, 
052:             * the same key sequence and contain the same key -> value mappings
053:             */
054:            private void checkEquality(String msg, Configuration c1,
055:                    Configuration c2) {
056:                Iterator it1 = c1.getKeys();
057:                Iterator it2 = c2.getKeys();
058:
059:                while (it1.hasNext() && it2.hasNext()) {
060:                    String key1 = (String) it1.next();
061:                    String key2 = (String) it2.next();
062:                    assertEquals(msg + ", Keys: ", key1, key2);
063:                    assertEquals(msg + ", Contains: ", c1.containsKey(key1), c2
064:                            .containsKey(key2));
065:                }
066:                assertEquals(msg + ", Iterator: ", it1.hasNext(), it2.hasNext());
067:            }
068:
069:            /**
070:             * Checks whether two configurations have the same key -> value mapping
071:             */
072:            private void checkSameKey(String msg, String key, Configuration c1,
073:                    Configuration c2) {
074:                String[] s1 = c1.getStringArray(key);
075:                String[] s2 = c2.getStringArray(key);
076:
077:                assertEquals(msg + ", length: ", s1.length, s2.length);
078:
079:                for (int i = 0; i < s1.length; i++) {
080:                    assertEquals(msg + ", String Array: ", s1[i], s2[i]);
081:                }
082:
083:                List list1 = c1.getList(key);
084:                List list2 = c2.getList(key);
085:
086:                assertEquals(msg + ", Size: ", list1.size(), list2.size());
087:
088:                Iterator it1 = list1.iterator();
089:                Iterator it2 = list2.iterator();
090:
091:                while (it1.hasNext() && it2.hasNext()) {
092:                    String val1 = (String) it1.next();
093:                    String val2 = (String) it2.next();
094:                    assertEquals(msg + ", List: ", val1, val2);
095:                }
096:                assertEquals(msg + ", Iterator End: ", it1.hasNext(), it2
097:                        .hasNext());
098:            }
099:
100:            /**
101:             * Are both configurations equal after loading?
102:             */
103:            public void testLoading() throws Exception {
104:                Configuration simple = setupSimpleConfiguration();
105:                Configuration composite = setupCompositeConfiguration();
106:
107:                checkEquality("testLoading", simple, composite);
108:            }
109:
110:            /**
111:             * If we delete a key, does it vanish? Does it leave all
112:             * the other keys unchanged? How about an unset key?
113:             */
114:            public void testDeletingExisting() throws Exception {
115:                Configuration simple = setupSimpleConfiguration();
116:                Configuration composite = setupCompositeConfiguration();
117:
118:                String key = "clear.property";
119:
120:                assertTrue(simple.containsKey(key));
121:                assertEquals(simple.containsKey(key), composite
122:                        .containsKey(key));
123:
124:                simple.clearProperty(key);
125:                composite.clearProperty(key);
126:
127:                assertFalse(simple.containsKey(key));
128:                assertEquals(simple.containsKey(key), composite
129:                        .containsKey(key));
130:
131:                checkEquality("testDeletingExisting", simple, composite);
132:            }
133:
134:            public void testDeletingNonExisting() throws Exception {
135:                Configuration simple = setupSimpleConfiguration();
136:                Configuration composite = setupCompositeConfiguration();
137:
138:                String key = "nonexisting.clear.property";
139:
140:                assertFalse(simple.containsKey(key));
141:                assertEquals(simple.containsKey(key), composite
142:                        .containsKey(key));
143:
144:                simple.clearProperty(key);
145:                composite.clearProperty(key);
146:
147:                assertFalse(simple.containsKey(key));
148:                assertEquals(simple.containsKey(key), composite
149:                        .containsKey(key));
150:
151:                checkEquality("testDeletingNonExisting", simple, composite);
152:            }
153:
154:            /**
155:             * If we set a key, does it work? How about an existing
156:             * key? Can we change it?
157:             */
158:            public void testSettingNonExisting() throws Exception {
159:                Configuration simple = setupSimpleConfiguration();
160:                Configuration composite = setupCompositeConfiguration();
161:
162:                String key = "nonexisting.property";
163:                String value = "new value";
164:
165:                assertFalse(simple.containsKey(key));
166:                assertEquals(simple.containsKey(key), composite
167:                        .containsKey(key));
168:
169:                simple.setProperty(key, value);
170:                composite.setProperty(key, value);
171:
172:                assertTrue(simple.containsKey(key));
173:                assertEquals(simple.containsKey(key), composite
174:                        .containsKey(key));
175:
176:                checkSameKey("testSettingNonExisting", key, simple, composite);
177:                checkEquality("testSettingNonExisting", simple, composite);
178:            }
179:
180:            public void testSettingExisting() throws Exception {
181:                Configuration simple = setupSimpleConfiguration();
182:                Configuration composite = setupCompositeConfiguration();
183:
184:                String key = "existing.property";
185:                String value = "new value";
186:
187:                assertTrue(simple.containsKey(key));
188:                assertFalse(simple.getString(key).equals(value));
189:                assertEquals(simple.containsKey(key), composite
190:                        .containsKey(key));
191:
192:                simple.setProperty(key, value);
193:                composite.setProperty(key, value);
194:
195:                assertTrue(simple.containsKey(key));
196:                assertEquals(simple.getString(key), value);
197:                assertEquals(simple.containsKey(key), composite
198:                        .containsKey(key));
199:
200:                checkSameKey("testSettingExisting", key, simple, composite);
201:                checkEquality("testSettingExisting", simple, composite);
202:            }
203:
204:            /**
205:             * If we add a key, does it work?
206:             */
207:            public void testAddingUnset() throws Exception {
208:                Configuration simple = setupSimpleConfiguration();
209:                Configuration composite = setupCompositeConfiguration();
210:
211:                String key = "nonexisting.property";
212:                String value = "new value";
213:
214:                assertFalse(simple.containsKey(key));
215:                assertEquals(simple.containsKey(key), composite
216:                        .containsKey(key));
217:
218:                simple.addProperty(key, value);
219:                composite.addProperty(key, value);
220:
221:                checkSameKey("testAddingUnset", key, simple, composite);
222:                checkEquality("testAddingUnset", simple, composite);
223:            }
224:
225:            /**
226:             * If we add a to an existing key, does it work?
227:             */
228:            public void testAddingSet() throws Exception {
229:                Configuration simple = setupSimpleConfiguration();
230:                Configuration composite = setupCompositeConfiguration();
231:
232:                String key = "existing.property";
233:                String value = "new value";
234:
235:                assertTrue(simple.containsKey(key));
236:                assertEquals(simple.containsKey(key), composite
237:                        .containsKey(key));
238:
239:                simple.addProperty(key, value);
240:                composite.addProperty(key, value);
241:
242:                assertTrue(simple.containsKey(key));
243:                assertEquals(simple.containsKey(key), composite
244:                        .containsKey(key));
245:
246:                checkSameKey("testAddingSet", key, simple, composite);
247:                checkEquality("testAddingSet", simple, composite);
248:            }
249:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.