KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import java.util.Date JavaDoc;
23
24 import javax.naming.NamingException JavaDoc;
25
26 import javax.naming.directory.Attribute JavaDoc;
27 import javax.naming.directory.Attributes JavaDoc;
28 import javax.naming.directory.DirContext JavaDoc;
29
30 import junit.framework.Test;
31 import junit.framework.TestCase;
32 import junit.framework.TestSuite;
33
34
35 /**
36  * Unit tests for <code>org.apache.naming.resources.FileDirContext</code>.
37  *
38  * @author Craig R. McClanahan
39  * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:55 $
40  */

41
42 public class FileDirContextTestCase extends BaseDirContextTestCase {
43
44
45     // ----------------------------------------------------------- Constructors
46

47
48     /**
49      * Construct a new instance of this test case.
50      *
51      * @param name Name of the test case
52      */

53     public FileDirContextTestCase(String JavaDoc name) {
54
55         super(name);
56
57     }
58
59
60     // --------------------------------------------------- Overall Test Methods
61

62
63     /**
64      * Set up instance variables required by this test case. This method
65      * <strong>MUST</strong> be implemented by a subclass.
66      */

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

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

90     public void tearDown() {
91
92         context = null;
93
94     }
95
96
97     // ------------------------------------------------ Individual Test Methods
98

99
100     /**
101      * Test the attributes returned for the <code>WEB-INF</code> entry.
102      */

103     public void testGetAttributesWebInf() {
104
105         try {
106
107             // Identify a local file object for WEB-INF
108
File JavaDoc docBaseFile = new File JavaDoc(docBase);
109             File JavaDoc webInfFile = new File JavaDoc(docBaseFile, "WEB-INF");
110
111             // Look up the attributes for the WEB-INF entry
112
Attributes JavaDoc attributes = context.getAttributes("WEB-INF");
113
114             // Enumerate and check the attributes for this entry
115
checkWebInfAttributes(attributes,
116                                   new Date JavaDoc(webInfFile.lastModified()),
117                                   webInfFile.length(),
118                                   "WEB-INF",
119                                   new Date JavaDoc(webInfFile.lastModified()));
120
121         } catch (NamingException JavaDoc e) {
122
123             fail("NamingException: " + e);
124
125         }
126
127     }
128
129
130     /**
131      * Test the attributes returned for the <code>WEB-INF/web.xml</code>
132      * entry.
133      */

134     public void testGetAttributesWebXml() {
135
136         try {
137
138             // Identify a local file object for WEB-INF/web.xml
139
File JavaDoc docBaseFile = new File JavaDoc(docBase);
140             File JavaDoc webInfFile = new File JavaDoc(docBaseFile, "WEB-INF");
141             File JavaDoc webXmlFile = new File JavaDoc(webInfFile, "web.xml");
142
143             // Look up the attributes for the WEB-INF entry
144
Attributes JavaDoc attributes = context.getAttributes("WEB-INF/web.xml");
145
146             // Enumerate and check the attributes for this entry
147
checkWebXmlAttributes(attributes,
148                                   new Date JavaDoc(webXmlFile.lastModified()),
149                                   webXmlFile.length(),
150                                   "web.xml",
151                                   new Date JavaDoc(webXmlFile.lastModified()));
152
153         } catch (NamingException JavaDoc e) {
154
155             fail("NamingException: " + e);
156
157         }
158
159     }
160
161
162 }
163
164
165
166
Popular Tags