KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > client > builder > 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.client.builder;
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     public void testApplicationClient13ToApplicationClient14Transform() throws Exception JavaDoc {
43         URL JavaDoc srcXml = classLoader.getResource("j2ee_1_3dtd/application-client-13.xml");
44         URL JavaDoc expectedOutputXml = classLoader.getResource("j2ee_1_3dtd/application-client-14.xml");
45         XmlObject xmlObject = XmlObject.Factory.parse(srcXml);
46         XmlObject expected = XmlObject.Factory.parse(expectedOutputXml);
47         XmlBeansUtil.validateDD(expected);
48         xmlObject = AppClientModuleBuilder.convertToApplicationClientSchema(xmlObject);
49 // log.debug(xmlObject.toString());
50
// log.debug(expected.toString());
51
List JavaDoc problems = new ArrayList JavaDoc();
52         boolean ok = compareXmlObjects(xmlObject, expected, problems);
53         assertTrue("Differences: " + problems, ok);
54         //make sure trying to convert twice has no bad effects
55
XmlCursor cursor2 = xmlObject.newCursor();
56         try {
57             String JavaDoc schemaLocationURL = "http://java.sun.com/xml/ns/j2ee/application_1_4.xsd";
58             String JavaDoc version = "1.4";
59             assertFalse(SchemaConversionUtils.convertToSchema(cursor2, SchemaConversionUtils.J2EE_NAMESPACE, schemaLocationURL, version));
60         } finally {
61             cursor2.dispose();
62         }
63         boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
64         assertTrue("Differences after reconverting to schema: " + problems, ok2);
65         //do the whole transform twice...
66
xmlObject = AppClientModuleBuilder.convertToApplicationClientSchema(xmlObject);
67         boolean ok3 = compareXmlObjects(xmlObject, expected, problems);
68         assertTrue("Differences after reconverting to application client schema: " + problems, ok3);
69     }
70
71 }
72
Popular Tags