1 19 20 package org.netbeans.modules.derby.test; 21 22 import java.io.File ; 23 import java.io.IOException ; 24 import org.netbeans.junit.NbTestCase; 25 import org.openide.filesystems.Repository; 26 import org.openide.util.Lookup; 27 import org.openide.util.lookup.AbstractLookup; 28 import org.openide.util.lookup.InstanceContent; 29 import org.openide.util.lookup.Lookups; 30 import org.openide.util.lookup.ProxyLookup; 31 32 37 public class TestBase extends NbTestCase { 38 39 static { 40 System.setProperty("org.openide.util.Lookup", Lkp.class.getName()); 41 assertEquals("Unable to set the default lookup!", Lkp.class, Lookup.getDefault().getClass()); 42 43 ((Lkp)Lookup.getDefault()).addFixed(new RepositoryImpl()); 44 assertEquals("The default Repository is not our repository!", RepositoryImpl.class, Lookup.getDefault().lookup(Repository.class).getClass()); 45 } 46 47 public static void setLookup(Object [] instance) { 48 ((Lkp)Lookup.getDefault()).setLookup(instance); 49 } 50 51 public TestBase(String name) { 52 super(name); 53 } 54 55 public static void createFakeDerbyInstallation(File location) throws IOException { 56 if (!location.mkdirs()) { 57 throw new IOException ("Could not create " + location.getAbsolutePath()); 58 } 59 File lib = new File (location, "lib"); 60 if (!lib.mkdir()) { 61 throw new IOException ("Could not create " + lib.getAbsolutePath()); 62 } 63 new File (lib, "derby.jar").createNewFile(); 64 } 65 66 public static final class Lkp extends ProxyLookup { 67 68 private InstanceContent fixed = new InstanceContent(); 69 private Lookup fixedLookup = new AbstractLookup(fixed); 70 71 public Lkp() { 72 setLookup(new Object [0]); 73 } 74 75 void setLookup(Object [] instances) { 76 ClassLoader l = TestBase.class.getClassLoader(); 77 setLookups(new Lookup[] { 78 Lookups.metaInfServices(l), 79 Lookups.singleton(l), 80 fixedLookup, 81 Lookups.fixed(instances), 82 }); 83 } 84 85 void addFixed(Object instance) { 86 fixed.add(instance); 87 } 88 } 89 } 90 | Popular Tags |