1 16 package org.apache.naming.resources; 17 18 import java.util.Date ; 19 import java.util.Iterator ; 20 import java.util.Map ; 21 22 import javax.naming.Context ; 23 import javax.naming.Name ; 24 25 import javax.naming.directory.DirContext ; 26 import javax.naming.directory.Attributes ; 27 28 import junit.framework.Test; 29 import junit.framework.TestSuite; 30 import junit.textui.TestRunner; 31 32 33 38 public class FileDirContextTest extends AbstractDirContextTest { 39 40 public FileDirContextTest(String name) { 41 super(name); 42 } 43 44 public static void main(String [] args) { 45 TestRunner.run(suite()); 46 } 47 48 public static Test suite() { 49 TestSuite suite = new TestSuite(FileDirContextTest.class); 50 suite.setName("FileDirContext Tests"); 51 return suite; 52 } 53 54 56 protected Context makeInitialContext() { 57 try { 58 FileDirContext fdc = new FileDirContext(); 59 fdc.setDocBase("."); 60 return fdc; 61 } catch (Exception ex) { 62 fail("Failed to create Initial Context"); 63 } 64 return null; 65 } 66 67 70 protected void verifyLookup(Object boundObject, Object returnedObject) { 71 assertTrue(returnedObject instanceof Resource); 72 } 73 74 78 protected void verifyListBindings(Map expected, Map returned) { 79 super.verifyListBindings(expected, returned); 80 Iterator iterator = returned.values().iterator(); 81 while (iterator.hasNext()) { 82 assertTrue(iterator.next() instanceof Resource); 83 } 84 } 85 86 protected boolean isGetNameInNamespaceSupported() { 87 return true; 88 } 89 90 protected boolean isWritable() { 91 return true; 92 } 93 94 96 protected boolean isSchemaSupported() { 97 return false; 98 } 99 100 protected boolean isAttributeModificationSupported() { 101 return false; 102 } 103 104 107 public void testAttributes() throws Exception { 108 super.testAttributes(); 109 DirContext context = (DirContext ) initialContext.lookup(firstContextName()+ "/" + secondContextName()); 110 Attributes attrs = (Attributes ) context.getAttributes(firstBoundName()); 111 Date creationDate = (Date ) attrs.get(ResourceAttributes.CREATION_DATE).get(); 112 assertTrue(creationDate.before(new Date ())); 113 Date modifiedDate = (Date ) attrs.get(ResourceAttributes.LAST_MODIFIED).get(); 114 assertTrue(modifiedDate.equals(creationDate)); 115 String displayName = (String ) attrs.get(ResourceAttributes.NAME).get(); 116 assertEquals(displayName, firstBoundName()); 117 long contentLength = ((Long ) attrs.get(ResourceAttributes.CONTENT_LENGTH).get()).longValue(); 118 assertEquals(contentLength, bytes.length); 119 String resourceType = (String ) attrs.get(ResourceAttributes.TYPE).get(); 120 assertEquals(resourceType, ""); assertNull(attrs.get(ResourceAttributes.CONTENT_TYPE)); assertNull(attrs.get(ResourceAttributes.SOURCE)); assertNull(attrs.get(ResourceAttributes.ETAG)); } 125 126 public void testGetNameInNamespace() throws Exception { 127 super.testGetNameInNamespace(); 128 Name name = nameParser.parse(firstContext.getNameInNamespace()); 129 assertTrue(name.endsWith(nameParser.parse(firstContextName()))); 130 name = nameParser.parse(secondContext.getNameInNamespace()); 131 assertTrue(name.endsWith(nameParser.parse(secondContextName()))); 132 } 133 } 134 | Popular Tags |