Source Code Cross Referenced for TestConfigurationNodePointerFactory.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:
022:        import org.apache.commons.configuration.tree.ConfigurationNode;
023:        import org.apache.commons.configuration.tree.DefaultConfigurationNode;
024:        import org.apache.commons.jxpath.JXPathContext;
025:        import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
026:
027:        /**
028:         * Test class for ConfigurationNodePointerFactory. This class does not directly
029:         * call the factory's methods, but rather checks if it can be installed in a
030:         * <code>JXPathContext</code> and if XPath expressions can be evaluated.
031:         *
032:         * @author Oliver Heger
033:         * @version $Id: TestConfigurationNodePointerFactory.java 502705 2007-02-02 19:55:37Z oheger $
034:         */
035:        public class TestConfigurationNodePointerFactory extends
036:                AbstractXPathTest {
037:            /** Stores the JXPathContext used for testing. */
038:            JXPathContext context;
039:
040:            protected void setUp() throws Exception {
041:                super .setUp();
042:                JXPathContextReferenceImpl
043:                        .addNodePointerFactory(new ConfigurationNodePointerFactory());
044:                context = JXPathContext.newContext(root);
045:                context.setLenient(true);
046:            }
047:
048:            /**
049:             * Tests simple XPath expressions.
050:             */
051:            public void testSimpleXPath() {
052:                List nodes = context.selectNodes(CHILD_NAME1);
053:                assertEquals("Incorrect number of results", 2, nodes.size());
054:                for (Iterator it = nodes.iterator(); it.hasNext();) {
055:                    ConfigurationNode node = (ConfigurationNode) it.next();
056:                    assertEquals("Incorrect node name", CHILD_NAME1, node
057:                            .getName());
058:                    assertEquals("Incorrect parent node", root, node
059:                            .getParentNode());
060:                }
061:
062:                nodes = context.selectNodes("/" + CHILD_NAME1);
063:                assertEquals("Incorrect number of results", 2, nodes.size());
064:
065:                nodes = context.selectNodes(CHILD_NAME2 + "/" + CHILD_NAME1
066:                        + "/" + CHILD_NAME2);
067:                assertEquals("Incorrect number of results", 18, nodes.size());
068:            }
069:
070:            /**
071:             * Tests using indices to specify elements.
072:             */
073:            public void testIndices() {
074:                assertEquals("Incorrect value", "1.2.3", context.getValue("/"
075:                        + CHILD_NAME2 + "[1]/" + CHILD_NAME1 + "[1]/"
076:                        + CHILD_NAME2 + "[2]"));
077:                assertEquals("Incorrect value of last node", String
078:                        .valueOf(CHILD_COUNT), context.getValue(CHILD_NAME2
079:                        + "[last()]"));
080:
081:                List nodes = context.selectNodes("/" + CHILD_NAME1 + "[1]/*");
082:                assertEquals("Wrong number of children", CHILD_COUNT, nodes
083:                        .size());
084:                int index = 1;
085:                for (Iterator it = nodes.iterator(); it.hasNext(); index++) {
086:                    ConfigurationNode node = (ConfigurationNode) it.next();
087:                    assertEquals("Wrong node value for child " + index, "2."
088:                            + index, node.getValue());
089:                }
090:            }
091:
092:            /**
093:             * Tests accessing attributes.
094:             */
095:            public void testAttributes() {
096:                root.addAttribute(new DefaultConfigurationNode("testAttr",
097:                        "true"));
098:                assertEquals("Did not find attribute of root node", "true",
099:                        context.getValue("@testAttr"));
100:                assertEquals("Incorrect attribute value", "1", context
101:                        .getValue("/" + CHILD_NAME2 + "[1]/@" + ATTR_NAME));
102:
103:                assertTrue("Found elements with name attribute", context
104:                        .selectNodes("//" + CHILD_NAME2 + "[@name]").isEmpty());
105:                ConfigurationNode node = (ConfigurationNode) root.getChild(2)
106:                        .getChild(1).getChildren(CHILD_NAME2).get(1);
107:                node.addAttribute(new DefaultConfigurationNode("name",
108:                        "testValue"));
109:                List nodes = context
110:                        .selectNodes("//" + CHILD_NAME2 + "[@name]");
111:                assertEquals("Name attribute not found", 1, nodes.size());
112:                assertEquals("Wrong node returned", node, nodes.get(0));
113:            }
114:
115:            /**
116:             * Tests accessing a node's text.
117:             */
118:            public void testText() {
119:                List nodes = context.selectNodes("//" + CHILD_NAME2
120:                        + "[text()='1.1.1']");
121:                assertEquals("Incorrect number of result nodes", 1, nodes
122:                        .size());
123:            }
124:
125:            /**
126:             * Tests accessing the parent axis.
127:             */
128:            public void testParentAxis() {
129:                List nodes = context.selectNodes("/" + CHILD_NAME2
130:                        + "/parent::*");
131:                assertEquals("Wrong number of parent nodes", 1, nodes.size());
132:            }
133:
134:            /**
135:             * Tests accessing the following sibling axis.
136:             */
137:            public void testFollowingSiblingAxis() {
138:                List nodes = context.selectNodes("/" + CHILD_NAME1
139:                        + "[2]/following-sibling::*");
140:                assertEquals("Wrong number of following siblings", 1, nodes
141:                        .size());
142:                ConfigurationNode node = (ConfigurationNode) nodes.get(0);
143:                assertEquals("Wrong node type", CHILD_NAME2, node.getName());
144:                assertEquals("Wrong index", String.valueOf(CHILD_COUNT), node
145:                        .getValue());
146:            }
147:
148:            /**
149:             * Tests accessing the preceding sibling axis.
150:             */
151:            public void testPrecedingSiblingAxis() {
152:                List nodes = context.selectNodes("/" + CHILD_NAME1
153:                        + "[2]/preceding-sibling::*");
154:                assertEquals("Wrong number of preceding siblings", 3, nodes
155:                        .size());
156:                for (int index = 0, value = 3; index < nodes.size(); index++, value--) {
157:                    assertEquals("Wrong node index", String.valueOf(value),
158:                            ((ConfigurationNode) nodes.get(index)).getValue());
159:                }
160:            }
161:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.