1 19 20 package org.netbeans.modules.web.project; 21 22 import java.io.File ; 23 import java.lang.ref.Reference ; 24 import java.lang.ref.WeakReference ; 25 import org.netbeans.api.project.Project; 26 import org.netbeans.api.project.ProjectManager; 27 import org.netbeans.api.project.ui.OpenProjects; 28 import org.netbeans.junit.NbTestCase; 29 import org.netbeans.modules.web.project.WebProject.ProjectOpenedHookImpl; 30 import org.netbeans.modules.web.project.test.TestUtil; 31 import org.netbeans.modules.web.project.ui.WebLogicalViewProvider; 32 import org.netbeans.spi.project.ui.ProjectOpenedHook; 33 import org.openide.filesystems.FileObject; 34 import org.openide.filesystems.FileUtil; 35 import org.openide.nodes.Node; 36 37 40 public class WebProjectTest extends NbTestCase { 41 42 private String serverID; 43 44 public WebProjectTest(String testName) { 45 super(testName); 46 } 47 48 protected void setUp() throws Exception { 49 super.setUp(); 50 TestUtil.makeScratchDir(this); 51 serverID = TestUtil.registerSunAppServer(this); 52 } 53 54 public void testWebProjectIsGCed() throws Exception { File f = new File (getDataDir().getAbsolutePath(), "projects/WebApplication1"); 56 FileObject projdir = FileUtil.toFileObject(f); 57 Project webProject = ProjectManager.getDefault().findProject(projdir); 58 WebProjectTest.openProject((WebProject) webProject); 59 Node rootNode = ((WebLogicalViewProvider) webProject.getLookup().lookup(WebLogicalViewProvider.class)).createLogicalView(); 60 Reference <Project> wr = new WeakReference <Project>(webProject); 64 OpenProjects.getDefault().close(new Project[] { webProject }); 65 WebProjectTest.closeProject((WebProject) webProject); 66 rootNode = null; 67 webProject = null; 68 assertGC("project cannot be garbage collected", wr); 69 } 70 71 75 public static void openProject(final WebProject p) { 76 ProjectOpenedHookImpl hook = (ProjectOpenedHookImpl) p.getLookup().lookup(ProjectOpenedHook.class); 77 assertNotNull("has an OpenedHook", hook); 78 hook.projectOpened(); } 80 81 public static void closeProject(final WebProject p) { 82 ProjectOpenedHookImpl hook = (ProjectOpenedHookImpl) p.getLookup().lookup(ProjectOpenedHook.class); 83 assertNotNull("has an OpenedHook", hook); 84 hook.projectClosed(); } 86 87 } 88 | Popular Tags |