KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > j2ee > 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.j2ee.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.deployment.xmlbeans.XmlBeansUtil;
26 import org.apache.geronimo.schema.SchemaConversionUtils;
27 import org.apache.geronimo.testsupport.XmlBeansTestSupport;
28 import org.apache.xmlbeans.XmlCursor;
29 import org.apache.xmlbeans.XmlObject;
30
31 /**
32  * ejb 1.1 dtd appears to be a subset of ejb 2.0 dtd so the same xsl should
33  * work for both.
34  *
35  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
36  */

37 public class SchemaConversionTest extends XmlBeansTestSupport {
38     private static final Log log = LogFactory.getLog(SchemaConversionTest.class);
39
40     private ClassLoader JavaDoc classLoader = this.getClass().getClassLoader();
41
42
43     public void testApplication13ToApplication14Transform() throws Exception JavaDoc {
44         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_3dtd/application-13.xml");
45         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/application-14.xml");
46         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
47         XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
48         XmlBeansUtil.validateDD(expected);
49         xmlObject = EARConfigBuilder.convertToApplicationSchema(xmlObject);
50 // log.debug(xmlObject.toString());
51
// log.debug(expected.toString());
52
List JavaDoc problems = new ArrayList JavaDoc();
53         boolean ok = compareXmlObjects(xmlObject, expected, problems);
54         assertTrue("Differences: " + problems, ok);
55         //make sure trying to convert twice has no bad effects
56
XmlCursor cursor2 = xmlObject.newCursor();
57         try {
58             String JavaDoc schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/application_1_4.xsd";
59             String JavaDoc version = "1.4";
60             assertFalse(SchemaConversionUtils.convertToSchema(cursor2, SchemaConversionUtils.J2EE_NAMESPACE, schemaLocationURL, version));
61         } finally {
62             cursor2.dispose();
63         }
64         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
65         assertTrue("Differences after reconverting to schema: " + problems, ok2);
66         //do the whole transform twice...
67
xmlObject = EARConfigBuilder.convertToApplicationSchema(xmlObject);
68         boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
69         assertTrue("Differences after reconverting to application schema: " + problems, ok3);
70     }
71
72 }
73
Popular Tags