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: import java.io.IOException;
021:
022: import java.util.Date;
023:
024: import java.util.jar.JarEntry;
025: import java.util.jar.JarFile;
026:
027: import javax.naming.NamingException;
028:
029: import javax.naming.directory.Attribute;
030: import javax.naming.directory.Attributes;
031: import javax.naming.directory.DirContext;
032:
033: import junit.framework.Test;
034: import junit.framework.TestCase;
035: import junit.framework.TestSuite;
036:
037: /**
038: * Unit tests for <code>org.apache.naming.resources.WARDirContext</code>.
039: *
040: * @author Craig R. McClanahan
041: * @version $Revision: 1.2 $ $Date: 2004/02/27 14:58:55 $
042: */
043:
044: public class WARDirContextTestCase extends BaseDirContextTestCase {
045:
046: // ----------------------------------------------------------- Constructors
047:
048: /**
049: * Construct a new instance of this test case.
050: *
051: * @param name Name of the test case
052: */
053: public WARDirContextTestCase(String name) {
054:
055: super (name);
056:
057: }
058:
059: // --------------------------------------------------- Overall Test Methods
060:
061: /**
062: * Set up instance variables required by this test case. This method
063: * <strong>MUST</strong> be implemented by a subclass.
064: */
065: public void setUp() {
066:
067: context = new WARDirContext();
068: ((WARDirContext) context).setDocBase(docBase);
069:
070: }
071:
072: /**
073: * Return the tests included in this test suite. This method
074: * <strong>MUST</strong> be implemented by a subclass.
075: */
076: public static Test suite() {
077:
078: return (new TestSuite(WARDirContextTestCase.class));
079:
080: }
081:
082: /**
083: * Tear down instance variables required by this test case. This method
084: * <strong>MUST</strong> be implemented by a subclass.
085: */
086: public void tearDown() {
087:
088: context = null;
089:
090: }
091:
092: // ------------------------------------------------ Individual Test Methods
093:
094: /**
095: * Test the attributes returned for the <code>WEB-INF</code> entry.
096: */
097: public void testGetAttributesWebInf() {
098:
099: try {
100:
101: // Look up the attributes of this WAR file entry
102: JarFile jarFile = new JarFile(docBase);
103: assertNotNull("Created JarFile for " + docBase, jarFile);
104: JarEntry jarEntry = (JarEntry) jarFile.getEntry("WEB-INF");
105: assertNotNull("Created JarEntry for WEB-INF", jarEntry);
106:
107: // Look up the attributes for the WEB-INF entry
108: Attributes attributes = context.getAttributes("WEB-INF");
109:
110: // Enumerate and check the attributes for this entry
111: checkWebInfAttributes(attributes, new Date(jarEntry
112: .getTime()), jarEntry.getSize(), "WEB-INF",
113: new Date(jarEntry.getTime()));
114:
115: } catch (IOException e) {
116:
117: fail("IOException: " + e);
118:
119: } catch (NamingException e) {
120:
121: fail("NamingException: " + e);
122:
123: }
124:
125: }
126:
127: /**
128: * Test the attributes returned for the <code>WEB-INF/web.xml</code>
129: * entry.
130: */
131: public void testGetAttributesWebXml() {
132:
133: try {
134:
135: // Look up the attributes of this WAR file entry
136: JarFile jarFile = new JarFile(docBase);
137: assertNotNull("Created JarFile for " + docBase, jarFile);
138: JarEntry jarEntry = (JarEntry) jarFile
139: .getEntry("WEB-INF/web.xml");
140: assertNotNull("Created JarEntry for WEB-INF/web.xml",
141: jarEntry);
142:
143: // Look up the attributes for the WEB-INF/web.xml entry
144: Attributes attributes = context
145: .getAttributes("WEB-INF/web.xml");
146:
147: // Enumerate and check the attributes for this entry
148: checkWebXmlAttributes(attributes, new Date(jarEntry
149: .getTime()), jarEntry.getSize(), "web.xml",
150: new Date(jarEntry.getTime()));
151:
152: } catch (IOException e) {
153:
154: fail("IOException: " + e);
155:
156: } catch (NamingException e) {
157:
158: fail("NamingException: " + e);
159:
160: }
161:
162: }
163:
164: }
|