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-2006 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.project.ui;
043:
044: import java.beans.PropertyChangeEvent;
045: import java.beans.PropertyChangeListener;
046: import java.lang.reflect.Field;
047: import java.net.MalformedURLException;
048: import java.net.URL;
049: import java.util.Collections;
050: import java.util.HashMap;
051: import java.util.HashSet;
052: import java.util.List;
053: import java.util.Map;
054: import java.util.Set;
055: import java.util.SortedSet;
056: import java.util.TreeSet;
057: import java.util.logging.Level;
058: import java.util.regex.Matcher;
059: import java.util.regex.Pattern;
060: import org.netbeans.api.project.FileOwnerQuery;
061: import org.netbeans.api.project.Project;
062: import org.netbeans.api.project.ProjectManager;
063: import org.netbeans.junit.Log;
064: import org.netbeans.junit.MockServices;
065: import org.netbeans.junit.NbTestCase;
066: import org.netbeans.modules.project.ui.actions.TestSupport;
067: import org.netbeans.spi.project.SubprojectProvider;
068: import org.netbeans.spi.project.ui.ProjectOpenedHook;
069: import org.openide.filesystems.FileObject;
070: import org.openide.filesystems.FileStateInvalidException;
071: import org.openide.filesystems.FileUtil;
072: import org.openide.filesystems.URLMapper;
073: import org.openide.loaders.DataObject;
074: import org.openide.loaders.DataObjectNotFoundException;
075: import org.openide.util.lookup.Lookups;
076:
077: /** Tests fix of issue 56454.
078: *
079: * @author Jiri Rechtacek
080: */
081: public class OpenProjectListNPUTest extends NbTestCase {
082: FileObject f1_1_open, f1_2_open, f1_3_close;
083: FileObject f2_1_open;
084:
085: Project project1, project2;
086:
087: public OpenProjectListNPUTest(String testName) {
088: super (testName);
089: }
090:
091: protected boolean runInEQ() {
092: return true;
093: }
094:
095: protected void setUp() throws Exception {
096: super .setUp();
097: MockServices.setServices(TestSupport.TestProjectFactory.class);
098: clearWorkDir();
099:
100: FileObject workDir = FileUtil.toFileObject(getWorkDir());
101:
102: FileObject p1 = TestSupport.createTestProject(workDir,
103: "project1");
104: f1_1_open = p1.createData("f1_1.java");
105: f1_2_open = p1.createData("f1_2.java");
106: f1_3_close = p1.createData("f1_3.java");
107:
108: project1 = ProjectManager.getDefault().findProject(p1);
109: OpenProjectList.getDefault().getTemplatesLRU(project1);
110:
111: ((TestSupport.TestProject) project1).setLookup(Lookups
112: .singleton(TestSupport.createAuxiliaryConfiguration()));
113:
114: FileObject p2 = TestSupport.createTestProject(workDir,
115: "project2");
116: f2_1_open = p2.createData("f2_1.java");
117:
118: // project2 depends on projects1
119: project2 = ProjectManager.getDefault().findProject(p2);
120: ((TestSupport.TestProject) project2).setLookup(Lookups
121: .fixed(TestSupport.createAuxiliaryConfiguration()));
122:
123: // prepare set of open documents for both projects
124: ProjectUtilities.OPEN_CLOSE_PROJECT_DOCUMENT_IMPL
125: .open(f1_1_open);
126: ProjectUtilities.OPEN_CLOSE_PROJECT_DOCUMENT_IMPL
127: .open(f1_2_open);
128: ProjectUtilities.OPEN_CLOSE_PROJECT_DOCUMENT_IMPL
129: .open(f2_1_open);
130:
131: // close both projects with own open files
132: OpenProjectList.getDefault().close(
133: new Project[] { project1, project2 }, false);
134: }
135:
136: protected void tearDown() {
137: OpenProjectList.getDefault().close(
138: new Project[] { project1, project2 }, false);
139: }
140:
141: public void testOpen() throws Exception {
142: OpenProjectList.getDefault().getTemplatesLRU(project1);
143:
144: assertTrue("No project is open.", OpenProjectList.getDefault()
145: .getOpenProjects().length == 0);
146: CharSequence log = Log.enable("org.netbeans.ui", Level.FINE);
147: OpenProjectList.getDefault().open(project1, true);
148: assertTrue("Project1 is opened.", OpenProjectList.getDefault()
149: .isOpen(project1));
150: Pattern p = Pattern.compile("Opening.*1.*TestProject",
151: Pattern.MULTILINE | Pattern.DOTALL);
152: Matcher m = p.matcher(log);
153: if (!m.find()) {
154: fail("There should be TestProject\n" + log.toString());
155: }
156: }
157: }
|