1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.awt.EventQueue ; 23 import java.beans.PropertyChangeEvent ; 24 import java.util.Arrays ; 25 import java.util.HashSet ; 26 import java.util.Locale ; 27 import java.util.Set ; 28 import org.netbeans.api.project.ProjectManager; 29 import org.netbeans.modules.apisupport.project.TestBase; 30 import org.netbeans.modules.apisupport.project.suite.SuiteProject; 31 import org.netbeans.modules.apisupport.project.suite.SuiteProjectTest; 32 import org.netbeans.modules.apisupport.project.ui.SuiteLogicalView.SuiteRootNode; 33 import org.netbeans.spi.project.support.ant.AntProjectHelper; 34 import org.netbeans.spi.project.support.ant.EditableProperties; 35 import org.netbeans.spi.project.ui.LogicalViewProvider; 36 import org.openide.filesystems.FileObject; 37 import org.openide.loaders.DataObject; 38 import org.openide.nodes.Node; 39 import org.openide.nodes.NodeAdapter; 40 import org.openide.util.Mutex; 41 import org.openide.util.RequestProcessor; 42 43 48 public class SuiteLogicalViewTest extends TestBase { 49 50 public SuiteLogicalViewTest(String name) { 51 super(name); 52 } 53 54 public void testModulesNode() throws Exception { 55 SuiteProject suite1 = generateSuite("suite1"); 56 TestBase.generateSuiteComponent(suite1, "module1a"); 57 Node modulesNode = new ModulesNodeFactory.ModulesNode(suite1); 58 modulesNode.getChildren().getNodes(true); waitForGUIUpdate(); 60 assertEquals("one children", 1, modulesNode.getChildren().getNodes(true).length); 61 62 final ModulesNodeFactory.ModulesNode.ModuleChildren children = (ModulesNodeFactory.ModulesNode.ModuleChildren) modulesNode.getChildren(); 63 TestBase.generateSuiteComponent(suite1, "module1b"); 64 waitForGUIUpdate(); 65 assertEquals("two children", 2, children.getNodes(true).length); 66 TestBase.generateSuiteComponent(suite1, "module1c"); 67 ProjectManager.mutex().writeAccess(new Mutex.Action<Void >() { 68 public Void run() { 69 children.stateChanged(null); return null; } 72 }); 73 waitForGUIUpdate(); 74 assertEquals("three children", 3, children.getNodes(true).length); 75 } 76 77 public void testNameAndDisplayName() throws Exception { 78 SuiteProject p = generateSuite("Sweet Stuff"); 79 Node n = p.getLookup().lookup(LogicalViewProvider.class).createLogicalView(); 80 assertEquals("Sweet Stuff", n.getName()); 81 assertEquals("Sweet Stuff", n.getDisplayName()); 82 NL nl = new NL(); 83 n.addNodeListener(nl); 84 EditableProperties ep = p.getHelper().getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 85 ep.setProperty("app.name", "sweetness"); 86 ep.setProperty("app.title", "Sweetness is Now!"); 87 p.getHelper().putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 88 assertEquals(new HashSet <String >(Arrays.asList(Node.PROP_NAME, Node.PROP_DISPLAY_NAME)), nl.changed); 89 assertEquals("Sweetness is Now!", n.getName()); 90 assertEquals("Sweetness is Now!", n.getDisplayName()); 91 } 92 93 public void testProjectFiles() throws Exception { 94 SuiteProject suite = generateSuite("suite"); 95 TestBase.generateSuiteComponent(suite, "module"); 96 SuiteProjectTest.openSuite(suite); 97 SuiteRootNode rootNode = (SuiteRootNode) suite.getLookup().lookup(LogicalViewProvider.class).createLogicalView(); 98 Set <FileObject> expected = new HashSet <FileObject>(Arrays.asList( 99 suite.getProjectDirectory().getFileObject("nbproject"), 100 suite.getProjectDirectory().getFileObject("build.xml") 101 )); 102 assertTrue(expected.equals(rootNode.getProjectFiles())); 103 } 104 105 public void testImportantFiles() throws Exception { 106 Locale.setDefault(Locale.US); 108 109 SuiteProject suite = generateSuite("sweet"); 110 FileObject master = suite.getProjectDirectory().createData("master.jnlp"); 111 112 LogicalViewProvider viewProv = suite.getLookup().lookup(LogicalViewProvider.class); 113 Node n = viewProv.createLogicalView(); 114 115 Node[] nodes = n.getChildren().getNodes(true); 116 assertEquals("Now there are two", 2, nodes.length); 117 assertEquals("Named modules", "modules", nodes[0].getName()); 118 assertEquals("Named imp files", "important.files", nodes[1].getName()); 119 120 FileObject projProps = suite.getProjectDirectory().getFileObject("nbproject/project.properties"); 121 assertNotNull(projProps); 122 viewProv.findPath(n, projProps); flushRequestProcessor(); 124 Node nodeForFO = viewProv.findPath(n, projProps); 125 126 assertNotNull("found project.properties node", nodeForFO); 127 assertEquals("Name of node is localized", "Project Properties", nodeForFO.getDisplayName()); 128 129 nodeForFO = viewProv.findPath(n, master); 130 assertNotNull("found master.jnlp node", nodeForFO); 131 assertEquals("same by DataObject", nodeForFO, viewProv.findPath(n, DataObject.find(master))); 132 assertEquals("Name of node is localized", "JNLP Descriptor", nodeForFO.getDisplayName()); 133 134 master.delete(); 135 136 nodeForFO = viewProv.findPath(n, master); 137 assertNull("For file object null", nodeForFO); 138 } 139 140 private static final class NL extends NodeAdapter { 141 public final Set <String > changed = new HashSet <String >(); 142 public void propertyChange(PropertyChangeEvent evt) { 143 changed.add(evt.getPropertyName()); 144 } 145 } 146 147 private void waitForGUIUpdate() throws Exception { 148 EventQueue.invokeAndWait(new Runnable () { public void run() {} }); 149 } 150 151 private void flushRequestProcessor() { 152 RequestProcessor.getDefault().post(new Runnable () { 153 public void run() { 154 } 156 }).waitFinished(); 157 } 158 159 } 160 | Popular Tags |