1 16 package org.apache.commons.vfs.impl.test; 17 18 import org.apache.commons.vfs.Capability; 19 import org.apache.commons.vfs.FileSystemException; 20 import org.apache.commons.vfs.impl.VFSClassLoader; 21 import org.apache.commons.vfs.test.AbstractProviderTestCase; 22 23 import java.net.URL ; 24 import java.net.URLConnection ; 25 26 31 public class VfsClassLoaderTests 32 extends AbstractProviderTestCase 33 { 34 37 protected Capability[] getRequiredCaps() 38 { 39 return new Capability[] 40 { 41 Capability.READ_CONTENT, 42 Capability.URI 43 }; 44 } 45 46 49 private VFSClassLoader createClassLoader() throws FileSystemException 50 { 51 final VFSClassLoader loader = 52 new VFSClassLoader(getBaseFolder(), getManager()); 53 return loader; 54 } 55 56 59 public void testLoadClass() throws Exception 60 { 61 final VFSClassLoader loader = createClassLoader(); 62 63 final Class testClass = loader.loadClass("code.ClassToLoad"); 64 final Package pack = testClass.getPackage(); 65 assertEquals("code", pack.getName()); 66 verifyPackage(pack, false); 67 68 final Object testObject = testClass.newInstance(); 69 assertEquals("**PRIVATE**", testObject.toString()); 70 } 71 72 75 public void testLoadResource() throws Exception 76 { 77 final VFSClassLoader loader = createClassLoader(); 78 79 final URL resource = loader.getResource("read-tests/file1.txt"); 80 81 assertNotNull(resource); 82 final URLConnection urlCon = resource.openConnection(); 83 assertSameURLContent(FILE1_CONTENT, urlCon); 84 } 85 86 89 public void testSealing() throws Exception 90 { 91 final VFSClassLoader loader = createClassLoader(); 92 final Class testClass = loader.loadClass("code.sealed.AnotherClass"); 93 final Package pack = testClass.getPackage(); 94 assertEquals("code.sealed", pack.getName()); 95 verifyPackage(pack, true); 96 } 97 98 101 private void verifyPackage(final Package pack, 102 final boolean sealed) 103 throws FileSystemException 104 { 105 if (getBaseFolder().getFileSystem().hasCapability(Capability.MANIFEST_ATTRIBUTES)) 106 { 107 assertEquals("ImplTitle", pack.getImplementationTitle()); 108 assertEquals("ImplVendor", pack.getImplementationVendor()); 109 assertEquals("1.1", pack.getImplementationVersion()); 110 assertEquals("SpecTitle", pack.getSpecificationTitle()); 111 assertEquals("SpecVendor", pack.getSpecificationVendor()); 112 assertEquals("1.0", pack.getSpecificationVersion()); 113 assertEquals(sealed, pack.isSealed()); 114 } 115 else 116 { 117 assertNull(pack.getImplementationTitle()); 118 assertNull(pack.getImplementationVendor()); 119 assertNull(pack.getImplementationVersion()); 120 assertNull(pack.getSpecificationTitle()); 121 assertNull(pack.getSpecificationVendor()); 122 assertNull(pack.getSpecificationVersion()); 123 assertFalse(pack.isSealed()); 124 } 125 } 126 127 } 128 | Popular Tags |