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.web25.deployment;
017:
018: import java.net.URL;
019: import java.util.List;
020: import java.util.ArrayList;
021: import java.util.Collection;
022: import java.util.Collections;
023: import java.util.jar.JarFile;
024:
025: import org.apache.geronimo.testsupport.XmlBeansTestSupport;
026: import org.apache.geronimo.j2ee.deployment.Module;
027: import org.apache.geronimo.j2ee.deployment.EARContext;
028: import org.apache.geronimo.gbean.AbstractName;
029: import org.apache.geronimo.kernel.Naming;
030: import org.apache.geronimo.kernel.Kernel;
031: import org.apache.geronimo.deployment.ModuleIDBuilder;
032: import org.apache.geronimo.common.DeploymentException;
033: import org.apache.xmlbeans.XmlObject;
034: import org.apache.xmlbeans.XmlException;
035: import org.apache.xmlbeans.XmlOptions;
036:
037: /**
038: * @version $Rev: 516226 $ $Date: 2007-03-08 15:31:23 -0800 (Thu, 08 Mar 2007) $
039: */
040: public class SchemaConversionTest extends XmlBeansTestSupport {
041:
042: private ClassLoader classLoader = this .getClass().getClassLoader();
043: private XmlOptions options = new XmlOptions();
044: private WebModuleBuilder webModuleBuilder = new WebModuleBuilder(
045: null);
046:
047: public void testWeb24To25Transform() throws Exception {
048: URL srcXml = classLoader
049: .getResource("j2ee_1_4schema/web-2-24.xml");
050: URL expectedOutputXml = classLoader
051: .getResource("javaee_5schema/web-2-25.xml");
052: XmlObject xmlObject = XmlObject.Factory.parse(srcXml, options);
053: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
054: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
055: log.debug(xmlObject.toString());
056: log.debug(expected.toString());
057: List problems = new ArrayList();
058: boolean ok = compareXmlObjects(xmlObject, expected, problems);
059: assertTrue("Differences: " + problems, ok);
060: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
061: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
062: assertTrue("Differences: " + problems, ok2);
063: }
064:
065: public void testWeb23To25Transform() throws Exception {
066: URL srcXml = classLoader.getResource("j2ee_1_3dtd/web-23.xml");
067: URL expectedOutputXml = classLoader
068: .getResource("j2ee_1_3dtd/web-25.xml");
069: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
070: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
071: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
072: log.debug(xmlObject.toString());
073: log.debug(expected.toString());
074: List problems = new ArrayList();
075: boolean ok = compareXmlObjects(xmlObject, expected, problems);
076: assertTrue("Differences: " + problems, ok);
077: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
078: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
079: assertTrue("Differences: " + problems, ok2);
080: }
081:
082: public void testWeb23To25OtherTransform() throws Exception {
083: URL srcXml = classLoader
084: .getResource("j2ee_1_3dtd/web-1-23.xml");
085: URL expectedOutputXml = classLoader
086: .getResource("j2ee_1_3dtd/web-1-25.xml");
087: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
088: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
089: // log.debug(xmlObject.toString());
090: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
091: List problems = new ArrayList();
092: boolean ok = compareXmlObjects(xmlObject, expected, problems);
093: assertTrue("Differences: " + problems, ok);
094: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
095: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
096: assertTrue("Differences: " + problems, ok2);
097: }
098:
099: public void testWeb22To25Transform1() throws Exception {
100: URL srcXml = classLoader
101: .getResource("j2ee_1_2dtd/web-1-22.xml");
102: URL expectedOutputXml = classLoader
103: .getResource("j2ee_1_2dtd/web-1-25.xml");
104: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
105: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
106: XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
107: // log.debug(xmlObject.toString());
108: // log.debug(expected.toString());
109: List problems = new ArrayList();
110: boolean ok = compareXmlObjects(xmlObject, expected, problems);
111: assertTrue("Differences: " + problems, ok);
112: xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
113: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
114: assertTrue("Differences: " + problems, ok2);
115: }
116:
117: public void testWebRejectBad25() throws Exception {
118: URL srcXml = classLoader
119: .getResource("javaee_5schema/web-1-25.xml");
120: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
121: try {
122: webModuleBuilder.convertToServletSchema(xmlObject);
123: fail("doc src/test-data/javaee_5schema/web-1-25.xml is invalid, should not have validated");
124: } catch (XmlException e) {
125: //expected
126: }
127: }
128:
129: public void testParseWeb25() throws Exception {
130: URL srcXml = classLoader
131: .getResource("javaee_5schema/web-2-25.xml");
132: XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
133: webModuleBuilder.convertToServletSchema(xmlObject);
134: }
135:
136: private static class WebModuleBuilder extends
137: AbstractWebModuleBuilder {
138:
139: protected WebModuleBuilder(Kernel kernel) {
140: super (kernel, null, null, null, null,
141: Collections.EMPTY_SET, null);
142: }
143:
144: protected Module createModule(Object plan, JarFile moduleFile,
145: String targetPath, URL specDDUrl, boolean standAlone,
146: String contextRoot, AbstractName earName,
147: Naming naming, ModuleIDBuilder idBuilder)
148: throws DeploymentException {
149: return null;
150: }
151:
152: public void initContext(EARContext earContext, Module module,
153: ClassLoader classLoader) throws DeploymentException {
154: }
155:
156: public void addGBeans(EARContext earContext, Module module,
157: ClassLoader classLoader, Collection repositories)
158: throws DeploymentException {
159: }
160:
161: public String getSchemaNamespace() {
162: return null;
163: }
164: }
165:
166: }
|