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.application;
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 ApplicationXmlVersion}.
032: *
033: * @version $Id: TestApplicationXmlVersion.java 239003 2004-05-31 20:05:27Z vmassol $
034: */
035: public final class TestApplicationXmlVersion 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 1.2 to version 1.2 yields zero.
056: *
057: * @throws Exception If an unexpected error occurs
058: */
059: public void testCompare12To12() throws Exception {
060: assertTrue(ApplicationXmlVersion.V1_2
061: .compareTo(ApplicationXmlVersion.V1_2) == 0);
062: }
063:
064: /**
065: * Verifies that comparing version 1.2 to version 1.3 yields a negative
066: * value.
067: *
068: * @throws Exception If an unexpected error occurs
069: */
070: public void testCompare12To13() throws Exception {
071: assertTrue(ApplicationXmlVersion.V1_2
072: .compareTo(ApplicationXmlVersion.V1_3) < 0);
073: }
074:
075: /**
076: * Verifies that comparing version 1.3 to version 1.3 yields zero.
077: *
078: * @throws Exception If an unexpected error occurs
079: */
080: public void testCompare13To13() throws Exception {
081: assertTrue(ApplicationXmlVersion.V1_3
082: .compareTo(ApplicationXmlVersion.V1_3) == 0);
083: }
084:
085: /**
086: * Verifies that comparing version 1.2 to version 1.3 yields a negative
087: * value.
088: *
089: * @throws Exception If an unexpected error occurs
090: */
091: public void testCompare13To12() throws Exception {
092: assertTrue(ApplicationXmlVersion.V1_3
093: .compareTo(ApplicationXmlVersion.V1_2) > 0);
094: }
095:
096: /**
097: * Verifies that calling ApplicationXmlVersion.valueOf(null) throws a
098: * NullPointerException.
099: *
100: * @throws Exception If an unexpected error occurs
101: */
102: public void testValueOfNull() throws Exception {
103: try {
104: ApplicationXmlVersion.valueOf((DocumentType) null);
105: fail("Expected NullPointerException");
106: } catch (NullPointerException expected) {
107: // expected
108: }
109: }
110:
111: /**
112: * Verifies that calling ApplicationXmlVersion.valueOf() with a unknown
113: * document type returns null.
114: *
115: * @throws Exception If an unexpected error occurs
116: */
117: public void testValueOfUnknownDocType() throws Exception {
118: DocumentType docType = domImpl.createDocumentType(
119: "application", "foo", "bar");
120: assertNull(ApplicationXmlVersion.valueOf(docType));
121: }
122:
123: /**
124: * Verifies that calling ApplicationXmlVersion.valueOf() with a application
125: * 1.2 document type returns the correct instance.
126: *
127: * @throws Exception If an unexpected error occurs
128: */
129: public void testValueOfDocType12() throws Exception {
130: DocumentType docType = domImpl.createDocumentType(
131: "application",
132: ApplicationXmlVersion.V1_2.getPublicId(),
133: ApplicationXmlVersion.V1_2.getSystemId());
134: assertEquals(ApplicationXmlVersion.V1_2, ApplicationXmlVersion
135: .valueOf(docType));
136: }
137:
138: /**
139: * Verifies that calling ApplicationXmlVersion.valueOf() with a application
140: * 1.3 document type returns the correct instance.
141: *
142: * @throws Exception If an unexpected error occurs
143: */
144: public void testValueOfDocType13() throws Exception {
145: DocumentType docType = domImpl.createDocumentType(
146: "application",
147: ApplicationXmlVersion.V1_3.getPublicId(),
148: ApplicationXmlVersion.V1_3.getSystemId());
149: assertEquals(ApplicationXmlVersion.V1_3, ApplicationXmlVersion
150: .valueOf(docType));
151: }
152:
153: }
|