1 19 20 package org.netbeans.modules.apisupport.project.ui; 21 22 import java.util.Set ; 23 import javax.swing.Action ; 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 41 public class UnitTestLibrariesNodeTest extends TestBase { 42 private static final String UNIT = TestModuleDependency.UNIT; 43 private static final String DEP_CNB = "org.openide.filesystems"; 44 private static final String JUNIT_CNB = "org.netbeans.modules.junit"; 45 private static final String NBJUNIT_CNB = "org.netbeans.modules.nbjunit"; 46 private static int nc = 0; 48 public UnitTestLibrariesNodeTest(String testName) { 49 super(testName); 50 } 51 52 public void testLibrariesNodeDrawingDeps() throws Exception { 54 Lookup.getDefault().lookup(ModuleInfo.class); 55 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 ProjectXMLManager pxm = new ProjectXMLManager(p); 74 addTestDependency(p); 75 ModuleList ml = p.getModuleList(); 76 Set 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 pxm.removeTestDependency(UNIT, DEP_CNB); 83 ProjectManager.getDefault().saveProject(p); 84 assertEquals("nc nodes now", nc, libs.getChildren().getNodes().length); 85 } 86 87 public void testActions() throws Exception { 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 addTestDependency(p); 98 String depName = p.getModuleList().getEntry(DEP_CNB).getLocalizedName(); 99 Node depNode = libs.getChildren().findChild(depName); 100 assertNotNull("have a node with dependency", depNode); 101 Action [] 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 111 private void addTestDependency(NbModuleProject project) throws Exception { 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 |