KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > LibrariesNodeTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.apisupport.project.ui;
21
22 import org.netbeans.api.project.ProjectManager;
23 import org.netbeans.modules.apisupport.project.NbModuleProject;
24 import org.netbeans.modules.apisupport.project.TestBase;
25 import org.netbeans.modules.apisupport.project.Util;
26 import org.netbeans.spi.project.ui.LogicalViewProvider;
27 import org.openide.nodes.Node;
28
29 /**
30  * @author Martin Krauskopf
31  */

32 public class LibrariesNodeTest extends TestBase {
33     
34     public LibrariesNodeTest(String JavaDoc testName) {
35         super(testName);
36     }
37     
38     public void testLibrariesNodeListening() throws Exception JavaDoc {
39         NbModuleProject p = generateStandaloneModule("module");
40         LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class);
41         assertNotNull("have a LogicalViewProvider", lvp);
42         Node root = lvp.createLogicalView();
43         Node libraries = root.getChildren().findChild(LibrariesNode.LIBRARIES_NAME);
44         assertNotNull("have the Libraries node", libraries);
45         libraries.getChildren().getNodes(); // ping
46

47         waitForChildrenUpdate();
48         assertEquals("just jdk node is present", 1, libraries.getChildren().getNodes(true).length);
49         
50         Util.addDependency(p, "org.netbeans.modules.java.project");
51         ProjectManager.getDefault().saveProject(p);
52         
53         waitForChildrenUpdate();
54         assertEquals("dependency noticed", 2, libraries.getChildren().getNodes(true).length);
55     }
56     
57     public void testDependencyNodeActions() throws Exception JavaDoc {
58         NbModuleProject p = generateStandaloneModule("module");
59         LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class);
60         Node root = lvp.createLogicalView();
61         Node libraries = root.getChildren().findChild(LibrariesNode.LIBRARIES_NAME);
62         
63         Util.addDependency(p, "org.netbeans.modules.java.project");
64         ProjectManager.getDefault().saveProject(p);
65         libraries.getChildren().getNodes(); // ping
66
waitForChildrenUpdate();
67         Node[] nodes = libraries.getChildren().getNodes(true);
68         assertEquals("dependency noticed", 2, nodes.length);
69         assertEquals("dependency noticed", 4, nodes[1].getActions(false).length);
70     }
71     
72     private void waitForChildrenUpdate() {
73         LibrariesNode.RP.post(new Runnable JavaDoc() {
74             public void run() {
75                 // flush LibrariesNode.RP under which is the Children's update run
76
}
77         }).waitFinished();
78     }
79     
80     // XXX Much more needed
81

82 }
83
Popular Tags