1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.util.ArrayList ; 23 import java.util.Arrays ; 24 import java.util.List ; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.api.project.ProjectManager; 27 import org.netbeans.modules.apisupport.project.TestBase; 28 import org.netbeans.spi.project.ui.LogicalViewProvider; 29 import org.openide.filesystems.FileObject; 30 import org.openide.filesystems.FileUtil; 31 import org.openide.loaders.DataObject; 32 import org.openide.nodes.Children; 33 import org.openide.nodes.FilterNode; 34 import org.openide.nodes.Node; 35 36 40 public class ModuleLogicalViewTest extends TestBase { 41 42 public ModuleLogicalViewTest(String name) { 43 super(name); 44 } 45 46 public void testFindPath() throws Exception { 47 Project freeform = ProjectManager.getDefault().findProject(FileUtil.toFileObject(file("ant/freeform"))); 48 assertNotNull("have project in ant/freeform", freeform); 49 LogicalViewProvider lvp = (LogicalViewProvider) freeform.getLookup().lookup(LogicalViewProvider.class); 50 assertNotNull("have a LogicalViewProvider", lvp); 51 assertNotNull("found arch.xml", find(lvp, "ant/freeform/arch.xml")); 52 assertNotNull("found FreeformProject.java", find(lvp, "ant/freeform/src/org/netbeans/modules/ant/freeform/FreeformProject.java")); 53 assertNotNull("found freeform-project-general.xsd", find(lvp, "ant/freeform/src/org/netbeans/modules/ant/freeform/resources/freeform-project-general.xsd")); 54 assertNotNull("found FreeformProjectTest.java", find(lvp, "ant/freeform/test/unit/src/org/netbeans/modules/ant/freeform/FreeformProjectTest.java")); 55 assertNull("did not find test/cfg-unit.xml", find(lvp, "ant/freeform/test/cfg-unit.xml")); 56 } 58 59 public void testImportantFilesListening() throws Exception { 60 Project p = generateStandaloneModule("module"); 61 LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class); 62 assertNotNull("have a LogicalViewProvider", lvp); 63 Node root = lvp.createLogicalView(); 64 Node iFiles = root.getChildren().findChild(ImportantFilesNodeFactory.IMPORTANT_FILES_NAME); 65 assertNotNull("have the Important Files node", iFiles); 66 iFiles.getChildren().getNodes(true); waitForChildrenUpdate(); 68 assertEquals("five important files", 5, iFiles.getChildren().getNodes(true).length); 69 FileUtil.createData(p.getProjectDirectory(), "nbproject/project.properties"); 70 iFiles.getChildren().getNodes(true); waitForChildrenUpdate(); 72 assertEquals("nbproject/project.properties noticed", 6, iFiles.getChildren().getNodes(true).length); 73 } 74 75 private Node find(LogicalViewProvider lvp, String path) throws Exception { 76 FileObject f = FileUtil.toFileObject(file(path)); 77 assertNotNull("found " + path, f); 78 Node root = new FilterNode(lvp.createLogicalView()); 79 80 lvp.findPath(root, f); waitForChildrenUpdate(); 82 83 Node n = lvp.findPath(root, f); 84 DataObject d = DataObject.find(f); 85 assertEquals("same result for DataObject as for FileObject", n, lvp.findPath(root, d)); 86 if (n != null) { 87 assertEquals("right DataObject", d, n.getLookup().lookup(DataObject.class)); 88 } 89 return n; 90 } 91 92 private void waitForChildrenUpdate() { 93 ImportantFilesNodeFactory.RP.post(new Runnable () { 94 public void run() { 95 } 97 }).waitFinished(); 98 } 99 100 public void testNewlyCreatedSourceRootsDisplayed() throws Exception { Project p = generateStandaloneModule("module"); 102 LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class); 103 Node root = lvp.createLogicalView(); 104 p.getProjectDirectory().getFileObject("test").delete(); 105 Children ch = root.getChildren(); 106 assertEquals(Arrays.asList(new String [] {"${src.dir}", "important.files", "libraries"}), findKids(ch)); 107 115 p.getProjectDirectory().createFolder("javahelp"); 116 assertEquals(Arrays.asList(new String [] {"${src.dir}", "javahelp", "important.files", "libraries"}), findKids(ch)); 118 } 119 120 private static List findKids(Children ch) { 121 List l = new ArrayList (); 122 Node[] kids = ch.getNodes(true); 123 for (int i = 0; i < kids.length; i++) { 124 l.add(kids[i].getName()); 125 } 126 return l; 127 } 128 129 } 130 | Popular Tags |