1 16 17 18 package org.apache.naming.resources; 19 20 import java.io.File ; 21 import java.io.IOException ; 22 23 import java.util.Date ; 24 25 import java.util.jar.JarEntry ; 26 import java.util.jar.JarFile ; 27 28 import javax.naming.NamingException ; 29 30 import javax.naming.directory.Attribute ; 31 import javax.naming.directory.Attributes ; 32 import javax.naming.directory.DirContext ; 33 34 import junit.framework.Test; 35 import junit.framework.TestCase; 36 import junit.framework.TestSuite; 37 38 39 45 46 public class WARDirContextTestCase extends BaseDirContextTestCase { 47 48 49 51 52 57 public WARDirContextTestCase(String name) { 58 59 super(name); 60 61 } 62 63 64 66 67 71 public void setUp() { 72 73 context = new WARDirContext(); 74 ((WARDirContext) context).setDocBase(docBase); 75 76 } 77 78 79 83 public static Test suite() { 84 85 return (new TestSuite(WARDirContextTestCase.class)); 86 87 } 88 89 90 94 public void tearDown() { 95 96 context = null; 97 98 } 99 100 101 103 104 107 public void testGetAttributesWebInf() { 108 109 try { 110 111 JarFile jarFile = new JarFile (docBase); 113 assertNotNull("Created JarFile for " + docBase, jarFile); 114 JarEntry jarEntry = 115 (JarEntry ) jarFile.getEntry("WEB-INF"); 116 assertNotNull("Created JarEntry for WEB-INF", jarEntry); 117 118 Attributes attributes = context.getAttributes("WEB-INF"); 120 121 checkWebInfAttributes(attributes, 123 new Date (jarEntry.getTime()), 124 jarEntry.getSize(), 125 "WEB-INF", 126 new Date (jarEntry.getTime())); 127 128 } catch (IOException e) { 129 130 fail("IOException: " + e); 131 132 } catch (NamingException e) { 133 134 fail("NamingException: " + e); 135 136 } 137 138 } 139 140 141 145 public void testGetAttributesWebXml() { 146 147 try { 148 149 JarFile jarFile = new JarFile (docBase); 151 assertNotNull("Created JarFile for " + docBase, jarFile); 152 JarEntry jarEntry = 153 (JarEntry ) jarFile.getEntry("WEB-INF/web.xml"); 154 assertNotNull("Created JarEntry for WEB-INF/web.xml", jarEntry); 155 156 Attributes attributes = context.getAttributes("WEB-INF/web.xml"); 158 159 checkWebXmlAttributes(attributes, 161 new Date (jarEntry.getTime()), 162 jarEntry.getSize(), 163 "web.xml", 164 new Date (jarEntry.getTime())); 165 166 } catch (IOException e) { 167 168 fail("IOException: " + e); 169 170 } catch (NamingException e) { 171 172 fail("NamingException: " + e); 173 174 } 175 176 } 177 178 179 } 180 | Popular Tags |