001: /*
002: * Copyright 1999,2004 The Apache Software Foundation.
003: *
004: * Licensed under the Apache License, Version 2.0 (the "License");
005: * you may not use this file except in compliance with the License.
006: * You may obtain a copy of the License at
007: *
008: * http://www.apache.org/licenses/LICENSE-2.0
009: *
010: * Unless required by applicable law or agreed to in writing, software
011: * distributed under the License is distributed on an "AS IS" BASIS,
012: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013: * See the License for the specific language governing permissions and
014: * limitations under the License.
015: */
016:
017: package org.apache.naming.resources;
018:
019: import java.io.File;
020:
021: import java.util.Date;
022:
023: import javax.naming.NamingException;
024:
025: import javax.naming.directory.Attribute;
026: import javax.naming.directory.Attributes;
027: import javax.naming.directory.DirContext;
028:
029: import junit.framework.Test;
030: import junit.framework.TestCase;
031: import junit.framework.TestSuite;
032:
033: /**
034: * Unit tests for <code>org.apache.naming.resources.FileDirContext</code>.
035: *
036: * @author Craig R. McClanahan
037: * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:55 $
038: */
039:
040: public class FileDirContextTestCase extends BaseDirContextTestCase {
041:
042: // ----------------------------------------------------------- Constructors
043:
044: /**
045: * Construct a new instance of this test case.
046: *
047: * @param name Name of the test case
048: */
049: public FileDirContextTestCase(String name) {
050:
051: super (name);
052:
053: }
054:
055: // --------------------------------------------------- Overall Test Methods
056:
057: /**
058: * Set up instance variables required by this test case. This method
059: * <strong>MUST</strong> be implemented by a subclass.
060: */
061: public void setUp() {
062:
063: context = new FileDirContext();
064: ((FileDirContext) context).setDocBase(docBase);
065:
066: }
067:
068: /**
069: * Return the tests included in this test suite. This method
070: * <strong>MUST</strong> be implemented by a subclass.
071: */
072: public static Test suite() {
073:
074: return (new TestSuite(FileDirContextTestCase.class));
075:
076: }
077:
078: /**
079: * Tear down instance variables required by this test case. This method
080: * <strong>MUST</strong> be implemented by a subclass.
081: */
082: public void tearDown() {
083:
084: context = null;
085:
086: }
087:
088: // ------------------------------------------------ Individual Test Methods
089:
090: /**
091: * Test the attributes returned for the <code>WEB-INF</code> entry.
092: */
093: public void testGetAttributesWebInf() {
094:
095: try {
096:
097: // Identify a local file object for WEB-INF
098: File docBaseFile = new File(docBase);
099: File webInfFile = new File(docBaseFile, "WEB-INF");
100:
101: // Look up the attributes for the WEB-INF entry
102: Attributes attributes = context.getAttributes("WEB-INF");
103:
104: // Enumerate and check the attributes for this entry
105: checkWebInfAttributes(attributes, new Date(webInfFile
106: .lastModified()), webInfFile.length(), "WEB-INF",
107: new Date(webInfFile.lastModified()));
108:
109: } catch (NamingException e) {
110:
111: fail("NamingException: " + e);
112:
113: }
114:
115: }
116:
117: /**
118: * Test the attributes returned for the <code>WEB-INF/web.xml</code>
119: * entry.
120: */
121: public void testGetAttributesWebXml() {
122:
123: try {
124:
125: // Identify a local file object for WEB-INF/web.xml
126: File docBaseFile = new File(docBase);
127: File webInfFile = new File(docBaseFile, "WEB-INF");
128: File webXmlFile = new File(webInfFile, "web.xml");
129:
130: // Look up the attributes for the WEB-INF entry
131: Attributes attributes = context
132: .getAttributes("WEB-INF/web.xml");
133:
134: // Enumerate and check the attributes for this entry
135: checkWebXmlAttributes(attributes, new Date(webXmlFile
136: .lastModified()), webXmlFile.length(), "web.xml",
137: new Date(webXmlFile.lastModified()));
138:
139: } catch (NamingException e) {
140:
141: fail("NamingException: " + e);
142:
143: }
144:
145: }
146:
147: }
|