KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cactus > integration > ant > deployment > application > TestApplicationXmlVersion


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.application;
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 ApplicationXmlVersion}.
33  *
34  * @version $Id: TestApplicationXmlVersion.java,v 1.1 2004/05/31 20:05:22 vmassol Exp $
35  */

36 public final class TestApplicationXmlVersion 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 1.2 to version 1.2 yields zero.
57      *
58      * @throws Exception If an unexpected error occurs
59      */

60     public void testCompare12To12() throws Exception JavaDoc
61     {
62         assertTrue(ApplicationXmlVersion.V1_2.compareTo(
63             ApplicationXmlVersion.V1_2) == 0);
64     }
65
66     /**
67      * Verifies that comparing version 1.2 to version 1.3 yields a negative
68      * value.
69      *
70      * @throws Exception If an unexpected error occurs
71      */

72     public void testCompare12To13() throws Exception JavaDoc
73     {
74         assertTrue(ApplicationXmlVersion.V1_2.compareTo(
75             ApplicationXmlVersion.V1_3) < 0);
76     }
77
78     /**
79      * Verifies that comparing version 1.3 to version 1.3 yields zero.
80      *
81      * @throws Exception If an unexpected error occurs
82      */

83     public void testCompare13To13() throws Exception JavaDoc
84     {
85         assertTrue(ApplicationXmlVersion.V1_3.compareTo(
86             ApplicationXmlVersion.V1_3) == 0);
87     }
88
89     /**
90      * Verifies that comparing version 1.2 to version 1.3 yields a negative
91      * value.
92      *
93      * @throws Exception If an unexpected error occurs
94      */

95     public void testCompare13To12() throws Exception JavaDoc
96     {
97         assertTrue(ApplicationXmlVersion.V1_3.compareTo(
98             ApplicationXmlVersion.V1_2) > 0);
99     }
100
101     /**
102      * Verifies that calling ApplicationXmlVersion.valueOf(null) throws a
103      * NullPointerException.
104      *
105      * @throws Exception If an unexpected error occurs
106      */

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

126     public void testValueOfUnknownDocType() throws Exception JavaDoc
127     {
128         DocumentType JavaDoc docType = domImpl.createDocumentType("application",
129             "foo", "bar");
130         assertNull(ApplicationXmlVersion.valueOf(docType));
131     }
132
133     /**
134      * Verifies that calling ApplicationXmlVersion.valueOf() with a application
135      * 1.2 document type returns the correct instance.
136      *
137      * @throws Exception If an unexpected error occurs
138      */

139     public void testValueOfDocType12() throws Exception JavaDoc
140     {
141         DocumentType JavaDoc docType = domImpl.createDocumentType("application",
142             ApplicationXmlVersion.V1_2.getPublicId(),
143             ApplicationXmlVersion.V1_2.getSystemId());
144         assertEquals(ApplicationXmlVersion.V1_2,
145             ApplicationXmlVersion.valueOf(docType));
146     }
147
148     /**
149      * Verifies that calling ApplicationXmlVersion.valueOf() with a application
150      * 1.3 document type returns the correct instance.
151      *
152      * @throws Exception If an unexpected error occurs
153      */

154     public void testValueOfDocType13() throws Exception JavaDoc
155     {
156         DocumentType JavaDoc docType = domImpl.createDocumentType("application",
157             ApplicationXmlVersion.V1_3.getPublicId(),
158             ApplicationXmlVersion.V1_3.getSystemId());
159         assertEquals(ApplicationXmlVersion.V1_3,
160             ApplicationXmlVersion.valueOf(docType));
161     }
162
163 }
164
Popular Tags