Source Code Cross Referenced for TestConfigurationNodeIteratorChildren.java in  » Library » Apache-commons-configuration-1.4-src » org » apache » commons » configuration » tree » xpath » 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.xpath 
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.xpath;
018:
019:        import java.util.Iterator;
020:        import java.util.List;
021:        import java.util.Locale;
022:
023:        import org.apache.commons.configuration.tree.ConfigurationNode;
024:        import org.apache.commons.configuration.tree.DefaultConfigurationNode;
025:        import org.apache.commons.jxpath.ri.Compiler;
026:        import org.apache.commons.jxpath.ri.QName;
027:        import org.apache.commons.jxpath.ri.compiler.NodeNameTest;
028:        import org.apache.commons.jxpath.ri.compiler.NodeTest;
029:        import org.apache.commons.jxpath.ri.compiler.NodeTypeTest;
030:        import org.apache.commons.jxpath.ri.compiler.ProcessingInstructionTest;
031:        import org.apache.commons.jxpath.ri.model.NodeIterator;
032:        import org.apache.commons.jxpath.ri.model.NodePointer;
033:
034:        /**
035:         * Test class for ConfigurationNodeIteratorChildren.
036:         *
037:         * @author Oliver Heger
038:         * @version $Id: TestConfigurationNodeIteratorChildren.java 502705 2007-02-02 19:55:37Z oheger $
039:         */
040:        public class TestConfigurationNodeIteratorChildren extends
041:                AbstractXPathTest {
042:            /** Stores the node pointer to the root node. */
043:            NodePointer rootPointer;
044:
045:            protected void setUp() throws Exception {
046:                super .setUp();
047:                rootPointer = new ConfigurationNodePointer(root, Locale
048:                        .getDefault());
049:            }
050:
051:            /**
052:             * Tests to iterate over all children of the root node.
053:             */
054:            public void testIterateAllChildren() {
055:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
056:                        rootPointer, null, false, null);
057:                assertEquals("Wrong number of elements", CHILD_COUNT,
058:                        iteratorSize(it));
059:                checkValues(it, new int[] { 1, 2, 3, 4, 5 });
060:            }
061:
062:            /**
063:             * Tests a reverse iteration.
064:             */
065:            public void testIterateReverse() {
066:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
067:                        rootPointer, null, true, null);
068:                assertEquals("Wrong number of elements", CHILD_COUNT,
069:                        iteratorSize(it));
070:                checkValues(it, new int[] { 5, 4, 3, 2, 1 });
071:            }
072:
073:            /**
074:             * Tests using a node test with a wildcard name.
075:             */
076:            public void testIterateWithWildcardTest() {
077:                NodeNameTest test = new NodeNameTest(new QName(null, "*"));
078:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
079:                        rootPointer, test, false, null);
080:                assertEquals("Wrong number of elements", CHILD_COUNT,
081:                        iteratorSize(it));
082:            }
083:
084:            /**
085:             * Tests using a node test that defines a namespace prefix. Because
086:             * namespaces are not supported, no elements should be in the iteration.
087:             */
088:            public void testIterateWithPrefixTest() {
089:                NodeNameTest test = new NodeNameTest(new QName("prefix", "*"));
090:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
091:                        rootPointer, test, false, null);
092:                assertNull("Undefined node pointer not returned", it
093:                        .getNodePointer());
094:                assertEquals("Prefix was not evaluated", 0, iteratorSize(it));
095:            }
096:
097:            /**
098:             * Tests using a node test that selects a certain sub node name.
099:             */
100:            public void testIterateWithNameTest() {
101:                NodeNameTest test = new NodeNameTest(new QName(null,
102:                        CHILD_NAME2));
103:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
104:                        rootPointer, test, false, null);
105:                assertTrue("No children found", iteratorSize(it) > 0);
106:                for (Iterator elemIt = iterationElements(it).iterator(); elemIt
107:                        .hasNext();) {
108:                    assertEquals("Wrong child element", CHILD_NAME2,
109:                            ((ConfigurationNode) elemIt.next()).getName());
110:                }
111:            }
112:
113:            /**
114:             * Tests using a not supported test class. This should yield an empty
115:             * iteration.
116:             */
117:            public void testIterateWithUnknownTest() {
118:                NodeTest test = new ProcessingInstructionTest("test");
119:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
120:                        rootPointer, test, false, null);
121:                assertEquals("Unknown test was not evaluated", 0,
122:                        iteratorSize(it));
123:            }
124:
125:            /**
126:             * Tests using a type test for nodes. This should return all nodes.
127:             */
128:            public void testIterateWithNodeType() {
129:                NodeTypeTest test = new NodeTypeTest(Compiler.NODE_TYPE_NODE);
130:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
131:                        rootPointer, test, false, null);
132:                assertEquals("Node type not evaluated", CHILD_COUNT,
133:                        iteratorSize(it));
134:            }
135:
136:            /**
137:             * Tests using a type test for a non supported type. This should return an
138:             * empty iteration.
139:             */
140:            public void testIterateWithUnknownType() {
141:                NodeTypeTest test = new NodeTypeTest(Compiler.NODE_TYPE_COMMENT);
142:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
143:                        rootPointer, test, false, null);
144:                assertEquals("Unknown node type not evaluated", 0,
145:                        iteratorSize(it));
146:            }
147:
148:            /**
149:             * Tests defining a start node for the iteration.
150:             */
151:            public void testIterateStartsWith() {
152:                NodePointer childPointer = new ConfigurationNodePointer(
153:                        rootPointer, root.getChild(2));
154:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
155:                        rootPointer, null, false, childPointer);
156:                assertEquals("Wrong start position", 0, it.getPosition());
157:                List nodes = iterationElements(it);
158:                assertEquals("Wrong size of iteration", CHILD_COUNT - 3, nodes
159:                        .size());
160:                int index = 4;
161:                for (Iterator it2 = nodes.iterator(); it2.hasNext(); index++) {
162:                    ConfigurationNode node = (ConfigurationNode) it2.next();
163:                    assertEquals("Wrong node value", String.valueOf(index),
164:                            node.getValue());
165:                }
166:            }
167:
168:            /**
169:             * Tests defining a start node for a reverse iteration.
170:             */
171:            public void testIterateStartsWithReverse() {
172:                NodePointer childPointer = new ConfigurationNodePointer(
173:                        rootPointer, root.getChild(3));
174:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
175:                        rootPointer, null, true, childPointer);
176:                int value = 3;
177:                for (int index = 1; it.setPosition(index); index++, value--) {
178:                    ConfigurationNode node = (ConfigurationNode) it
179:                            .getNodePointer().getNode();
180:                    assertEquals("Incorrect value at index " + index, String
181:                            .valueOf(value), node.getValue());
182:                }
183:                assertEquals("Iteration ended not at end node", 0, value);
184:            }
185:
186:            /**
187:             * Tests iteration with an invalid start node. This should cause the
188:             * iteration to start at the first position.
189:             */
190:            public void testIterateStartsWithInvalid() {
191:                NodePointer childPointer = new ConfigurationNodePointer(
192:                        rootPointer, new DefaultConfigurationNode("newNode"));
193:                ConfigurationNodeIteratorChildren it = new ConfigurationNodeIteratorChildren(
194:                        rootPointer, null, false, childPointer);
195:                assertEquals("Wrong size of iteration", CHILD_COUNT,
196:                        iteratorSize(it));
197:                it.setPosition(1);
198:                ConfigurationNode node = (ConfigurationNode) it
199:                        .getNodePointer().getNode();
200:                assertEquals("Wrong start node", "1", node.getValue());
201:            }
202:
203:            /**
204:             * Helper method for checking the values of the nodes returned by an
205:             * iterator. Because the values indicate the order of the child nodes with
206:             * this test it can be checked whether the nodes were returned in the
207:             * correct order.
208:             *
209:             * @param iterator the iterator
210:             * @param expectedIndices an array with the expected indices
211:             */
212:            private void checkValues(NodeIterator iterator,
213:                    int[] expectedIndices) {
214:                List nodes = iterationElements(iterator);
215:                for (int i = 0; i < expectedIndices.length; i++) {
216:                    ConfigurationNode child = (ConfigurationNode) nodes.get(i);
217:                    assertTrue("Wrong index value for child " + i, child
218:                            .getValue().toString().endsWith(
219:                                    String.valueOf(expectedIndices[i])));
220:                }
221:            }
222:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.