KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > deployment > webapp > TestWebXmlVersion


1 /*
2  * ========================================================================
3  *
4  * Copyright 2003 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * ========================================================================
19  */

20 package org.apache.cactus.integration.ant.deployment.webapp;
21
22
23 import javax.xml.parsers.DocumentBuilderFactory JavaDoc;
24 import javax.xml.parsers.ParserConfigurationException JavaDoc;
25
26 import junit.framework.TestCase;
27
28 import org.w3c.dom.DOMImplementation JavaDoc;
29 import org.w3c.dom.DocumentType JavaDoc;
30
31 /**
32  * Unit tests for {@link WebXmlVersion}.
33  *
34  * @version $Id: TestWebXmlVersion.java,v 1.1 2004/05/31 20:05:21 vmassol Exp $
35  */

36 public final class TestWebXmlVersion extends TestCase
37 {
38     /**
39      * The DOM implementation
40      */

41     private DOMImplementation JavaDoc domImpl;
42
43     /**
44      * @see TestCase#setUp
45      */

46     public void setUp() throws ParserConfigurationException JavaDoc
47     {
48         DocumentBuilderFactory JavaDoc factory = DocumentBuilderFactory.newInstance();
49         factory.setValidating(false);
50         factory.setNamespaceAware(false);
51
52         this.domImpl = factory.newDocumentBuilder().getDOMImplementation();
53     }
54
55     /**
56      * Verifies that comparing version 2.2 to version 2.2 yields zero.
57      *
58      * @throws Exception If an unexpected error occurs
59      */

60     public void testCompare22To22() throws Exception JavaDoc
61     {
62         assertTrue(WebXmlVersion.V2_2.compareTo(WebXmlVersion.V2_2) == 0);
63     }
64
65     /**
66      * Verifies that comparing version 2.2 to version 2.3 yields a negative
67      * value.
68      *
69      * @throws Exception If an unexpected error occurs
70      */

71     public void testCompare22To23() throws Exception JavaDoc
72     {
73         assertTrue(WebXmlVersion.V2_2.compareTo(WebXmlVersion.V2_3) < 0);
74     }
75
76     /**
77      * Verifies that comparing version 2.3 to version 2.3 yields zero.
78      *
79      * @throws Exception If an unexpected error occurs
80      */

81     public void testCompare23To23() throws Exception JavaDoc
82     {
83         assertTrue(WebXmlVersion.V2_3.compareTo(WebXmlVersion.V2_3) == 0);
84     }
85
86     /**
87      * Verifies that comparing version 2.2 to version 2.3 yields a negative
88      * value.
89      *
90      * @throws Exception If an unexpected error occurs
91      */

92     public void testCompare23To22() throws Exception JavaDoc
93     {
94         assertTrue(WebXmlVersion.V2_3.compareTo(WebXmlVersion.V2_2) > 0);
95     }
96
97     /**
98      * Verifies that calling WebXmlVersion.valueOf(null) throws a
99      * NullPointerException.
100      *
101      * @throws Exception If an unexpected error occurs
102      */

103     public void testValueOfNull() throws Exception JavaDoc
104     {
105         try
106         {
107             WebXmlVersion.valueOf((DocumentType JavaDoc) null);
108             fail("Expected NullPointerException");
109         }
110         catch (NullPointerException JavaDoc expected)
111         {
112             // expected
113
}
114     }
115
116     /**
117      * Verifies that calling WebXmlVersion.valueOf() with a unknown document
118      * type returns null.
119      *
120      * @throws Exception If an unexpected error occurs
121      */

122     public void testValueOfUnknownDocType() throws Exception JavaDoc
123     {
124         DocumentType JavaDoc docType = domImpl.createDocumentType("web-app",
125             "foo", "bar");
126         assertNull(WebXmlVersion.valueOf(docType));
127     }
128
129     /**
130      * Verifies that calling WebXmlVersion.valueOf() with a web-app 2.2 document
131      * type returns the correct instance.
132      *
133      * @throws Exception If an unexpected error occurs
134      */

135     public void testValueOfDocType22() throws Exception JavaDoc
136     {
137         DocumentType JavaDoc docType = domImpl.createDocumentType("web-app",
138             WebXmlVersion.V2_2.getPublicId(), WebXmlVersion.V2_2.getSystemId());
139         assertEquals(WebXmlVersion.V2_2, WebXmlVersion.valueOf(docType));
140     }
141
142     /**
143      * Verifies that calling WebXmlVersion.valueOf() with a web-app 2.3 document
144      * type returns the correct instance.
145      *
146      * @throws Exception If an unexpected error occurs
147      */

148     public void testValueOfDocType23() throws Exception JavaDoc
149     {
150         DocumentType JavaDoc docType = domImpl.createDocumentType("web-app",
151             WebXmlVersion.V2_3.getPublicId(), WebXmlVersion.V2_3.getSystemId());
152         assertEquals(WebXmlVersion.V2_3, WebXmlVersion.valueOf(docType));
153     }
154
155 }
156
Popular Tags