001: /*
002: * ========================================================================
003: *
004: * Copyright 2003 The Apache Software Foundation.
005: *
006: * Licensed under the Apache License, Version 2.0 (the "License");
007: * you may not use this file except in compliance with the License.
008: * You may obtain a copy of the License at
009: *
010: * http://www.apache.org/licenses/LICENSE-2.0
011: *
012: * Unless required by applicable law or agreed to in writing, software
013: * distributed under the License is distributed on an "AS IS" BASIS,
014: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015: * See the License for the specific language governing permissions and
016: * limitations under the License.
017: *
018: * ========================================================================
019: */
020: package org.apache.cactus.integration.ant.deployment.webapp;
021:
022: import javax.xml.parsers.DocumentBuilderFactory;
023: import javax.xml.parsers.ParserConfigurationException;
024:
025: import junit.framework.TestCase;
026:
027: import org.w3c.dom.DOMImplementation;
028: import org.w3c.dom.DocumentType;
029:
030: /**
031: * Unit tests for {@link WebXmlVersion}.
032: *
033: * @version $Id: TestWebXmlVersion.java 239003 2004-05-31 20:05:27Z vmassol $
034: */
035: public final class TestWebXmlVersion extends TestCase {
036: /**
037: * The DOM implementation
038: */
039: private DOMImplementation domImpl;
040:
041: /**
042: * @see TestCase#setUp
043: */
044: public void setUp() throws ParserConfigurationException {
045: DocumentBuilderFactory factory = DocumentBuilderFactory
046: .newInstance();
047: factory.setValidating(false);
048: factory.setNamespaceAware(false);
049:
050: this .domImpl = factory.newDocumentBuilder()
051: .getDOMImplementation();
052: }
053:
054: /**
055: * Verifies that comparing version 2.2 to version 2.2 yields zero.
056: *
057: * @throws Exception If an unexpected error occurs
058: */
059: public void testCompare22To22() throws Exception {
060: assertTrue(WebXmlVersion.V2_2.compareTo(WebXmlVersion.V2_2) == 0);
061: }
062:
063: /**
064: * Verifies that comparing version 2.2 to version 2.3 yields a negative
065: * value.
066: *
067: * @throws Exception If an unexpected error occurs
068: */
069: public void testCompare22To23() throws Exception {
070: assertTrue(WebXmlVersion.V2_2.compareTo(WebXmlVersion.V2_3) < 0);
071: }
072:
073: /**
074: * Verifies that comparing version 2.3 to version 2.3 yields zero.
075: *
076: * @throws Exception If an unexpected error occurs
077: */
078: public void testCompare23To23() throws Exception {
079: assertTrue(WebXmlVersion.V2_3.compareTo(WebXmlVersion.V2_3) == 0);
080: }
081:
082: /**
083: * Verifies that comparing version 2.2 to version 2.3 yields a negative
084: * value.
085: *
086: * @throws Exception If an unexpected error occurs
087: */
088: public void testCompare23To22() throws Exception {
089: assertTrue(WebXmlVersion.V2_3.compareTo(WebXmlVersion.V2_2) > 0);
090: }
091:
092: /**
093: * Verifies that calling WebXmlVersion.valueOf(null) throws a
094: * NullPointerException.
095: *
096: * @throws Exception If an unexpected error occurs
097: */
098: public void testValueOfNull() throws Exception {
099: try {
100: WebXmlVersion.valueOf((DocumentType) null);
101: fail("Expected NullPointerException");
102: } catch (NullPointerException expected) {
103: // expected
104: }
105: }
106:
107: /**
108: * Verifies that calling WebXmlVersion.valueOf() with a unknown document
109: * type returns null.
110: *
111: * @throws Exception If an unexpected error occurs
112: */
113: public void testValueOfUnknownDocType() throws Exception {
114: DocumentType docType = domImpl.createDocumentType("web-app",
115: "foo", "bar");
116: assertNull(WebXmlVersion.valueOf(docType));
117: }
118:
119: /**
120: * Verifies that calling WebXmlVersion.valueOf() with a web-app 2.2 document
121: * type returns the correct instance.
122: *
123: * @throws Exception If an unexpected error occurs
124: */
125: public void testValueOfDocType22() throws Exception {
126: DocumentType docType = domImpl.createDocumentType("web-app",
127: WebXmlVersion.V2_2.getPublicId(), WebXmlVersion.V2_2
128: .getSystemId());
129: assertEquals(WebXmlVersion.V2_2, WebXmlVersion.valueOf(docType));
130: }
131:
132: /**
133: * Verifies that calling WebXmlVersion.valueOf() with a web-app 2.3 document
134: * type returns the correct instance.
135: *
136: * @throws Exception If an unexpected error occurs
137: */
138: public void testValueOfDocType23() throws Exception {
139: DocumentType docType = domImpl.createDocumentType("web-app",
140: WebXmlVersion.V2_3.getPublicId(), WebXmlVersion.V2_3
141: .getSystemId());
142: assertEquals(WebXmlVersion.V2_3, WebXmlVersion.valueOf(docType));
143: }
144:
145: }
|