KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > web > 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 package org.apache.geronimo.web.deployment;
18
19 import java.net.URL JavaDoc;
20 import java.util.ArrayList JavaDoc;
21 import java.util.List JavaDoc;
22
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.geronimo.testsupport.XmlBeansTestSupport;
26 import org.apache.xmlbeans.XmlException;
27 import org.apache.xmlbeans.XmlObject;
28
29 /**
30  * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should
31  * work for both.
32  *
33  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
34  */

35 public class SchemaConversionTest extends XmlBeansTestSupport {
36     private static final Log log = LogFactory.getLog(SchemaConversionTest.class);
37
38     private ClassLoader JavaDoc classLoader = this.getClass().getClassLoader();
39
40     public void testWeb23To24Transform() throws Exception JavaDoc {
41         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_3dtd/web-23.xml");
42         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/web-24.xml");
43         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
44         xmlObject = AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
45         XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
46 // log.debug(xmlObject.toString());
47
// log.debug(expected.toString());
48
List JavaDoc problems = new ArrayList JavaDoc();
49         boolean ok = compareXmlObjects(xmlObject, expected, problems);
50         assertTrue("Differences: " + problems, ok);
51         xmlObject = AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
52         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
53         assertTrue("Differences: " + problems, ok2);
54     }
55
56     public void testWeb23To24OtherTransform() throws Exception JavaDoc {
57         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_3dtd/web-1-23.xml");
58         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/web-1-24.xml");
59         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
60         xmlObject = AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
61 // log.debug(xmlObject.toString());
62
XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
63         List JavaDoc problems = new ArrayList JavaDoc();
64         boolean ok = compareXmlObjects(xmlObject, expected, problems);
65         assertTrue("Differences: " + problems, ok);
66         xmlObject = AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
67         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
68         assertTrue("Differences: " + problems, ok2);
69     }
70
71     public void testWeb22To24Transform1() throws Exception JavaDoc {
72         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_2dtd/web-1-22.xml");
73         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_2dtd/web-1-24.xml");
74         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
75         xmlObject = AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
76         XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
77 // log.debug(xmlObject.toString());
78
// log.debug(expected.toString());
79
List JavaDoc problems = new ArrayList JavaDoc();
80         boolean ok = compareXmlObjects(xmlObject, expected, problems);
81         assertTrue("Differences: " + problems, ok);
82         xmlObject = AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
83         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
84         assertTrue("Differences: " + problems, ok2);
85     }
86
87     public void testWebRejectBad24() throws Exception JavaDoc {
88         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_4schema/web-1-24.xml");
89         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
90         try {
91             AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
92             fail("doc src/test-data/j2ee_1_4schema/web-1-24.xml is invalid, should not have validated");
93         } catch (XmlException e) {
94             //expected
95
}
96     }
97
98     public void testParseWeb24() throws Exception JavaDoc {
99         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_4schema/web-2-24.xml");
100         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
101         xmlObject = AbstractWebModuleBuilder.convertToServletSchema(xmlObject);
102         assertNotNull(xmlObject);
103     }
104
105 }
106
Popular Tags