1 22 package org.objectweb.petals.classloader; 23 24 import java.io.File ; 25 import java.net.URL ; 26 import java.util.ArrayList ; 27 import java.util.List ; 28 29 import junit.framework.TestCase; 30 31 36 public class LoadersTest extends TestCase { 37 38 private PetalsClassLoader petalsClassLoader; 39 40 public void setUp() throws Exception { 41 List <URL > baseUrls = new ArrayList <URL >(); 42 List <String > classpathLocations = new ArrayList <String >(); 43 String baseDir = this.getClass().getResource(".").toString(); 44 baseDir = baseDir.substring(0, baseDir.indexOf("target")); 45 baseDir = baseDir.substring(baseDir.indexOf(":")+1); 46 baseUrls.add(new URL ("file:" + baseDir.replace(File.separator, "/"))); 47 baseUrls.add(new URL ("file:" + baseDir.replace(File.separator, "/") + "target/test-classes/")); 48 baseUrls.add(new URL ("file:" + baseDir.replace(File.separator, "/") + "target/")); 49 baseUrls.add(new URL ("file:" + baseDir.replace(File.separator, "/") + "src/test-data/junit-3.8.jar")); 50 petalsClassLoader = new PetalsClassLoader(baseUrls.toArray(new URL [0]), 51 classpathLocations); 52 petalsClassLoader.setParentFirst(false); 53 } 54 55 public void testPut() { 56 Loaders loaders = Loaders.getInstance(); 57 loaders.put("test", petalsClassLoader); 58 } 59 60 public void testContains() { 61 Loaders loaders = Loaders.getInstance(); 62 loaders.put("test", petalsClassLoader); 63 assertTrue(loaders.contains("test")); 64 } 65 66 public void testGet() { 67 Loaders loaders = Loaders.getInstance(); 68 loaders.put("test", petalsClassLoader); 69 PetalsClassLoader classLoader = loaders.get("test"); 70 assertEquals(classLoader, petalsClassLoader); 71 } 72 73 public void testGetSharedLibrariesClassLoader() { 74 Loaders loaders = Loaders.getInstance(); 75 assertNotNull(loaders.getSharedLibrariesClassLoader()); 76 } 77 78 public void testRemove() { 79 Loaders loaders = Loaders.getInstance(); 80 loaders.remove("test"); 81 } 82 } 83 | Popular Tags |