1 19 20 package org.netbeans.modules.navigator; 21 22 import java.beans.PropertyVetoException ; 23 import java.io.File ; 24 import java.io.IOException ; 25 import java.net.URL ; 26 import javax.swing.text.Utilities ; 27 import junit.framework.Assert; 28 import org.netbeans.junit.NbTestCase; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 import org.openide.filesystems.LocalFileSystem; 32 import org.openide.filesystems.Repository; 33 import org.openide.filesystems.XMLFileSystem; 34 import org.openide.util.Lookup; 35 import org.openide.util.lookup.Lookups; 36 import org.openide.util.lookup.ProxyLookup; 37 import org.xml.sax.SAXException ; 38 39 45 public class UnitTestUtils extends ProxyLookup { 46 47 public static UnitTestUtils DEFAULT_LOOKUP = null; 48 49 50 public UnitTestUtils() { 51 Assert.assertNull(DEFAULT_LOOKUP); 52 DEFAULT_LOOKUP = this; 53 } 54 55 56 public static void prepareTest(String [] stringLayers) 57 throws IOException , SAXException , PropertyVetoException { 58 prepareTest(stringLayers, null); 59 } 60 61 public static void prepareTest (String [] stringLayers, Lookup lkp) 62 throws IOException , SAXException , PropertyVetoException { 63 URL [] layers = new URL [stringLayers.length]; 64 65 for (int cntr = 0; cntr < layers.length; cntr++) { 66 layers[cntr] = Utilities .class.getResource(stringLayers[cntr]); 67 } 68 69 XMLFileSystem system = new XMLFileSystem(); 70 system.setXmlUrls(layers); 71 72 Repository repository = new Repository(system); 73 74 if (lkp == null) { 75 DEFAULT_LOOKUP.setLookup(new Object [] { repository }, UnitTestUtils.class.getClassLoader()); 76 } else { 77 DEFAULT_LOOKUP.setLookup(new Object [] { repository }, lkp, UnitTestUtils.class.getClassLoader()); 78 } 79 } 80 81 84 private static void setLookup(Object [] instances, ClassLoader cl) { 85 DEFAULT_LOOKUP.setLookups(new Lookup[] { 86 Lookups.fixed(instances), 87 Lookups.metaInfServices(cl), 88 Lookups.singleton(cl), 89 }); 90 } 91 92 private static void setLookup(Object [] instances, Lookup lkp, ClassLoader cl) { 93 DEFAULT_LOOKUP.setLookups(new Lookup[] { 94 lkp, 95 Lookups.fixed(instances), 96 Lookups.metaInfServices(cl), 97 Lookups.singleton(cl), 98 }); 99 } 100 101 102 static { 103 UnitTestUtils.class.getClassLoader().setDefaultAssertionStatus(true); 104 System.setProperty("org.openide.util.Lookup", UnitTestUtils.class.getName()); 105 Assert.assertEquals(UnitTestUtils.class, Lookup.getDefault().getClass()); 106 } 107 108 public static void initLookup() { 109 } 111 112 } 113 | Popular Tags |