Source Code Cross Referenced for XIncludeXMLBuilderTestCase.java in  » Installer » IzPack » net » n3 » nanoxml » xinclude » 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 » Installer » IzPack » net.n3.nanoxml.xinclude 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2007 Volantis Systems Ltd., All Rights Reserved.
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:        package net.n3.nanoxml.xinclude;
017:
018:        import junit.framework.TestCase;
019:        import net.n3.nanoxml.IXMLReader;
020:        import net.n3.nanoxml.NonValidator;
021:        import net.n3.nanoxml.StdXMLParser;
022:        import net.n3.nanoxml.StdXMLReader;
023:        import net.n3.nanoxml.XMLBuilderFactory;
024:        import net.n3.nanoxml.XMLElement;
025:
026:        import java.util.Enumeration;
027:
028:        /**
029:         * Test the XInclude style functionality added to the XMLBuilder
030:         */
031:        public class XIncludeXMLBuilderTestCase extends TestCase {
032:
033:            /**
034:             * This method takes the fileBase name and attempts to find two files
035:             * called <fileBase>-input.xml and <fileBase>-expected.xml
036:             *
037:             * @param fileBase the base of the test file names
038:             * @throws Exception
039:             */
040:            public void doTest(String fileBase) throws Exception {
041:
042:                String baseURL = getClass()
043:                        .getResource(fileBase + "-input.xml").toExternalForm();
044:                // set up a new parser to parse the input xml (with includes)
045:                StdXMLParser inputParser = new StdXMLParser();
046:                inputParser.setBuilder(XMLBuilderFactory.createXMLBuilder());
047:                IXMLReader inputReader = new StdXMLReader(getClass()
048:                        .getResourceAsStream(fileBase + "-input.xml"));
049:                inputReader.setSystemID(baseURL);
050:                inputParser.setReader(inputReader);
051:                inputParser.setValidator(new NonValidator());
052:
053:                // set up a new parser to parse the expected xml (without includes)
054:                StdXMLParser expectedParser = new StdXMLParser();
055:                expectedParser.setBuilder(XMLBuilderFactory.createXMLBuilder());
056:                IXMLReader expectedReader = new StdXMLReader(getClass()
057:                        .getResourceAsStream(fileBase + "-expect.xml"));
058:                expectedReader.setSystemID(baseURL);
059:                expectedParser.setReader(expectedReader);
060:                expectedParser.setValidator(new NonValidator());
061:
062:                XMLElement inputElement = (XMLElement) inputParser.parse();
063:                XMLElement expectedElement = (XMLElement) expectedParser
064:                        .parse();
065:
066:                deepEqual(expectedElement, inputElement);
067:
068:            }
069:
070:            /**
071:             * This method is used to ensure that the contents of the specified file
072:             * (when having "-input.xml" appended) cause the parser to fail
073:             *
074:             * @param fileBase the base name of the input file.
075:             * @throws Exception
076:             */
077:            public void ensureFailure(String fileBase) throws Exception {
078:                try {
079:                    String baseURL = getClass().getResource(
080:                            fileBase + "-input.xml").toExternalForm();
081:                    // set up a new parser to parse the input xml (with includes)
082:                    StdXMLParser inputParser = new StdXMLParser();
083:                    inputParser
084:                            .setBuilder(XMLBuilderFactory.createXMLBuilder());
085:                    IXMLReader inputReader = new StdXMLReader(getClass()
086:                            .getResourceAsStream(fileBase + "-input.xml"));
087:                    inputReader.setSystemID(baseURL);
088:                    inputParser.setReader(inputReader);
089:                    inputParser.setValidator(new NonValidator());
090:
091:                    inputParser.parse();
092:                    fail("an exception should have been thrown");
093:                } catch (Throwable t) {
094:                    // success
095:                }
096:            }
097:
098:            /**
099:             * Perform a deep equality check on the two nodes.
100:             *
101:             */
102:            public void deepEqual(XMLElement a, XMLElement b) {
103:
104:                assertEquals("element names", a.getName(), b.getName());
105:                assertEquals("element attributes for " + a.getName(), a
106:                        .getAttributes(), b.getAttributes());
107:                assertEquals("content for " + a.getName(), a.getContent(), b
108:                        .getContent());
109:                assertEquals("equal number of children" + a.getName(), a
110:                        .getChildrenCount(), b.getChildrenCount());
111:
112:                Enumeration aChildren = a.enumerateChildren();
113:                Enumeration bChildren = b.enumerateChildren();
114:                while (aChildren.hasMoreElements()) {
115:                    XMLElement aChild = (XMLElement) aChildren.nextElement();
116:                    XMLElement bChild = (XMLElement) bChildren.nextElement();
117:                    deepEqual(aChild, bChild);
118:                }
119:            }
120:
121:            /**
122:             * Test Empty document with include
123:             * @throws Exception
124:             */
125:            public void testIncludeOnly() throws Exception {
126:                doTest("include-only");
127:            }
128:
129:            /**
130:             * Test that a fragment included as the root node does not have the
131:             * "fragment" element removed
132:             * @throws Exception
133:             */
134:            public void testIncludeFragmentOnly() throws Exception {
135:                doTest("include-fragment-only");
136:            }
137:
138:            /**
139:             * Test to ensure that content is correctly included when the include
140:             * element is not the root element
141:             * @throws Exception
142:             */
143:            public void testIncludeInElement() throws Exception {
144:                doTest("include-in-element");
145:            }
146:
147:            /**
148:             * Test to ensure that content is correctly included when the include
149:             * element is not the root element
150:             * @throws Exception
151:             */
152:            public void testIncludeFragmentInElement() throws Exception {
153:                doTest("include-fragment-in-element");
154:            }
155:
156:            /**
157:             * Test text inclusion
158:             * @throws Exception
159:             */
160:            public void testIncludeTextInElement() throws Exception {
161:                doTest("include-fragment-in-element");
162:            }
163:
164:            /**
165:             * Ensure that the parse attribute accepts "text" and treats it like text
166:             * @throws Exception
167:             */
168:            public void testParseAttributeText() throws Exception {
169:                doTest("include-xml-as-text");
170:            }
171:
172:            /**
173:             * Ensure that the parse attribute accepts "xml" and treats like xml
174:             * (most other tests do not explicitly set the parse parameter and let it
175:             * default to "xml"
176:             * @throws Exception
177:             */
178:            public void testParseAttributeXML() throws Exception {
179:                doTest("include-xml-as-xml");
180:            }
181:
182:            /**
183:             * Make sure that a failure occurs for a parse valid that is not "xml"
184:             * or "text"
185:             *
186:             * @throws Exception
187:             */
188:            public void testParseInvalidAttribute() throws Exception {
189:                ensureFailure("invalid-parse-attrib");
190:            }
191:
192:            /**
193:             * Ensure fallbacks work correctly
194:             *
195:             * @throws Exception
196:             */
197:            public void testFallback() throws Exception {
198:                doTest("fallback");
199:            }
200:
201:            /**
202:             * Test that an empty fallback just removes the include and fallback
203:             * elements
204:             *
205:             * @throws Exception
206:             */
207:            public void testEmptyFallback() throws Exception {
208:                doTest("empty-fallback");
209:            }
210:
211:            /**
212:             * Ensure that two includes in the same element both get included
213:             * @throws Exception
214:             */
215:            public void testMultipleIncludes() throws Exception {
216:                doTest("multiple-include");
217:            }
218:
219:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.