1 19 20 package org.netbeans.modules.enode; 21 22 import junit.textui.TestRunner; 23 24 import org.netbeans.junit.NbTestCase; 25 import org.netbeans.junit.NbTestSuite; 26 27 import org.openide.ErrorManager; 28 import org.openide.filesystems.*; 29 import org.openide.modules.ModuleInfo; 30 import org.openide.nodes.Node; 31 import org.openide.util.Lookup; 32 33 import org.netbeans.api.enode.ExtensibleNode; 34 import org.netbeans.spi.enode.LookupContentFactory; 35 import org.netbeans.modules.enode.test.*; 36 37 44 public class ExtensibleLookupTest extends NbTestCase { 45 46 private FileObject root; 47 48 public ExtensibleLookupTest(String name) { 49 super(name); 50 } 51 52 public static void main(String [] args) { 53 TestRunner.run(new NbTestSuite(ExtensibleLookupTest.class)); 54 } 55 56 60 protected void setUp () throws Exception { 61 Lookup.getDefault().lookup(ModuleInfo.class); 62 String baseFolder = ExtensibleNode.E_NODE_LOOKUP.substring(1, ExtensibleNode.E_NODE_LOOKUP.length()-1); 63 root = Repository.getDefault().getDefaultFileSystem().findResource(baseFolder); 64 if (root == null) { 65 String s = baseFolder.substring(0, baseFolder.lastIndexOf('/')); 66 FileObject f1 = Repository.getDefault().getDefaultFileSystem().getRoot().getFileObject(s); 67 if (f1 == null) { 68 f1 = Repository.getDefault().getDefaultFileSystem().getRoot().createFolder(s); 69 } 70 root = f1.createFolder(baseFolder.substring(baseFolder.lastIndexOf('/')+1)); 71 } 72 } 73 74 77 protected void tearDown() throws Exception { 78 } 80 81 95 public void testFindObjectInLookup() throws Exception { 96 ExtensibleNode en1 = new ExtensibleNode("test", false); 97 assertNull("No objects at the start", en1.getLookup().lookup(MONodeEnhancer.class)); 98 FileObject test = root.getFileObject("test"); 99 if (test == null) { 100 test = root.createFolder("test"); 101 } 102 FileObject a1 = test.createData("cookie1.instance"); 103 a1.setAttribute("instanceCreate", org.netbeans.spi.enode.LookupContentFactoryManager.create(a1)); 104 a1.setAttribute("factoryClass", "org.netbeans.modules.enode.test.C1Factory"); 105 a1.setAttribute("implements", "org.netbeans.modules.enode.test.MONodeEnhancer"); 106 assertNotNull("Object not found", en1.getLookup().lookup(MONodeEnhancer.class)); 107 a1.delete(); 108 assertNull("Object found but should be gone.", en1.getLookup().lookup(MONodeEnhancer.class)); 109 } 110 111 117 public void testMergingContentOfFolders() throws Exception { 118 ExtensibleNode en1 = new ExtensibleNode("test/t2", true); 119 assertNull("No objects at the start", en1.getLookup().lookup(MONodeEnhancer.class)); 120 FileObject test = root.getFileObject("test"); 121 if (test == null) { 122 test = root.createFolder("test"); 123 } 124 FileObject a1 = test.createData("cookie1.instance"); 125 a1.setAttribute("instanceCreate", org.netbeans.spi.enode.LookupContentFactoryManager.create(a1)); 126 a1.setAttribute("factoryClass", "org.netbeans.modules.enode.test.C1Factory"); 127 a1.setAttribute("implements", "org.netbeans.modules.enode.test.MONodeEnhancer"); 128 assertNotNull("Object not found", en1.getLookup().lookup(MONodeEnhancer.class)); 129 130 a1.delete(); 131 assertNull("Object found but should be gone.", en1.getLookup().lookup(MONodeEnhancer.class)); 132 } 133 } 134 | Popular Tags |