KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > naming > resources > WARDirContextTestCase


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

16
17
18 package org.apache.naming.resources;
19
20 import java.io.File JavaDoc;
21 import java.io.IOException JavaDoc;
22
23 import java.util.Date JavaDoc;
24
25 import java.util.jar.JarEntry JavaDoc;
26 import java.util.jar.JarFile JavaDoc;
27
28 import javax.naming.NamingException JavaDoc;
29
30 import javax.naming.directory.Attribute JavaDoc;
31 import javax.naming.directory.Attributes JavaDoc;
32 import javax.naming.directory.DirContext JavaDoc;
33
34 import junit.framework.Test;
35 import junit.framework.TestCase;
36 import junit.framework.TestSuite;
37
38
39 /**
40  * Unit tests for <code>org.apache.naming.resources.WARDirContext</code>.
41  *
42  * @author Craig R. McClanahan
43  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:55 $
44  */

45
46 public class WARDirContextTestCase extends BaseDirContextTestCase {
47
48
49     // ----------------------------------------------------------- Constructors
50

51
52     /**
53      * Construct a new instance of this test case.
54      *
55      * @param name Name of the test case
56      */

57     public WARDirContextTestCase(String JavaDoc name) {
58
59         super(name);
60
61     }
62
63
64     // --------------------------------------------------- Overall Test Methods
65

66
67     /**
68      * Set up instance variables required by this test case. This method
69      * <strong>MUST</strong> be implemented by a subclass.
70      */

71     public void setUp() {
72
73         context = new WARDirContext();
74         ((WARDirContext) context).setDocBase(docBase);
75
76     }
77
78
79     /**
80      * Return the tests included in this test suite. This method
81      * <strong>MUST</strong> be implemented by a subclass.
82      */

83     public static Test suite() {
84
85         return (new TestSuite(WARDirContextTestCase.class));
86
87     }
88
89
90     /**
91      * Tear down instance variables required by this test case. This method
92      * <strong>MUST</strong> be implemented by a subclass.
93      */

94     public void tearDown() {
95
96         context = null;
97
98     }
99
100
101     // ------------------------------------------------ Individual Test Methods
102

103
104     /**
105      * Test the attributes returned for the <code>WEB-INF</code> entry.
106      */

107     public void testGetAttributesWebInf() {
108
109         try {
110
111             // Look up the attributes of this WAR file entry
112
JarFile JavaDoc jarFile = new JarFile JavaDoc(docBase);
113             assertNotNull("Created JarFile for " + docBase, jarFile);
114             JarEntry JavaDoc jarEntry =
115                 (JarEntry JavaDoc) jarFile.getEntry("WEB-INF");
116             assertNotNull("Created JarEntry for WEB-INF", jarEntry);
117
118             // Look up the attributes for the WEB-INF entry
119
Attributes JavaDoc attributes = context.getAttributes("WEB-INF");
120
121             // Enumerate and check the attributes for this entry
122
checkWebInfAttributes(attributes,
123                                   new Date JavaDoc(jarEntry.getTime()),
124                                   jarEntry.getSize(),
125                                   "WEB-INF",
126                                   new Date JavaDoc(jarEntry.getTime()));
127
128         } catch (IOException JavaDoc e) {
129
130             fail("IOException: " + e);
131
132         } catch (NamingException JavaDoc e) {
133
134             fail("NamingException: " + e);
135
136         }
137
138     }
139
140
141     /**
142      * Test the attributes returned for the <code>WEB-INF/web.xml</code>
143      * entry.
144      */

145     public void testGetAttributesWebXml() {
146
147         try {
148
149             // Look up the attributes of this WAR file entry
150
JarFile JavaDoc jarFile = new JarFile JavaDoc(docBase);
151             assertNotNull("Created JarFile for " + docBase, jarFile);
152             JarEntry JavaDoc jarEntry =
153                 (JarEntry JavaDoc) jarFile.getEntry("WEB-INF/web.xml");
154             assertNotNull("Created JarEntry for WEB-INF/web.xml", jarEntry);
155
156             // Look up the attributes for the WEB-INF/web.xml entry
157
Attributes JavaDoc attributes = context.getAttributes("WEB-INF/web.xml");
158
159             // Enumerate and check the attributes for this entry
160
checkWebXmlAttributes(attributes,
161                                   new Date JavaDoc(jarEntry.getTime()),
162                                   jarEntry.getSize(),
163                                   "web.xml",
164                                   new Date JavaDoc(jarEntry.getTime()));
165
166         } catch (IOException JavaDoc e) {
167
168             fail("IOException: " + e);
169
170         } catch (NamingException JavaDoc e) {
171
172             fail("NamingException: " + e);
173
174         }
175
176     }
177
178
179 }
180
Popular Tags