KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > project > WebProjectTest


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.web.project;
21
22 import java.io.File JavaDoc;
23 import java.lang.ref.Reference JavaDoc;
24 import java.lang.ref.WeakReference JavaDoc;
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 /**
38  * @author Martin Krauskopf, Radko Najman
39  */

40 public class WebProjectTest extends NbTestCase {
41     
42     private String JavaDoc serverID;
43     
44     public WebProjectTest(String JavaDoc testName) {
45         super(testName);
46     }
47     
48     protected void setUp() throws Exception JavaDoc {
49         super.setUp();
50         TestUtil.makeScratchDir(this);
51         serverID = TestUtil.registerSunAppServer(this);
52     }
53     
54     public void testWebProjectIsGCed() throws Exception JavaDoc { // #83128
55
File JavaDoc f = new File JavaDoc(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 //.getNodes(true) causes IllegalArgumentException: Called DataObject.find on null
61
//commenting out till it is fixed
62
// rootNode.getChildren().getNodes(true); // ping
63
Reference JavaDoc<Project> wr = new WeakReference JavaDoc<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     /**
72      * Accessor method for those who wish to simulate open of a project and in
73      * case of suite for example generate the build.xml.
74      */

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(); // protected but can use package-private access
79
}
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(); // protected but can use package-private access
85
}
86     
87 }
88
Popular Tags