Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved. |
5 |
* |
6 |
* The contents of this file are subject to the terms of either the GNU |
7 |
* General Public License Version 2 only ("GPL") or the Common |
8 |
* Development and Distribution License("CDDL") (collectively, the |
9 |
* "License"). You may not use this file except in compliance with the |
10 |
* License. You can obtain a copy of the License at |
11 |
* http://www.netbeans.org/cddl-gplv2.html |
12 |
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the |
13 |
* specific language governing permissions and limitations under the |
14 |
* License. When distributing the software, include this License Header |
15 |
* Notice in each file and include the License file at |
16 |
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this |
17 |
* particular file as subject to the "Classpath" exception as provided |
18 |
* by Sun in the GPL Version 2 section of the License file that |
19 |
* accompanied this code. If applicable, add the following below the |
20 |
* License Header, with the fields enclosed by brackets [] replaced by |
21 |
* your own identifying information: |
22 |
* "Portions Copyrighted [year] [name of copyright owner]" |
23 |
* |
24 |
* If you wish your version of this file to be governed by only the CDDL |
25 |
* or only the GPL Version 2, indicate your decision by adding |
26 |
* "[Contributor] elects to include this software in this distribution |
27 |
* under the [CDDL or GPL Version 2] license." If you do not indicate a |
28 |
* single choice of license, a recipient has the option to distribute |
29 |
* your version of this file under either the CDDL, the GPL Version 2 or |
30 |
* to extend the choice of license to its licensees as provided above. |
31 |
* However, if you add GPL Version 2 code and therefore, elected the GPL |
32 |
* Version 2 license, then the option applies only if the new code is |
33 |
* made subject to such option by the copyright holder. |
34 |
* |
35 |
* Contributor(s): |
36 |
* |
37 |
* Portions Copyrighted 2007 Sun Microsystems, Inc. |
38 |
*/ |
39 |
|
40 |
package org.netbeans.modules.project.ui; |
41 |
|
42 |
import org.netbeans.api.project.Project; |
43 |
import org.netbeans.api.project.ProjectManager; |
44 |
import org.netbeans.junit.MockServices; |
45 |
import org.netbeans.junit.NbTestCase; |
46 |
import org.netbeans.modules.project.ui.actions.TestSupport; |
47 |
import org.netbeans.modules.project.ui.actions.TestSupport.TestProject; |
48 |
import org.netbeans.spi.project.ui.ProjectOpenedHook; |
49 |
import org.openide.filesystems.FileObject; |
50 |
import org.openide.filesystems.FileUtil; |
51 |
import org.openide.util.Lookup; |
52 |
import org.openide.util.lookup.Lookups; |
53 |
|
54 |
/** |
55 |
* |
56 |
* @author Jaroslav Tulach |
57 |
*/ |
58 |
public class OpenProjectHookAddedWhileOpenTest extends NbTestCase { |
59 |
private TestProjectOpenedHookImpl hook2; |
60 |
private TestProjectOpenedHookImpl hook1; |
61 |
private TestProject project; |
62 |
public OpenProjectHookAddedWhileOpenTest(String testName) { |
63 |
super(testName); |
64 |
} |
65 |
|
66 |
@Override |
67 |
protected void setUp() throws Exception { |
68 |
clearWorkDir(); |
69 |
|
70 |
MockServices.setServices(TestSupport.TestProjectFactory.class); |
71 |
|
72 |
FileObject workDir = FileUtil.toFileObject(getWorkDir()); |
73 |
assertNotNull(workDir); |
74 |
|
75 |
FileObject prj = TestSupport.createTestProject(workDir, "prj0"); |
76 |
project = (TestProject)ProjectManager.getDefault ().findProject (prj); |
77 |
assertNotNull("Project found", project); |
78 |
|
79 |
hook1 = new TestProjectOpenedHookImpl(project); |
80 |
hook2 = new TestProjectOpenedHookImpl(project); |
81 |
|
82 |
Lookup initialLookup = Lookups.singleton(hook1); |
83 |
hook1.newLookup = Lookups.fixed(hook1, hook2); |
84 |
|
85 |
project.setLookup(initialLookup); |
86 |
} |
87 |
|
88 |
public void testBehaviourOfProjectsLogicNode() throws Exception { |
89 |
OpenProjectList.getDefault().open(project); |
90 |
|
91 |
assertEquals("First hook opened once", 1, hook1.cnt); |
92 |
assertEquals("Second hook opened once", 1, hook2.cnt); |
93 |
|
94 |
OpenProjectList.getDefault().close(new Project[] { project }, true); |
95 |
|
96 |
assertEquals("First hook closed once", 1, hook1.close); |
97 |
assertEquals("Second hook closed once", 1, hook2.close); |
98 |
} |
99 |
|
100 |
private static class TestProjectOpenedHookImpl extends ProjectOpenedHook { |
101 |
private final TestProject project; |
102 |
Lookup newLookup; |
103 |
int cnt; |
104 |
int close; |
105 |
|
106 |
public TestProjectOpenedHookImpl(TestProject p) { |
107 |
this.project = p; |
108 |
} |
109 |
|
110 |
protected void projectClosed() { |
111 |
close++; |
112 |
} |
113 |
|
114 |
protected void projectOpened() { |
115 |
cnt++; |
116 |
if (newLookup != null) { |
117 |
project.setLookup(newLookup); |
118 |
} |
119 |
} |
120 |
|
121 |
} |
122 |
} |