Source Code Cross Referenced for SchemaConversionUtilsTest.java in  » EJB-Server-geronimo » plugins » org » apache » geronimo » schema » 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 » EJB Server geronimo » plugins » org.apache.geronimo.schema 
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:         */package org.apache.geronimo.schema;
017:
018:        import java.util.ArrayList;
019:        import java.util.List;
020:        import java.net.URL;
021:
022:        import javax.xml.namespace.QName;
023:
024:        import org.apache.xmlbeans.XmlCursor;
025:        import org.apache.xmlbeans.XmlObject;
026:        import org.apache.geronimo.xbeans.javaee.EjbJarType;
027:        import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
028:        import org.apache.geronimo.testsupport.XmlBeansTestSupport;
029:
030:        import org.apache.commons.logging.Log;
031:        import org.apache.commons.logging.LogFactory;
032:
033:        /**
034:         * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should
035:         * work for both.
036:         *
037:         * @version $Rev: 610760 $ $Date: 2008-01-10 03:07:04 -0800 (Thu, 10 Jan 2008) $
038:         */
039:        public class SchemaConversionUtilsTest extends XmlBeansTestSupport {
040:            private static final Log log = LogFactory
041:                    .getLog(SchemaConversionUtilsTest.class);
042:
043:            private ClassLoader classLoader = this .getClass().getClassLoader();
044:
045:            //comment on validity of j2ee 1.4 schemas: validation doesn't work...
046:            //        From: "Radu Preotiuc-Pietro" <radup@bea.com>
047:            //        Date: Tue Jun 15, 2004  3:37:50 PM US/Pacific
048:            //        To: <xmlbeans-user@xml.apache.org>
049:            //        Subject: RE: Problem with validate -- xsb schema file missing/wrong name
050:            //        Reply-To: xmlbeans-user@xml.apache.org
051:            //
052:            //        Unfortunately, there is an issue in XmlBeans v1 having to do with duplicate id constraints definitions.
053:            //        XmlBeans v2 does not have this issue.
054:            //        Also, these ejb Schemas are techically incorrect because they violate the id constraint uniqueness rule (at least when processed together, you could try and compile each one separately)
055:            //        So, there are a couple of options:
056:            //        1. you hand-edit the schemas to rename those problematic id constraints
057:            //        2. you upgrade to v2
058:            //        Well, there is a third alternative, which is a fix integrated in XmlBeans v1, may or may not be feasible
059:            //
060:            //        Radu
061:
062:            //I've taken option (1) and fixed the schemas
063:
064:            //The schemas have been fixed by sun, we can use the official schemas.
065:
066:            public void testOrderDescriptionGroup() throws Exception {
067:                URL srcXml = classLoader
068:                        .getResource("j2ee_1_3dtd/DescriptionGroupTestSource.xml");
069:                URL expectedOutputXml = classLoader
070:                        .getResource("j2ee_1_3dtd/DescriptionGroupTestExpected.xml");
071:                XmlObject srcObject = XmlObject.Factory.parse(srcXml);
072:                XmlCursor srcCursor = srcObject.newCursor();
073:                XmlCursor moveable = srcObject.newCursor();
074:                try {
075:                    srcCursor.toFirstChild();
076:                    srcCursor.toFirstChild();
077:                    assertTrue(srcCursor.getName().toString(), "filter"
078:                            .equals(srcCursor.getName().getLocalPart()));
079:                    do {
080:                        srcCursor.push();
081:                        srcCursor.toFirstChild();
082:                        SchemaConversionUtils.convertToDescriptionGroup(
083:                                SchemaConversionUtils.J2EE_NAMESPACE,
084:                                srcCursor, moveable);
085:                        srcCursor.pop();
086:                    } while (srcCursor.toNextSibling());
087:                } finally {
088:                    srcCursor.dispose();
089:                }
090:                //        log.debug(srcObject.toString());
091:                XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
092:                List problems = new ArrayList();
093:                boolean ok = compareXmlObjects(srcObject, expected, problems);
094:                assertTrue("Differences: " + problems, ok);
095:            }
096:
097:            public void testOrderJNDIEnvironmentRefsGroup() throws Exception {
098:                URL srcXml = classLoader
099:                        .getResource("j2ee_1_3dtd/JNDIEnvironmentRefsGroupTestSource.xml");
100:                URL expectedOutputXml = classLoader
101:                        .getResource("j2ee_1_3dtd/JNDIEnvironmentRefsGroupTestExpected.xml");
102:                XmlObject srcObject = XmlObject.Factory.parse(srcXml);
103:                XmlCursor srcCursor = srcObject.newCursor();
104:                XmlCursor moveable = srcObject.newCursor();
105:                try {
106:                    srcCursor.toFirstChild();
107:                    srcCursor.toFirstChild();
108:                    assertTrue(srcCursor.getName().toString(), "web-app"
109:                            .equals(srcCursor.getName().getLocalPart()));
110:                    do {
111:                        srcCursor.push();
112:                        srcCursor.toFirstChild();
113:                        srcCursor.toNextSibling();
114:                        srcCursor.toNextSibling();
115:                        moveable.toCursor(srcCursor);
116:                        SchemaConversionUtils
117:                                .convertToJNDIEnvironmentRefsGroup(
118:                                        SchemaConversionUtils.J2EE_NAMESPACE,
119:                                        srcCursor, moveable);
120:                        srcCursor.pop();
121:                    } while (srcCursor.toNextSibling());
122:                } finally {
123:                    srcCursor.dispose();
124:                }
125:                //        log.debug(srcObject.toString());
126:                XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
127:                List problems = new ArrayList();
128:                boolean ok = compareXmlObjects(srcObject, expected, problems);
129:                assertTrue("Differences: " + problems, ok);
130:            }
131:
132:            public void testGeronimoNamingNamespaceChange() throws Exception {
133:                URL srcXml = classLoader
134:                        .getResource("geronimo/ejb-naming-pre.xml");
135:                URL expectedOutputXml = classLoader
136:                        .getResource("geronimo/ejb-naming-post.xml");
137:                XmlObject xmlObject = XmlBeansUtil.parse(srcXml, this 
138:                        .getClass().getClassLoader());
139:                XmlCursor cursor = xmlObject.newCursor();
140:                try {
141:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
142:                    log.debug(xmlObject.toString());
143:
144:                    XmlObject expected = XmlObject.Factory
145:                            .parse(expectedOutputXml);
146:                    log.debug(expected.toString());
147:
148:                    List problems = new ArrayList();
149:                    boolean ok = compareXmlObjects(xmlObject, expected,
150:                            problems);
151:                    assertTrue("Differences: " + problems, ok);
152:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
153:                    boolean ok2 = compareXmlObjects(xmlObject, expected,
154:                            problems);
155:                    assertTrue("Differences: " + problems, ok2);
156:                } finally {
157:                    cursor.dispose();
158:                }
159:            }
160:
161:            //
162:            public void testGetNestedObjectAsType() throws Exception {
163:                URL srcXml = classLoader
164:                        .getResource("geronimo/ejb-naming-pre.xml");
165:                //        URL expectedOutputXml = classLoader.getResource("geronimo/ejb-naming-post.xml");
166:                XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
167:                //this is not a usable type, we'll see what happens though
168:                xmlObject = SchemaConversionUtils
169:                        .getNestedObjectAsType(
170:                                xmlObject,
171:                                new QName(
172:                                        "http://openejb.apache.org/xml/ns/openejb-jar-2.3",
173:                                        "openejb-jar"), EjbJarType.type);
174:                //	        log.debug(xmlObject.toString());
175:            }
176:
177:            public void testSecurityElementConverter() throws Exception {
178:                URL srcXml = classLoader
179:                        .getResource("geronimo/security-pre.xml");
180:                URL expectedOutputXml = classLoader
181:                        .getResource("geronimo/security-post.xml");
182:                XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
183:                ElementConverter elementConverter = new SecurityElementConverter();
184:                XmlCursor cursor = xmlObject.newCursor();
185:                XmlCursor end = cursor.newCursor();
186:                try {
187:                    elementConverter.convertElement(cursor, end);
188:                    //        log.debug(xmlObject.toString());
189:                    XmlObject expected = XmlObject.Factory
190:                            .parse(expectedOutputXml);
191:                    List problems = new ArrayList();
192:                    boolean ok = compareXmlObjects(xmlObject, expected,
193:                            problems);
194:                    assertTrue("Differences: " + problems, ok);
195:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
196:                    boolean ok2 = compareXmlObjects(xmlObject, expected,
197:                            problems);
198:                    assertTrue("Differences: " + problems, ok2);
199:                } finally {
200:                    cursor.dispose();
201:                    end.dispose();
202:                }
203:
204:            }
205:
206:            public void testGBeanElementConverter() throws Exception {
207:                URL srcXml = classLoader.getResource("geronimo/gbean-pre.xml");
208:                URL expectedOutputXml = classLoader
209:                        .getResource("geronimo/gbean-post.xml");
210:                XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
211:                ElementConverter elementConverter = new GBeanElementConverter();
212:                XmlCursor cursor = xmlObject.newCursor();
213:                XmlCursor end = cursor.newCursor();
214:                try {
215:                    elementConverter.convertElement(cursor, end);
216:                    //        log.debug(xmlObject.toString());
217:                    XmlObject expected = XmlObject.Factory
218:                            .parse(expectedOutputXml);
219:                    List problems = new ArrayList();
220:                    boolean ok = compareXmlObjects(xmlObject, expected,
221:                            problems);
222:                    assertTrue("Differences: " + problems, ok);
223:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
224:                    boolean ok2 = compareXmlObjects(xmlObject, expected,
225:                            problems);
226:                    assertTrue("Differences: " + problems, ok2);
227:                } finally {
228:                    cursor.dispose();
229:                    end.dispose();
230:                }
231:
232:            }
233:
234:            public void testQNameConverter1() throws Exception {
235:                URL srcXml = classLoader.getResource("geronimo/qname1-pre.xml");
236:                URL expectedOutputXml = classLoader
237:                        .getResource("geronimo/qname1-post.xml");
238:                XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
239:                ElementConverter elementConverter = new QNameConverter(
240:                        "import",
241:                        "http://geronimo.apache.org/xml/ns/deployment-1.0",
242:                        "parent");
243:                XmlCursor cursor = xmlObject.newCursor();
244:                XmlCursor end = cursor.newCursor();
245:                try {
246:                    elementConverter.convertElement(cursor, end);
247:                    //        log.debug(xmlObject.toString());
248:                    XmlObject expected = XmlObject.Factory
249:                            .parse(expectedOutputXml);
250:                    List problems = new ArrayList();
251:                    boolean ok = compareXmlObjects(xmlObject, expected,
252:                            problems);
253:                    assertTrue("Differences: " + problems, ok);
254:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
255:                    boolean ok2 = compareXmlObjects(xmlObject, expected,
256:                            problems);
257:                    assertTrue("Differences: " + problems, ok2);
258:                } finally {
259:                    cursor.dispose();
260:                    end.dispose();
261:                }
262:
263:            }
264:
265:            public void testQNameConverter2() throws Exception {
266:                URL srcXml = classLoader.getResource("geronimo/qname2-pre.xml");
267:                URL expectedOutputXml = classLoader
268:                        .getResource("geronimo/qname2-post.xml");
269:                XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
270:                ElementConverter elementConverter = new QNameConverter(
271:                        "import",
272:                        "http://geronimo.apache.org/xml/ns/deployment-1.0",
273:                        "parent");
274:                XmlCursor cursor = xmlObject.newCursor();
275:                XmlCursor end = cursor.newCursor();
276:                try {
277:                    elementConverter.convertElement(cursor, end);
278:                    //        log.debug(xmlObject.toString());
279:                    XmlObject expected = XmlObject.Factory
280:                            .parse(expectedOutputXml);
281:                    List problems = new ArrayList();
282:                    boolean ok = compareXmlObjects(xmlObject, expected,
283:                            problems);
284:                    assertTrue("Differences: " + problems, ok);
285:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
286:                    boolean ok2 = compareXmlObjects(xmlObject, expected,
287:                            problems);
288:                    assertTrue("Differences: " + problems, ok2);
289:                } finally {
290:                    cursor.dispose();
291:                    end.dispose();
292:                }
293:
294:            }
295:
296:            public void testWebMessageDestination1() throws Exception {
297:                URL srcXml = classLoader.getResource("geronimo/web-md-pre.xml");
298:                URL expectedOutputXml = classLoader
299:                        .getResource("geronimo/web-md-post.xml");
300:                XmlObject xmlObject = XmlBeansUtil.parse(srcXml, this 
301:                        .getClass().getClassLoader());
302:                XmlCursor cursor = xmlObject.newCursor();
303:                try {
304:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
305:                    log.debug(xmlObject.toString());
306:
307:                    XmlObject expected = XmlObject.Factory
308:                            .parse(expectedOutputXml);
309:                    log.debug(expected.toString());
310:
311:                    List problems = new ArrayList();
312:                    boolean ok = compareXmlObjects(xmlObject, expected,
313:                            problems);
314:                    assertTrue("Differences: " + problems, ok);
315:                    SchemaConversionUtils.convertToGeronimoSubSchemas(cursor);
316:                    boolean ok2 = compareXmlObjects(xmlObject, expected,
317:                            problems);
318:                    assertTrue("Differences: " + problems, ok2);
319:                } finally {
320:                    cursor.dispose();
321:                }
322:
323:            }
324:
325:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.