KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > web25 > deployment > SchemaConversionTest


1 /**
2  * Licensed to the Apache Software Foundation (ASF) under one or more
3  * contributor license agreements. See the NOTICE file distributed with
4  * this work for additional information regarding copyright ownership.
5  * The ASF licenses this file to You under the Apache License, Version 2.0
6  * (the "License"); you may not use this file except in compliance with
7  * the License. You may obtain a copy of the License at
8  *
9  * 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  */

17
18 package org.apache.geronimo.web25.deployment;
19
20 import java.net.URL JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.ArrayList JavaDoc;
23 import java.util.Collection JavaDoc;
24 import java.util.jar.JarFile JavaDoc;
25
26 import org.apache.geronimo.testsupport.XmlBeansTestSupport;
27 import org.apache.geronimo.j2ee.deployment.Module;
28 import org.apache.geronimo.j2ee.deployment.EARContext;
29 import org.apache.geronimo.gbean.AbstractName;
30 import org.apache.geronimo.kernel.Naming;
31 import org.apache.geronimo.kernel.Kernel;
32 import org.apache.geronimo.deployment.ModuleIDBuilder;
33 import org.apache.geronimo.common.DeploymentException;
34 import org.apache.xmlbeans.XmlObject;
35 import org.apache.xmlbeans.XmlException;
36 import org.apache.xmlbeans.XmlOptions;
37
38 /**
39  * @version $Rev: 482336 $ $Date: 2006-12-04 15:12:19 -0500 (Mon, 04 Dec 2006) $
40  */

41 public class SchemaConversionTest extends XmlBeansTestSupport {
42
43     private ClassLoader JavaDoc classLoader = this.getClass().getClassLoader();
44     private XmlOptions options = new XmlOptions();
45     private WebModuleBuilder webModuleBuilder = new WebModuleBuilder(null);
46
47     public void testWeb24To25Transform() throws Exception JavaDoc {
48         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_4schema/web-2-24.xml");
49         URL JavaDoc expectedOutputXml = classLoader.getResource("javaee_5schema/web-2-25.xml");
50         XmlObject xmlObject = XmlObject.Factory.parse(srcXml, options);
51         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
52         XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
53         System.out.println(xmlObject.toString());
54         System.out.println(expected.toString());
55         List JavaDoc problems = new ArrayList JavaDoc();
56         boolean ok = compareXmlObjects(xmlObject, expected, problems);
57         assertTrue("Differences: " + problems, ok);
58         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
59         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
60         assertTrue("Differences: " + problems, ok2);
61     }
62
63     public void testWeb23To25Transform() throws Exception JavaDoc {
64         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_3dtd/web-23.xml");
65         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/web-25.xml");
66         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
67         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
68         XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
69         System.out.println(xmlObject.toString());
70         System.out.println(expected.toString());
71         List JavaDoc problems = new ArrayList JavaDoc();
72         boolean ok = compareXmlObjects(xmlObject, expected, problems);
73         assertTrue("Differences: " + problems, ok);
74         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
75         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
76         assertTrue("Differences: " + problems, ok2);
77     }
78
79     public void testWeb23To25OtherTransform() throws Exception JavaDoc {
80         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_3dtd/web-1-23.xml");
81         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/web-1-25.xml");
82         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
83         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
84 // System.out.println(xmlObject.toString());
85
XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
86         List JavaDoc problems = new ArrayList JavaDoc();
87         boolean ok = compareXmlObjects(xmlObject, expected, problems);
88         assertTrue("Differences: " + problems, ok);
89         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
90         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
91         assertTrue("Differences: " + problems, ok2);
92     }
93
94     public void testWeb22To25Transform1() throws Exception JavaDoc {
95         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_2dtd/web-1-22.xml");
96         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_2dtd/web-1-25.xml");
97         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
98         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
99         XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
100 // System.out.println(xmlObject.toString());
101
// System.out.println(expected.toString());
102
List JavaDoc problems = new ArrayList JavaDoc();
103         boolean ok = compareXmlObjects(xmlObject, expected, problems);
104         assertTrue("Differences: " + problems, ok);
105         xmlObject = webModuleBuilder.convertToServletSchema(xmlObject);
106         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
107         assertTrue("Differences: " + problems, ok2);
108     }
109
110     public void testWebRejectBad25() throws Exception JavaDoc {
111         URL JavaDoc srcXml = classLoader.getResource("javaee_5schema/web-1-25.xml");
112         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
113         try {
114             webModuleBuilder.convertToServletSchema(xmlObject);
115             fail("doc src/test-data/javaee_5schema/web-1-25.xml is invalid, should not have validated");
116         } catch (XmlException e) {
117             //expected
118
}
119     }
120
121     public void testParseWeb25() throws Exception JavaDoc {
122         URL JavaDoc srcXml = classLoader.getResource("javaee_5schema/web-2-25.xml");
123         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
124         webModuleBuilder.convertToServletSchema(xmlObject);
125     }
126
127     private static class WebModuleBuilder extends AbstractWebModuleBuilder {
128
129         protected WebModuleBuilder(Kernel kernel) {
130             super(kernel, null, null, null, null);
131         }
132
133         protected Module createModule(Object JavaDoc plan, JarFile JavaDoc moduleFile, String JavaDoc targetPath, URL JavaDoc specDDUrl, boolean standAlone, String JavaDoc contextRoot, AbstractName earName, Naming naming, ModuleIDBuilder idBuilder) throws DeploymentException {
134             return null;
135         }
136
137         public void initContext(EARContext earContext, Module module, ClassLoader JavaDoc classLoader) throws DeploymentException {
138         }
139
140         public void addGBeans(EARContext earContext, Module module, ClassLoader JavaDoc classLoader, Collection JavaDoc repositories) throws DeploymentException {
141         }
142
143         public String JavaDoc getSchemaNamespace() {
144             return null;
145         }
146     }
147
148
149 }
150
Popular Tags