001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.web.project;
043:
044: import java.io.File;
045: import java.lang.ref.Reference;
046: import java.lang.ref.WeakReference;
047: import org.netbeans.api.project.Project;
048: import org.netbeans.api.project.ProjectManager;
049: import org.netbeans.api.project.ui.OpenProjects;
050: import org.netbeans.junit.NbTestCase;
051: import org.netbeans.modules.project.uiapi.ProjectOpenedTrampoline;
052: import org.netbeans.modules.web.project.api.WebPropertyEvaluator;
053: import org.netbeans.modules.web.project.test.TestUtil;
054: import org.netbeans.modules.web.project.ui.WebLogicalViewProvider;
055: import org.netbeans.spi.project.ui.ProjectOpenedHook;
056: import org.openide.filesystems.FileObject;
057: import org.openide.filesystems.FileUtil;
058: import org.openide.nodes.Node;
059:
060: /**
061: * @author Martin Krauskopf, Radko Najman
062: */
063: public class WebProjectTest extends NbTestCase {
064:
065: private String serverID;
066:
067: public WebProjectTest(String testName) {
068: super (testName);
069: }
070:
071: protected void setUp() throws Exception {
072: super .setUp();
073: TestUtil.makeScratchDir(this );
074: serverID = TestUtil.registerSunAppServer(this );
075: }
076:
077: public void testWebProjectIsGCed() throws Exception { // #83128
078:
079: // #99077 - see umbrella issue #70052 for web project memory leaks
080: // for now commenting out this test:
081: if (true)
082: return;
083:
084: File f = new File(getDataDir().getAbsolutePath(),
085: "projects/WebApplication1");
086: FileObject projdir = FileUtil.toFileObject(f);
087: Project webProject = ProjectManager.getDefault().findProject(
088: projdir);
089: WebProjectTest.openProject((WebProject) webProject);
090: Node rootNode = ((WebLogicalViewProvider) webProject
091: .getLookup().lookup(WebLogicalViewProvider.class))
092: .createLogicalView();
093: //.getNodes(true) causes IllegalArgumentException: Called DataObject.find on null
094: //commenting out till it is fixed
095: // rootNode.getChildren().getNodes(true); // ping
096: Reference<Project> wr = new WeakReference<Project>(webProject);
097: OpenProjects.getDefault().close(new Project[] { webProject });
098: WebProjectTest.closeProject((WebProject) webProject);
099: rootNode = null;
100: webProject = null;
101: assertGC("project cannot be garbage collected", wr);
102: }
103:
104: public void testWebPropertiesEvaluator() throws Exception {
105: File f = new File(getDataDir().getAbsolutePath(),
106: "projects/WebApplication1");
107: FileObject projdir = FileUtil.toFileObject(f);
108: Project webProject = ProjectManager.getDefault().findProject(
109: projdir);
110: WebPropertyEvaluator evaluator = webProject.getLookup().lookup(
111: WebPropertyEvaluator.class);
112: assertNotNull("Property evaluatero is null", evaluator);
113: String property = evaluator.evaluator().getProperty(
114: "war.ear.name");
115: assertEquals("war.ear.name property ", "WebApplication1.war",
116: property);
117: }
118:
119: /**
120: * Accessor method for those who wish to simulate open of a project and in
121: * case of suite for example generate the build.xml.
122: */
123: public static void openProject(final WebProject p) throws Exception {
124: ProjectOpenedHook hook = p.getLookup().lookup(
125: ProjectOpenedHook.class);
126: assertNotNull("has an OpenedHook", hook);
127: ProjectOpenedTrampoline.DEFAULT.projectOpened(hook);
128: }
129:
130: public static void closeProject(final WebProject p)
131: throws Exception {
132: ProjectOpenedHook hook = p.getLookup().lookup(
133: ProjectOpenedHook.class);
134: assertNotNull("has an OpenedHook", hook);
135: ProjectOpenedTrampoline.DEFAULT.projectClosed(hook);
136: }
137:
138: }
|