KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.Set JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import org.netbeans.api.project.ProjectManager;
25 import org.netbeans.modules.apisupport.project.NbModuleProject;
26 import org.netbeans.modules.apisupport.project.ProjectXMLManager;
27 import org.netbeans.modules.apisupport.project.TestBase;
28 import org.netbeans.modules.apisupport.project.ui.UnitTestLibrariesNode.RemoveDependencyAction;
29 import org.netbeans.modules.apisupport.project.universe.ModuleEntry;
30 import org.netbeans.modules.apisupport.project.universe.ModuleList;
31 import org.netbeans.modules.apisupport.project.universe.TestModuleDependency;
32 import org.netbeans.spi.project.ui.LogicalViewProvider;
33 import org.openide.modules.ModuleInfo;
34 import org.openide.nodes.AbstractNode;
35 import org.openide.nodes.Node;
36 import org.openide.util.Lookup;
37
38 /**
39  * @author Tomas Musil
40  */

41 public class UnitTestLibrariesNodeTest extends TestBase {
42     private static final String JavaDoc UNIT = TestModuleDependency.UNIT;
43     private static final String JavaDoc DEP_CNB = "org.openide.filesystems";
44     private static final String JavaDoc JUNIT_CNB = "org.netbeans.modules.junit";
45     private static final String JavaDoc NBJUNIT_CNB = "org.netbeans.modules.nbjunit";
46     private static int nc = 0; //says if junit or nbjunit is present
47

48     public UnitTestLibrariesNodeTest(String JavaDoc testName) {
49         super(testName);
50     }
51     
52     //this tests if node draws subnodes
53
public void testLibrariesNodeDrawingDeps() throws Exception JavaDoc {
54         Lookup.getDefault().lookup(ModuleInfo.class);
55         //initial check
56
NbModuleProject p = generateStandaloneModule("module");
57         if((p.getModuleList().getEntry(JUNIT_CNB)) != null) {
58             nc++;
59         }
60         if((p.getModuleList().getEntry(NBJUNIT_CNB)) != null) {
61             nc++;
62         }
63
64         LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class);
65         assertNotNull("have a LogicalViewProvider", lvp);
66         Node root = lvp.createLogicalView();
67         Node libs = root.getChildren().findChild(UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME);
68         assertNotNull("have the Libraries node", libs);
69         libs.getChildren().getNodes();
70         assertEquals("nc node", nc, libs.getChildren().getNodes(true).length);
71         
72         //add tests dependecy
73
ProjectXMLManager pxm = new ProjectXMLManager(p);
74         addTestDependency(p);
75         ModuleList ml = p.getModuleList();
76         Set JavaDoc unitDeps = pxm.getTestDependencies(ml).get(TestModuleDependency.UNIT);
77         assertNotNull("Have unit deps now", unitDeps);
78         assertEquals("one dep now", 1, unitDeps.size());
79         assertEquals("nc+1 nodes now", nc+1, libs.getChildren().getNodes().length);
80         
81         //remove test dependency
82
pxm.removeTestDependency(UNIT, DEP_CNB);
83         ProjectManager.getDefault().saveProject(p);
84         assertEquals("nc nodes now", nc, libs.getChildren().getNodes().length);
85     }
86     
87     //test action on node
88
public void testActions() throws Exception JavaDoc{
89         Lookup.getDefault().lookup(ModuleInfo.class);
90         NbModuleProject p = generateStandaloneModule("module");
91         LogicalViewProvider lvp = (LogicalViewProvider) p.getLookup().lookup(LogicalViewProvider.class);
92         assertNotNull("have a LogicalViewProvider", lvp);
93         Node root = lvp.createLogicalView();
94         Node libs = root.getChildren().findChild(UnitTestLibrariesNode.UNIT_TEST_LIBRARIES_NAME);
95         assertNotNull("have the Libraries node", libs);
96         //test removedep action
97
addTestDependency(p);
98         String JavaDoc depName = p.getModuleList().getEntry(DEP_CNB).getLocalizedName();
99         Node depNode = libs.getChildren().findChild(depName);
100         assertNotNull("have a node with dependency", depNode);
101         Action JavaDoc[] act = depNode.getActions(false);
102         assertEquals("have three actions", 3, act.length);
103         RemoveDependencyAction removeAct = (RemoveDependencyAction) act[2];
104         assertEquals("nc+1 nodes now", nc+1, libs.getChildren().getNodes().length);
105         removeAct.performAction(new Node[] {depNode});
106         assertEquals("nc nodes now, dep removed", nc, libs.getChildren().getNodes().length);
107     }
108     
109     //TODO add more tests, try to invoke all actions on nodes, etc
110

111     private void addTestDependency(NbModuleProject project) throws Exception JavaDoc{
112         ProjectXMLManager pxm = new ProjectXMLManager(project);
113         ModuleList ml = project.getModuleList();
114         ModuleEntry me = ml.getEntry(DEP_CNB);
115         assertNotNull("me exist", me);
116         TestModuleDependency tmd = new TestModuleDependency(me, true, true, true);
117         pxm.addTestDependency(UNIT, tmd);
118         ProjectManager.getDefault().saveProject(project);
119     }
120     
121     
122 }
123
Popular Tags