Source Code Cross Referenced for AbstractXPathTemplateTestCase.java in  » Web-Services » spring-ws-1.0.0 » org » springframework » xml » 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 » Web Services » spring ws 1.0.0 » org.springframework.xml.xpath 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 the original author or authors.
003:         *
004:         * Licensed under the Apache License, Version 2.0 (the "License");
005:         * you may not use this file except in compliance with the License.
006:         * You may obtain a copy of the License at
007:         *
008:         *      http://www.apache.org/licenses/LICENSE-2.0
009:         *
010:         * Unless required by applicable law or agreed to in writing, software
011:         * distributed under the License is distributed on an "AS IS" BASIS,
012:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013:         * See the License for the specific language governing permissions and
014:         * limitations under the License.
015:         */
016:
017:        package org.springframework.xml.xpath;
018:
019:        import java.io.IOException;
020:        import java.io.InputStream;
021:        import java.util.List;
022:        import javax.xml.parsers.DocumentBuilder;
023:        import javax.xml.parsers.DocumentBuilderFactory;
024:        import javax.xml.parsers.ParserConfigurationException;
025:        import javax.xml.transform.Source;
026:        import javax.xml.transform.dom.DOMSource;
027:        import javax.xml.transform.stream.StreamSource;
028:
029:        import junit.framework.TestCase;
030:        import org.springframework.core.io.ClassPathResource;
031:        import org.springframework.xml.sax.SaxUtils;
032:        import org.springframework.xml.transform.ResourceSource;
033:        import org.w3c.dom.DOMException;
034:        import org.w3c.dom.Document;
035:        import org.w3c.dom.Node;
036:        import org.xml.sax.SAXException;
037:
038:        public abstract class AbstractXPathTemplateTestCase extends TestCase {
039:
040:            XPathOperations template;
041:
042:            private Source namespaces;
043:
044:            private Source nonamespaces;
045:
046:            protected final void setUp() throws Exception {
047:                template = createTemplate();
048:                namespaces = new ResourceSource(new ClassPathResource(
049:                        "namespaces.xml", AbstractXPathTemplateTestCase.class));
050:                nonamespaces = new ResourceSource(
051:                        new ClassPathResource("nonamespaces.xml",
052:                                AbstractXPathTemplateTestCase.class));
053:            }
054:
055:            protected abstract XPathOperations createTemplate()
056:                    throws Exception;
057:
058:            public void testEvaluateAsBoolean() {
059:                boolean result = template.evaluateAsBoolean(
060:                        "/root/child/boolean", nonamespaces);
061:                assertTrue("Invalid result", result);
062:            }
063:
064:            public void testEvaluateAsBooleanNamespaces() {
065:                boolean result = template.evaluateAsBoolean(
066:                        "/prefix1:root/prefix2:child/prefix2:boolean",
067:                        namespaces);
068:                assertTrue("Invalid result", result);
069:            }
070:
071:            public void testEvaluateAsDouble() {
072:                double result = template.evaluateAsDouble("/root/child/number",
073:                        nonamespaces);
074:                assertEquals("Invalid result", 42D, result, 0D);
075:            }
076:
077:            public void testEvaluateAsDoubleNamespaces() {
078:                double result = template.evaluateAsDouble(
079:                        "/prefix1:root/prefix2:child/prefix2:number",
080:                        namespaces);
081:                assertEquals("Invalid result", 42D, result, 0D);
082:            }
083:
084:            public void testEvaluateAsNode() {
085:                Node result = template.evaluateAsNode("/root/child",
086:                        nonamespaces);
087:                assertNotNull("Invalid result", result);
088:                assertEquals("Invalid localname", "child", result
089:                        .getLocalName());
090:            }
091:
092:            public void testEvaluateAsNodeNamespaces() {
093:                Node result = template.evaluateAsNode(
094:                        "/prefix1:root/prefix2:child", namespaces);
095:                assertNotNull("Invalid result", result);
096:                assertEquals("Invalid localname", "child", result
097:                        .getLocalName());
098:            }
099:
100:            public void testEvaluateAsNodes() {
101:                List results = template.evaluateAsNodeList("/root/child/*",
102:                        nonamespaces);
103:                assertNotNull("Invalid result", results);
104:                assertEquals("Invalid amount of results", 3, results.size());
105:            }
106:
107:            public void testEvaluateAsNodesNamespaces() {
108:                List results = template.evaluateAsNodeList(
109:                        "/prefix1:root/prefix2:child/*", namespaces);
110:                assertNotNull("Invalid result", results);
111:                assertEquals("Invalid amount of results", 3, results.size());
112:            }
113:
114:            public void testEvaluateAsStringNamespaces() throws IOException,
115:                    SAXException {
116:                String result = template.evaluateAsString(
117:                        "/prefix1:root/prefix2:child/prefix2:text", namespaces);
118:                assertEquals("Invalid result", "text", result);
119:            }
120:
121:            public void testEvaluateAsString() throws IOException, SAXException {
122:                String result = template.evaluateAsString("/root/child/text",
123:                        nonamespaces);
124:                assertEquals("Invalid result", "text", result);
125:            }
126:
127:            public void testEvaluateDomSource() throws IOException,
128:                    SAXException, ParserConfigurationException {
129:                DocumentBuilderFactory documentBuilderFactory = DocumentBuilderFactory
130:                        .newInstance();
131:                documentBuilderFactory.setNamespaceAware(true);
132:                DocumentBuilder documentBuilder = documentBuilderFactory
133:                        .newDocumentBuilder();
134:                Document document = documentBuilder.parse(SaxUtils
135:                        .createInputSource(new ClassPathResource(
136:                                "nonamespaces.xml",
137:                                AbstractXPathTemplateTestCase.class)));
138:
139:                String result = template.evaluateAsString("/root/child/text",
140:                        new DOMSource(document));
141:                assertEquals("Invalid result", "text", result);
142:            }
143:
144:            public void testEvaluateStreamSource() throws IOException,
145:                    SAXException, ParserConfigurationException {
146:                InputStream in = AbstractXPathTemplateTestCase.class
147:                        .getResourceAsStream("nonamespaces.xml");
148:                String result = template.evaluateAsString("/root/child/text",
149:                        new StreamSource(in));
150:                assertEquals("Invalid result", "text", result);
151:            }
152:
153:            public void testInvalidExpression() {
154:                try {
155:                    template.evaluateAsBoolean("\\", namespaces);
156:                    fail("No XPathException thrown");
157:                } catch (XPathException ex) {
158:                    // Expected behaviour
159:                }
160:            }
161:
162:            public void testEvaluateAsObject() throws Exception {
163:                String result = (String) template.evaluateAsObject(
164:                        "/root/child", nonamespaces, new NodeMapper() {
165:                            public Object mapNode(Node node, int nodeNum)
166:                                    throws DOMException {
167:                                return node.getLocalName();
168:                            }
169:                        });
170:                assertNotNull("Invalid result", result);
171:                assertEquals("Invalid localname", "child", result);
172:            }
173:
174:            public void testEvaluate() throws Exception {
175:                List results = template.evaluate("/root/child/*", nonamespaces,
176:                        new NodeMapper() {
177:                            public Object mapNode(Node node, int nodeNum)
178:                                    throws DOMException {
179:                                return node.getLocalName();
180:                            }
181:                        });
182:                assertNotNull("Invalid result", results);
183:                assertEquals("Invalid amount of results", 3, results.size());
184:                assertEquals("Invalid first result", "text", results.get(0));
185:                assertEquals("Invalid first result", "number", results.get(1));
186:                assertEquals("Invalid first result", "boolean", results.get(2));
187:            }
188:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.