001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.apisupport.project.ui;
043:
044: import java.awt.EventQueue;
045: import java.beans.PropertyChangeEvent;
046: import java.util.Arrays;
047: import java.util.HashSet;
048: import java.util.Locale;
049: import java.util.Set;
050: import org.netbeans.api.project.ProjectManager;
051: import org.netbeans.modules.apisupport.project.TestBase;
052: import org.netbeans.modules.apisupport.project.suite.SuiteProject;
053: import org.netbeans.modules.apisupport.project.ui.SuiteLogicalView.SuiteRootNode;
054: import org.netbeans.spi.project.support.ant.AntProjectHelper;
055: import org.netbeans.spi.project.support.ant.EditableProperties;
056: import org.netbeans.spi.project.ui.LogicalViewProvider;
057: import org.openide.filesystems.FileObject;
058: import org.openide.loaders.DataObject;
059: import org.openide.nodes.Node;
060: import org.openide.nodes.NodeAdapter;
061: import org.openide.util.Mutex;
062: import org.openide.util.RequestProcessor;
063:
064: /**
065: * Test functionality of {@link SuiteLogicalView}.
066: *
067: * @author Martin Krauskopf
068: */
069: public class SuiteLogicalViewTest extends TestBase {
070:
071: public SuiteLogicalViewTest(String name) {
072: super (name);
073: }
074:
075: public void testModulesNode() throws Exception {
076: SuiteProject suite1 = generateSuite("suite1");
077: TestBase.generateSuiteComponent(suite1, "module1a");
078: Node modulesNode = new ModulesNodeFactory.ModulesNode(suite1);
079: modulesNode.getChildren().getNodes(true); // "expand the node" simulation
080: waitForGUIUpdate();
081: assertEquals("one children", 1, modulesNode.getChildren()
082: .getNodes(true).length);
083:
084: final ModulesNodeFactory.ModulesNode.ModuleChildren children = (ModulesNodeFactory.ModulesNode.ModuleChildren) modulesNode
085: .getChildren();
086: TestBase.generateSuiteComponent(suite1, "module1b");
087: waitForGUIUpdate();
088: assertEquals("two children", 2, children.getNodes(true).length);
089: TestBase.generateSuiteComponent(suite1, "module1c");
090: ProjectManager.mutex().writeAccess(new Mutex.Action<Void>() {
091: public Void run() {
092: children.stateChanged(null); // #70914
093: return null; // #70914
094: }
095: });
096: waitForGUIUpdate();
097: assertEquals("three children", 3,
098: children.getNodes(true).length);
099: }
100:
101: public void testNameAndDisplayName() throws Exception {
102: SuiteProject p = generateSuite("Sweet Stuff");
103: Node n = p.getLookup().lookup(LogicalViewProvider.class)
104: .createLogicalView();
105: assertEquals("Sweet Stuff", n.getName());
106: assertEquals("Sweet Stuff", n.getDisplayName());
107: NL nl = new NL();
108: n.addNodeListener(nl);
109: EditableProperties ep = p.getHelper().getProperties(
110: AntProjectHelper.PROJECT_PROPERTIES_PATH);
111: ep.setProperty("app.name", "sweetness");
112: ep.setProperty("app.title", "Sweetness is Now!");
113: p.getHelper().putProperties(
114: AntProjectHelper.PROJECT_PROPERTIES_PATH, ep);
115: assertEquals(new HashSet<String>(Arrays.asList(Node.PROP_NAME,
116: Node.PROP_DISPLAY_NAME)), nl.changed);
117: assertEquals("Sweetness is Now!", n.getName());
118: assertEquals("Sweetness is Now!", n.getDisplayName());
119: }
120:
121: public void testProjectFiles() throws Exception {
122: SuiteProject suite = generateSuite("suite");
123: TestBase.generateSuiteComponent(suite, "module");
124: suite.open();
125: SuiteRootNode rootNode = (SuiteRootNode) suite.getLookup()
126: .lookup(LogicalViewProvider.class).createLogicalView();
127: Set<FileObject> expected = new HashSet<FileObject>(Arrays
128: .asList(suite.getProjectDirectory().getFileObject(
129: "nbproject"), suite.getProjectDirectory()
130: .getFileObject("build.xml")));
131: assertTrue(expected.equals(rootNode.getProjectFiles()));
132: }
133:
134: public void testImportantFiles() throws Exception {
135: // so getDisplayName is taken from english bundle
136: Locale.setDefault(Locale.US);
137:
138: SuiteProject suite = generateSuite("sweet");
139: FileObject master = suite.getProjectDirectory().createData(
140: "master.jnlp");
141:
142: LogicalViewProvider viewProv = suite.getLookup().lookup(
143: LogicalViewProvider.class);
144: Node n = viewProv.createLogicalView();
145:
146: Node[] nodes = n.getChildren().getNodes(true);
147: assertEquals("Now there are two", 2, nodes.length);
148: assertEquals("Named modules", "modules", nodes[0].getName());
149: assertEquals("Named imp files", "important.files", nodes[1]
150: .getName());
151:
152: FileObject projProps = suite.getProjectDirectory()
153: .getFileObject("nbproject/project.properties");
154: assertNotNull(projProps);
155: viewProv.findPath(n, projProps); // ping
156: flushRequestProcessor();
157: Node nodeForFO = viewProv.findPath(n, projProps);
158:
159: assertNotNull("found project.properties node", nodeForFO);
160: assertEquals("Name of node is localized", "Project Properties",
161: nodeForFO.getDisplayName());
162:
163: nodeForFO = viewProv.findPath(n, master);
164: assertNotNull("found master.jnlp node", nodeForFO);
165: assertEquals("same by DataObject", nodeForFO, viewProv
166: .findPath(n, DataObject.find(master)));
167: assertEquals("Name of node is localized", "JNLP Descriptor",
168: nodeForFO.getDisplayName());
169:
170: master.delete();
171:
172: nodeForFO = viewProv.findPath(n, master);
173: assertNull("For file object null", nodeForFO);
174: }
175:
176: private static final class NL extends NodeAdapter {
177: public final Set<String> changed = new HashSet<String>();
178:
179: public @Override
180: void propertyChange(PropertyChangeEvent evt) {
181: changed.add(evt.getPropertyName());
182: }
183: }
184:
185: private void waitForGUIUpdate() throws Exception {
186: EventQueue.invokeAndWait(new Runnable() {
187: public void run() {
188: }
189: });
190: }
191:
192: private void flushRequestProcessor() {
193: RequestProcessor.getDefault().post(new Runnable() {
194: public void run() {
195: // flush
196: }
197: }).waitFinished();
198: }
199:
200: }
|