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.jasper.deployment;
017:
018: import java.net.URL;
019: import java.util.List;
020: import java.util.ArrayList;
021:
022: import org.apache.commons.logging.Log;
023: import org.apache.commons.logging.LogFactory;
024: import org.apache.geronimo.testsupport.XmlBeansTestSupport;
025: import org.apache.xmlbeans.XmlObject;
026: import org.apache.xmlbeans.XmlOptions;
027:
028: /**
029: * Schema conversion tests for various JSP TLD files. The following DTD and XSD schema versions are
030: * tested:
031: *
032: * <ol>
033: * <li>1.1 DTD
034: * <li>1.2 DTD
035: * <li>2.0 XSD
036: * <li>2.1 XSD
037: * </ol>
038: *
039: * <p><strong>Note(s):</strong>
040: * <ul>
041: * <li>Those tags from the 1.1 and 1.2 DTD that are no longer valid (e.g., jsp-version) are
042: * removed
043: * <li>Valid tags from the 1.1 and 1.2 DTD are converted (e.g., tlibversion to
044: * tlib-version)
045: * <li>The <taglib> root and the <tag> root elements are reordered as necessary (i.e.,
046: * description, display-name)
047: * <li>The <rtexprvalue> tag is inserted in the <attribute> tag if necessary since it was
048: * not required to preceed <type> in 2.0 schema. Default value of false is used.
049: * </ul>
050: */
051: public class SchemaConversionTest extends XmlBeansTestSupport {
052:
053: private static final Log log = LogFactory
054: .getLog(SchemaConversionTest.class);
055: private ClassLoader classLoader = this .getClass().getClassLoader();
056: private XmlOptions options = new XmlOptions();
057:
058: /**
059: * Tests for empty TLD files
060: */
061: public void testTLD11Empty() throws Exception {
062: URL srcXML = classLoader
063: .getResource("1_1_dtd/taglib-empty-src.tld");
064: URL expectedXML = classLoader
065: .getResource("1_1_dtd/taglib-empty-expected.tld");
066: parseAndCompare(srcXML, expectedXML);
067: }
068:
069: public void testTLD12Empty() throws Exception {
070: URL srcXML = classLoader
071: .getResource("1_2_dtd/taglib-empty-src.tld");
072: URL expectedXML = classLoader
073: .getResource("1_1_dtd/taglib-empty-expected.tld");
074: parseAndCompare(srcXML, expectedXML);
075: }
076:
077: public void testTLD20Empty() throws Exception {
078: URL srcXML = classLoader
079: .getResource("2_0_xsd/taglib-empty-src.tld");
080: URL expectedXML = classLoader
081: .getResource("1_1_dtd/taglib-empty-expected.tld");
082: parseAndCompare(srcXML, expectedXML);
083: }
084:
085: public void testTLD21Empty() throws Exception {
086: URL srcXML = classLoader
087: .getResource("2_1_xsd/taglib-empty-src.tld");
088: URL expectedXML = classLoader
089: .getResource("1_1_dtd/taglib-empty-expected.tld");
090: parseAndCompare(srcXML, expectedXML);
091: }
092:
093: /**
094: * Tests for removal of obsolete TLD tags
095: */
096: public void testTLD11Obsolete() throws Exception {
097: URL srcXML = classLoader
098: .getResource("1_1_dtd/taglib-obsolete-src.tld");
099: URL expectedXML = classLoader
100: .getResource("1_1_dtd/taglib-obsolete-expected.tld");
101: parseAndCompare(srcXML, expectedXML);
102: }
103:
104: public void testTLD12Obsolete() throws Exception {
105: URL srcXML = classLoader
106: .getResource("1_2_dtd/taglib-obsolete-src.tld");
107: URL expectedXML = classLoader
108: .getResource("1_1_dtd/taglib-obsolete-expected.tld");
109: parseAndCompare(srcXML, expectedXML);
110: }
111:
112: /**
113: * Tests for reordering TLD tags
114: */
115: public void testTLD11Reorder() throws Exception {
116: URL srcXML = classLoader
117: .getResource("1_1_dtd/taglib-reorder-src.tld");
118: URL expectedXML = classLoader
119: .getResource("1_1_dtd/taglib-reorder-expected.tld");
120: parseAndCompare(srcXML, expectedXML);
121: }
122:
123: public void testTLD12Reorder_1() throws Exception {
124: URL srcXML = classLoader
125: .getResource("1_2_dtd/taglib-reorder-src-1.tld");
126: URL expectedXML = classLoader
127: .getResource("1_1_dtd/taglib-reorder-expected.tld");
128: parseAndCompare(srcXML, expectedXML);
129: }
130:
131: public void testTLD12Reorder_2() throws Exception {
132: URL srcXML = classLoader
133: .getResource("1_2_dtd/taglib-reorder-src-2.tld");
134: URL expectedXML = classLoader
135: .getResource("1_2_dtd/taglib-reorder-expected-2.tld");
136: parseAndCompare(srcXML, expectedXML);
137: }
138:
139: public void testTLD12Reorder_3() throws Exception {
140: URL srcXML = classLoader
141: .getResource("1_2_dtd/taglib-reorder-src-3.tld");
142: URL expectedXML = classLoader
143: .getResource("2_0_xsd/taglib-reorder-expected-3.tld");
144: parseAndCompare(srcXML, expectedXML);
145: }
146:
147: public void testTLD20Reorder_1() throws Exception {
148: URL srcXML = classLoader
149: .getResource("2_0_xsd/taglib-reorder-src-1.tld");
150: URL expectedXML = classLoader
151: .getResource("2_0_xsd/taglib-reorder-expected-1.tld");
152: parseAndCompare(srcXML, expectedXML);
153: }
154:
155: public void testTLD20Reorder_2() throws Exception {
156: URL srcXML = classLoader
157: .getResource("2_0_xsd/taglib-reorder-src-2.tld");
158: URL expectedXML = classLoader
159: .getResource("2_0_xsd/taglib-reorder-expected-2.tld");
160: parseAndCompare(srcXML, expectedXML);
161: }
162:
163: /**
164: * Tests for missing TLD tags
165: */
166: public void testTLD11Missing() throws Exception {
167: URL srcXML = classLoader
168: .getResource("1_1_dtd/taglib-missing-src.tld");
169: URL expectedXML = classLoader
170: .getResource("1_1_dtd/taglib-missing-expected.tld");
171: parseAndCompare(srcXML, expectedXML);
172: }
173:
174: public void testTLD12Missing() throws Exception {
175: URL srcXML = classLoader
176: .getResource("1_2_dtd/taglib-missing-src.tld");
177: URL expectedXML = classLoader
178: .getResource("1_1_dtd/taglib-missing-expected.tld");
179: parseAndCompare(srcXML, expectedXML);
180: }
181:
182: /**
183: * Common logic
184: */
185: private void parseAndCompare(URL srcXML, URL expectedXML)
186: throws Exception {
187: XmlObject xmlObject = XmlObject.Factory.parse(srcXML, options);
188: xmlObject = JspModuleBuilderExtension
189: .convertToTaglibSchema(xmlObject);
190: XmlObject expected = XmlObject.Factory.parse(expectedXML);
191: log.debug("[Source XML] " + '\n' + xmlObject.toString() + '\n');
192: log.debug("[Expected XML]" + '\n' + expected.toString() + '\n');
193: List problems = new ArrayList();
194: boolean ok = compareXmlObjects(xmlObject, expected, problems);
195: assertTrue("Differences: " + problems, ok);
196: xmlObject = JspModuleBuilderExtension
197: .convertToTaglibSchema(xmlObject);
198: boolean ok2 = compareXmlObjects(xmlObject, expected, problems);
199: assertTrue("Differences: " + problems, ok2);
200: }
201: }
|