01: /**
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */package org.apache.geronimo.connector.deployment;
17:
18: import java.net.URL;
19: import java.util.ArrayList;
20: import java.util.List;
21:
22: import org.apache.commons.logging.Log;
23: import org.apache.commons.logging.LogFactory;
24: import org.apache.geronimo.deployment.xmlbeans.XmlBeansUtil;
25: import org.apache.geronimo.schema.SchemaConversionUtils;
26: import org.apache.geronimo.testsupport.XmlBeansTestSupport;
27: import org.apache.xmlbeans.XmlCursor;
28: import org.apache.xmlbeans.XmlObject;
29:
30: /**
31: * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should
32: * work for both.
33: *
34: * @version $Rev: 476049 $ $Date: 2006-11-16 20:35:17 -0800 (Thu, 16 Nov 2006) $
35: */
36: public class SchemaConversionTest extends XmlBeansTestSupport {
37: private static final Log log = LogFactory
38: .getLog(SchemaConversionTest.class);
39:
40: private ClassLoader classLoader = this .getClass().getClassLoader();
41:
42: public void testConnector10ToConnector15Transform()
43: throws Exception {
44: URL srcXml = classLoader.getResource("j2ee_1_3dtd/ra-10.xml");
45: URL expectedOutputXml = classLoader
46: .getResource("j2ee_1_3dtd/ra-15.xml");
47: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
48: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
49: XmlBeansUtil.validateDD(expected);
50: xmlObject = ConnectorModuleBuilder
51: .convertToConnectorSchema(xmlObject);
52: // log.debug(xmlObject.toString());
53: // log.debug(expected.toString());
54: List problems = new ArrayList();
55: boolean ok = compareXmlObjects(xmlObject, expected, problems);
56: assertTrue("Differences: " + problems, ok);
57: //make sure trying to convert twice has no bad effects
58: XmlCursor cursor2 = xmlObject.newCursor();
59: try {
60: String schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/connector_1_5.xsd";
61: String version = "1.4";
62: assertFalse(SchemaConversionUtils.convertToSchema(cursor2,
63: SchemaConversionUtils.J2EE_NAMESPACE,
64: schemaLocationURL, version));
65: } finally {
66: cursor2.dispose();
67: }
68: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
69: assertTrue("Differences after reconverting to schema: "
70: + problems, ok2);
71: //do the whole transform twice...
72: xmlObject = ConnectorModuleBuilder
73: .convertToConnectorSchema(xmlObject);
74: boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
75: assertTrue(
76: "Differences after reconverting to application schema: "
77: + problems, ok3);
78: }
79:
80: }
|