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.myfaces.deployment;
017:
018: import java.net.URL;
019: import java.util.List;
020: import java.util.ArrayList;
021:
022: import org.apache.geronimo.testsupport.XmlBeansTestSupport;
023: import org.apache.xmlbeans.XmlObject;
024: import org.apache.xmlbeans.XmlOptions;
025:
026: /**
027: * Schema conversion tests for various faces-config XML files. These are fairly straight-forward
028: * tests as the only tag that must be updated is the <faces-config> tab. The following DTD and XSD
029: * schema versions are tested:
030: *
031: * <ol>
032: * <li>1.0 DTD
033: * <li>1.1 DTD
034: * <li>1.2 XSD
035: * <li>No schema
036: * </ol>
037: */
038: public class SchemaConversionTest extends XmlBeansTestSupport {
039:
040: private ClassLoader classLoader = this .getClass().getClassLoader();
041: private XmlOptions options = new XmlOptions();
042:
043: /**
044: * Tests for empty faces-config.xml files
045: */
046: public void testFacesConfig10Empty() throws Exception {
047: URL srcXML = classLoader
048: .getResource("1_0_dtd/faces-config-empty-src.xml");
049: URL expectedXML = classLoader
050: .getResource("1_0_dtd/faces-config-empty-expected.xml");
051: parseAndCompare(srcXML, expectedXML);
052: }
053:
054: public void testFacesConfig11Empty() throws Exception {
055: URL srcXML = classLoader
056: .getResource("1_1_dtd/faces-config-empty-src.xml");
057: URL expectedXML = classLoader
058: .getResource("1_0_dtd/faces-config-empty-expected.xml");
059: parseAndCompare(srcXML, expectedXML);
060: }
061:
062: public void testFacesConfig12Empty() throws Exception {
063: URL srcXML = classLoader
064: .getResource("1_2_xsd/faces-config-empty-src.xml");
065: URL expectedXML = classLoader
066: .getResource("1_0_dtd/faces-config-empty-expected.xml");
067: parseAndCompare(srcXML, expectedXML);
068: }
069:
070: public void testFacesConfigNoSchemaEmpty() throws Exception {
071: URL srcXML = classLoader
072: .getResource("no_schema/faces-config-empty-src.xml");
073: URL expectedXML = classLoader
074: .getResource("1_0_dtd/faces-config-empty-expected.xml");
075: parseAndCompare(srcXML, expectedXML);
076: }
077:
078: /**
079: * Tests for simple faces-config.xml files
080: */
081: public void testFacesConfig10Simple() throws Exception {
082: URL srcXML = classLoader
083: .getResource("1_0_dtd/faces-config-simple-src.xml");
084: URL expectedXML = classLoader
085: .getResource("1_0_dtd/faces-config-simple-expected.xml");
086: parseAndCompare(srcXML, expectedXML);
087: }
088:
089: public void testFacesConfig11Simple() throws Exception {
090: URL srcXML = classLoader
091: .getResource("1_1_dtd/faces-config-simple-src.xml");
092: URL expectedXML = classLoader
093: .getResource("1_0_dtd/faces-config-simple-expected.xml");
094: parseAndCompare(srcXML, expectedXML);
095: }
096:
097: public void testFacesConfig12Simple() throws Exception {
098: URL srcXML = classLoader
099: .getResource("1_2_xsd/faces-config-simple-src.xml");
100: URL expectedXML = classLoader
101: .getResource("1_0_dtd/faces-config-simple-expected.xml");
102: parseAndCompare(srcXML, expectedXML);
103: }
104:
105: public void testFacesConfigNoSchemaSimple() throws Exception {
106: URL srcXML = classLoader
107: .getResource("no_schema/faces-config-simple-src.xml");
108: URL expectedXML = classLoader
109: .getResource("1_0_dtd/faces-config-simple-expected.xml");
110: parseAndCompare(srcXML, expectedXML);
111: }
112:
113: /**
114: * Tests for somewhat moderate faces-config.xml files
115: */
116: public void testFacesConfig10Moderate() throws Exception {
117: URL srcXML = classLoader
118: .getResource("1_0_dtd/faces-config-moderate-src.xml");
119: URL expectedXML = classLoader
120: .getResource("1_0_dtd/faces-config-moderate-expected.xml");
121: parseAndCompare(srcXML, expectedXML);
122: }
123:
124: public void testFacesConfig11Moderate() throws Exception {
125: URL srcXML = classLoader
126: .getResource("1_1_dtd/faces-config-moderate-src.xml");
127: URL expectedXML = classLoader
128: .getResource("1_0_dtd/faces-config-moderate-expected.xml");
129: parseAndCompare(srcXML, expectedXML);
130: }
131:
132: public void testFacesConfig12Moderate() throws Exception {
133: URL srcXML = classLoader
134: .getResource("1_2_xsd/faces-config-moderate-src.xml");
135: URL expectedXML = classLoader
136: .getResource("1_0_dtd/faces-config-moderate-expected.xml");
137: parseAndCompare(srcXML, expectedXML);
138: }
139:
140: public void testFacesConfigNoSchemaModerate() throws Exception {
141: URL srcXML = classLoader
142: .getResource("no_schema/faces-config-moderate-src.xml");
143: URL expectedXML = classLoader
144: .getResource("1_0_dtd/faces-config-moderate-expected.xml");
145: parseAndCompare(srcXML, expectedXML);
146: }
147:
148: /**
149: * Tests for slightly more complex faces-config.xml files
150: */
151: public void testFacesConfig10Complex() throws Exception {
152: URL srcXML = classLoader
153: .getResource("1_0_dtd/faces-config-complex-src.xml");
154: URL expectedXML = classLoader
155: .getResource("1_0_dtd/faces-config-complex-expected.xml");
156: parseAndCompare(srcXML, expectedXML);
157: }
158:
159: public void testFacesConfig11Complex() throws Exception {
160: URL srcXML = classLoader
161: .getResource("1_1_dtd/faces-config-complex-src.xml");
162: URL expectedXML = classLoader
163: .getResource("1_0_dtd/faces-config-complex-expected.xml");
164: parseAndCompare(srcXML, expectedXML);
165: }
166:
167: public void testFacesConfig12Complex() throws Exception {
168: URL srcXML = classLoader
169: .getResource("1_2_xsd/faces-config-complex-src.xml");
170: URL expectedXML = classLoader
171: .getResource("1_0_dtd/faces-config-complex-expected.xml");
172: parseAndCompare(srcXML, expectedXML);
173: }
174:
175: public void testFacesConfigNoSchemaComplex() throws Exception {
176: URL srcXML = classLoader
177: .getResource("no_schema/faces-config-complex-src.xml");
178: URL expectedXML = classLoader
179: .getResource("1_0_dtd/faces-config-complex-expected.xml");
180: parseAndCompare(srcXML, expectedXML);
181: }
182:
183: /**
184: * Common logic
185: */
186: private void parseAndCompare(URL srcXML, URL expectedXML)
187: throws Exception {
188: XmlObject xmlObject = XmlObject.Factory.parse(srcXML, options);
189: xmlObject = MyFacesModuleBuilderExtension
190: .convertToFacesConfigSchema(xmlObject);
191: XmlObject expected = XmlObject.Factory.parse(expectedXML);
192: log.debug("[Source XML] " + '\n' + xmlObject.toString() + '\n');
193: log.debug("[Expected XML]" + '\n' + expected.toString() + '\n');
194: List problems = new ArrayList();
195: boolean ok = compareXmlObjects(xmlObject, expected, problems);
196: assertTrue("Differences: " + problems, ok);
197: xmlObject = MyFacesModuleBuilderExtension
198: .convertToFacesConfigSchema(xmlObject);
199: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
200: assertTrue("Differences: " + problems, ok2);
201: }
202: }
|