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.openejb.deployment;
017:
018: import java.net.URL;
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import junit.framework.Assert;
023: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
024: import org.apache.geronimo.schema.SchemaConversionUtils;
025: import org.apache.geronimo.testsupport.XmlBeansTestSupport;
026: import org.apache.xmlbeans.XmlCursor;
027: import org.apache.xmlbeans.XmlObject;
028:
029: /**
030: * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should
031: * work for both.
032: *
033: * @version $Rev: 451417 $ $Date: 2006-09-29 13:13:22 -0700 (Fri, 29 Sep 2006) $
034: */
035: public class SchemaConversionTest extends XmlBeansTestSupport {
036: private ClassLoader classLoader = this .getClass().getClassLoader();
037:
038: // Dain: I don't believe we need this test anymore since openejb is doing the converstions.
039: public void testNothing() {
040: }
041:
042: public void XtestEJB11ToEJB21Transform() throws Exception {
043: URL srcXml = classLoader
044: .getResource("j2ee_1_2dtd/ejb-1-11.xml");
045: URL expectedOutputXml = classLoader
046: .getResource("j2ee_1_2dtd/ejb-1-21.xml");
047: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
048: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
049: XmlBeansUtil.validateDD(expected);
050: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
051: // log.debug(xmlObject.toString());
052: // log.debug(expected.toString());
053: List problems = new ArrayList();
054: boolean ok = compareXmlObjects(xmlObject, expected, problems);
055: Assert.assertTrue("Differences: " + problems, ok);
056: //make sure trying to convert twice has no bad effects
057: XmlCursor cursor2 = xmlObject.newCursor();
058: try {
059: String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
060: String version = "2.1";
061: Assert.assertFalse(SchemaConversionUtils.convertToSchema(
062: cursor2, SchemaConversionUtils.J2EE_NAMESPACE,
063: schemaLocationURL, version));
064: } finally {
065: cursor2.dispose();
066: }
067: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
068: Assert.assertTrue("Differences after reconverting to schema: "
069: + problems, ok2);
070: //do the whole transform twice...
071: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
072: boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
073: Assert.assertTrue(
074: "Differences after reconverting to ejb schema: "
075: + problems, ok3);
076: }
077:
078: public void XtestEJB20ToEJB21Transform() throws Exception {
079: URL srcXml = classLoader.getResource("j2ee_1_3dtd/ejb-jar.xml");
080: URL expectedOutputXml = classLoader
081: .getResource("j2ee_1_3dtd/ejb-jar-21.xml");
082: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
083: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
084: XmlBeansUtil.validateDD(expected);
085: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
086: // log.debug(xmlObject.toString());
087: // log.debug(expected.toString());
088: List problems = new ArrayList();
089: boolean ok = compareXmlObjects(xmlObject, expected, problems);
090: Assert.assertTrue("Differences: " + problems, ok);
091: //make sure trying to convert twice has no bad effects
092: XmlCursor cursor2 = xmlObject.newCursor();
093: try {
094: String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
095: String version = "2.1";
096: Assert.assertFalse(SchemaConversionUtils.convertToSchema(
097: cursor2, SchemaConversionUtils.J2EE_NAMESPACE,
098: schemaLocationURL, version));
099: } finally {
100: cursor2.dispose();
101: }
102: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
103: Assert.assertTrue("Differences after reconverting to schema: "
104: + problems, ok2);
105: //do the whole transform twice...
106: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
107: boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
108: Assert.assertTrue(
109: "Differences after reconverting to ejb schema: "
110: + problems, ok3);
111: }
112:
113: public void xtestMDB20ToEJB21TransformBugGERONIMO_1649()
114: throws Exception {
115: URL srcXml = classLoader
116: .getResource("j2ee_1_3dtd/mdb-ejb-jar-20-GERONIMO-1649.xml");
117: URL expectedOutputXml = classLoader
118: .getResource("j2ee_1_3dtd/mdb-ejb-jar-21-GERONIMO-1649.xml");
119: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
120: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
121: XmlBeansUtil.validateDD(expected);
122: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
123: // log.debug(xmlObject.toString());
124: // log.debug(expected.toString());
125: List problems = new ArrayList();
126: boolean ok = compareXmlObjects(xmlObject, expected, problems);
127: Assert.assertTrue("Differences: " + problems, ok);
128: //make sure trying to convert twice has no bad effects
129: XmlCursor cursor2 = xmlObject.newCursor();
130: try {
131: String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
132: String version = "2.1";
133: Assert.assertFalse(SchemaConversionUtils.convertToSchema(
134: cursor2, SchemaConversionUtils.J2EE_NAMESPACE,
135: schemaLocationURL, version));
136: } finally {
137: cursor2.dispose();
138: }
139: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
140: Assert.assertTrue("Differences after reconverting to schema: "
141: + problems, ok2);
142: //do the whole transform twice...
143: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
144: boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
145: Assert.assertTrue(
146: "Differences after reconverting to ejb schema: "
147: + problems, ok3);
148: }
149:
150: public void XtestMDB20To21Transform() throws Exception {
151: URL srcXml = classLoader
152: .getResource("j2ee_1_3dtd/mdb-ejb-jar-20.xml");
153: URL expectedOutputXml = classLoader
154: .getResource("j2ee_1_3dtd/mdb-ejb-jar-21.xml");
155: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
156: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
157: XmlBeansUtil.validateDD(expected);
158: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
159: // log.debug(xmlObject.toString());
160: // log.debug(expected.toString());
161: List problems = new ArrayList();
162: boolean ok = compareXmlObjects(xmlObject, expected, problems);
163: Assert.assertTrue("Differences: " + problems, ok);
164: //make sure trying to convert twice has no bad effects
165: XmlCursor cursor2 = xmlObject.newCursor();
166: try {
167: String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/ejb-jar_2_1.xsd";
168: String version = "2.1";
169: Assert.assertFalse(SchemaConversionUtils.convertToSchema(
170: cursor2, SchemaConversionUtils.J2EE_NAMESPACE,
171: schemaLocationURL, version));
172: } finally {
173: cursor2.dispose();
174: }
175: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
176: Assert.assertTrue("Differences after reconverting to schema: "
177: + problems, ok2);
178: //do the whole transform twice...
179: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
180: boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
181: Assert.assertTrue(
182: "Differences after reconverting to ejb schema: "
183: + problems, ok3);
184: }
185:
186: public void XtestEJB21To21DoesNothing() throws Exception {
187: URL srcXml = classLoader
188: .getResource("j2ee_1_4schema/ejb-jar.xml");
189: URL expectedOutputXml = classLoader
190: .getResource("j2ee_1_4schema/ejb-jar.xml");
191: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
192: xmlObject = XmlUtil.convertToEJBSchema(xmlObject);
193: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
194: List problems = new ArrayList();
195: boolean ok = compareXmlObjects(xmlObject, expected, problems);
196: Assert.assertTrue("Differences: " + problems, ok);
197: }
198:
199: }
|