1 19 20 package org.netbeans.modules.j2ee.earproject.ui; 21 22 import java.io.File ; 23 import org.netbeans.api.project.Project; 24 import org.netbeans.api.project.ProjectManager; 25 import org.netbeans.junit.NbTestCase; 26 import org.netbeans.modules.j2ee.earproject.test.TestUtil; 27 import org.netbeans.modules.j2ee.earproject.ui.wizards.NewEarProjectWizardIteratorTest; 28 import org.openide.filesystems.FileObject; 29 import org.openide.filesystems.FileUtil; 30 import org.openide.nodes.Node; 31 32 38 public class ModuleNodeTest extends NbTestCase { 39 40 private static final int CHILDREN_UPDATE_TIME_OUT = 20000; 41 42 private String serverInstanceID; 43 44 public ModuleNodeTest(String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 clearWorkDir(); 50 serverInstanceID = TestUtil.registerSunAppServer(this); 51 } 52 53 public void testRemoveFromJarContent() throws Exception { 54 File prjDirF = new File (getWorkDir(), "testEA"); 55 String name = "Test EnterpriseApplication"; 56 String j2eeLevel = "1.4"; 57 String jarName = "testEA-ejb"; 58 59 NewEarProjectWizardIteratorTest.generateEARProject(prjDirF, name, j2eeLevel, 61 serverInstanceID, null, null, jarName, null, null, null); 62 63 Project earProject = ProjectManager.getDefault().findProject(FileUtil.toFileObject(prjDirF)); 64 65 LogicalViewProvider lvp = (LogicalViewProvider) earProject.getLookup().lookup(LogicalViewProvider.class); 66 assertNotNull("have a LogicalViewProvider", lvp); 67 Node root = lvp.createLogicalView(); 68 LogicalViewNode j2eeModules = (LogicalViewNode) root.getChildren().findChild(LogicalViewNode.J2EE_MODULES_NAME); 69 assertSame("have ejb module's node", 1, j2eeModules.getChildren().getNodes(true).length); 70 71 ModuleNode moduleNode = (ModuleNode) j2eeModules.getChildren().findChild(ModuleNode.MODULE_NODE_NAME); 72 assertNotNull("have modules node", moduleNode); 73 moduleNode.removeFromJarContent(); 74 assertNumberOfNodes("ejb module removed", j2eeModules, 0); 75 } 76 77 public void testRemoveFromJarContentWithDeletedProject() throws Exception { 79 File prjDirF = new File (getWorkDir(), "testEA"); 80 String name = "Test EnterpriseApplication"; 81 String j2eeLevel = "1.4"; 82 String jarName = "testEA-ejb"; 83 84 NewEarProjectWizardIteratorTest.generateEARProject(prjDirF, name, j2eeLevel, 86 serverInstanceID, null, null, jarName, null, null, null); 87 88 FileObject prjDirFO = FileUtil.toFileObject(prjDirF); 89 Project earProject = ProjectManager.getDefault().findProject(prjDirFO); 90 91 LogicalViewProvider lvp = (LogicalViewProvider) earProject.getLookup().lookup(LogicalViewProvider.class); 92 assertNotNull("have a LogicalViewProvider", lvp); 93 Node root = lvp.createLogicalView(); 94 LogicalViewNode j2eeModules = (LogicalViewNode) root.getChildren().findChild(LogicalViewNode.J2EE_MODULES_NAME); 95 assertSame("have ejb module's node", 1, j2eeModules.getChildren().getNodes(true).length); 96 97 ModuleNode moduleNode = (ModuleNode) j2eeModules.getChildren().findChild(ModuleNode.MODULE_NODE_NAME); 98 assertNotNull("have modules node", moduleNode); 99 100 FileObject ejbJarFO = prjDirFO.getFileObject("testEA-ejb"); 102 ejbJarFO.delete(); 103 moduleNode.removeFromJarContent(); 104 j2eeModules.getChildren().getNodes(true); 105 106 assertNumberOfNodes("ejb module removed", j2eeModules, 0); 107 } 108 109 private void assertNumberOfNodes(final String message, final LogicalViewNode j2eeModules, 110 int expectedNumber) throws InterruptedException { 111 int waitTime = 0; 112 boolean failed = false; 113 while (!failed && j2eeModules.getChildren().getNodes(true).length != 0) { 114 failed = ++waitTime > CHILDREN_UPDATE_TIME_OUT/50; 115 Thread.sleep(50); 116 } 117 assertFalse(message, failed); 118 } 119 120 } 121 | Popular Tags |