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.client.builder;
017:
018: import java.net.URL;
019: import java.util.ArrayList;
020: import java.util.List;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
025: import org.apache.geronimo.schema.SchemaConversionUtils;
026: import org.apache.geronimo.testsupport.XmlBeansTestSupport;
027: import org.apache.xmlbeans.XmlCursor;
028: import org.apache.xmlbeans.XmlObject;
029:
030: /**
031: * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should
032: * work for both.
033: *
034: * @version $Rev: 496305 $ $Date: 2007-01-15 05:01:56 -0800 (Mon, 15 Jan 2007) $
035: */
036: public class SchemaConversionTest extends XmlBeansTestSupport {
037: private static final Log log = LogFactory
038: .getLog(SchemaConversionTest.class);
039:
040: private ClassLoader classLoader = this .getClass().getClassLoader();
041:
042: public void testApplicationClient13ToApplicationClient5Transform()
043: throws Exception {
044: URL srcXml = classLoader
045: .getResource("j2ee_1_3dtd/application-client-13.xml");
046: URL expectedOutputXml = classLoader
047: .getResource("j2ee_1_3dtd/application-client-5.xml");
048: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
049: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
050: XmlBeansUtil.validateDD(expected);
051: xmlObject = AppClientModuleBuilder
052: .convertToApplicationClientSchema(xmlObject);
053: // log.debug(xmlObject.toString());
054: // log.debug(expected.toString());
055: List problems = new ArrayList();
056: boolean ok = compareXmlObjects(xmlObject, expected, problems);
057: assertTrue("Differences: " + problems, ok);
058: //make sure trying to convert twice has no bad effects
059: XmlCursor cursor2 = xmlObject.newCursor();
060: try {
061: String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/application_5.xsd";
062: String version = "5";
063: assertFalse(SchemaConversionUtils.convertToSchema(cursor2,
064: SchemaConversionUtils.JAVAEE_NAMESPACE,
065: schemaLocationURL, version));
066: } finally {
067: cursor2.dispose();
068: }
069: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
070: assertTrue("Differences after reconverting to schema: "
071: + problems, ok2);
072: //do the whole transform twice...
073: xmlObject = AppClientModuleBuilder
074: .convertToApplicationClientSchema(xmlObject);
075: boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
076: assertTrue(
077: "Differences after reconverting to application client schema: "
078: + problems, ok3);
079: }
080:
081: public void testApplicationClient14ToApplicationClient5Transform()
082: throws Exception {
083: URL srcXml = classLoader
084: .getResource("j2ee_1_3dtd/application-client-14.xml");
085: URL expectedOutputXml = classLoader
086: .getResource("j2ee_1_3dtd/application-client-5.xml");
087: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
088: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
089: XmlBeansUtil.validateDD(expected);
090: xmlObject = AppClientModuleBuilder
091: .convertToApplicationClientSchema(xmlObject);
092: // log.debug(xmlObject.toString());
093: // log.debug(expected.toString());
094: List problems = new ArrayList();
095: boolean ok = compareXmlObjects(xmlObject, expected, problems);
096: assertTrue("Differences: " + problems, ok);
097: //make sure trying to convert twice has no bad effects
098: XmlCursor cursor2 = xmlObject.newCursor();
099: try {
100: String schemaLocationURL = "http://java.sun.com/xml/ns/javaee/application_5.xsd";
101: String version = "5";
102: assertFalse(SchemaConversionUtils.convertToSchema(cursor2,
103: SchemaConversionUtils.JAVAEE_NAMESPACE,
104: schemaLocationURL, version));
105: } finally {
106: cursor2.dispose();
107: }
108: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
109: assertTrue("Differences after reconverting to schema: "
110: + problems, ok2);
111: //do the whole transform twice...
112: xmlObject = AppClientModuleBuilder
113: .convertToApplicationClientSchema(xmlObject);
114: boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
115: assertTrue(
116: "Differences after reconverting to application client schema: "
117: + problems, ok3);
118: }
119: }
|