Added
Link Here
|
1 |
/* |
2 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. |
3 |
* |
4 |
* Copyright 2009 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 2009 Sun Microsystems, Inc. |
38 |
*/ |
39 |
|
40 |
package org.netbeans.modules.server.ui.node; |
41 |
|
42 |
import java.awt.EventQueue; |
43 |
import java.awt.event.ActionEvent; |
44 |
import java.io.IOException; |
45 |
import java.util.Arrays; |
46 |
import javax.swing.AbstractAction; |
47 |
import javax.swing.Action; |
48 |
import org.netbeans.junit.NbTestCase; |
49 |
import org.openide.filesystems.FileObject; |
50 |
import org.openide.filesystems.FileUtil; |
51 |
import org.openide.util.HelpCtx; |
52 |
import org.openide.util.actions.CallableSystemAction; |
53 |
|
54 |
/** |
55 |
* |
56 |
* @author Jaroslav Tulach <jtulach@netbeans.org> |
57 |
*/ |
58 |
public class RootNodeConfigFileTest extends NbTestCase { |
59 |
|
60 |
public RootNodeConfigFileTest(String s) { |
61 |
super(s); |
62 |
} |
63 |
|
64 |
@Override |
65 |
protected void setUp() throws Exception { |
66 |
clearWorkDir(); |
67 |
} |
68 |
|
69 |
|
70 |
public void testInvokeActionsOnConfigFiles() throws Throwable { |
71 |
class Work implements Runnable { |
72 |
int action; |
73 |
Throwable t; |
74 |
CntAction a; |
75 |
CntAction b; |
76 |
|
77 |
|
78 |
public void run() { |
79 |
switch (action) { |
80 |
case 0: setup(); break; |
81 |
case 1: check1(); break; |
82 |
default: fail(); |
83 |
} |
84 |
} |
85 |
|
86 |
private void setup() { |
87 |
try { |
88 |
FileObject fo = FileUtil.getConfigFile("Servers/Actions"); |
89 |
assertNotNull("Folder for actions precreated", fo); |
90 |
a = new CntAction(); |
91 |
FileObject afo = fo.createData("A2.instance"); |
92 |
afo.setAttribute("instanceCreate", a); |
93 |
afo.setAttribute("position", 99); |
94 |
afo.setAttribute("config-Kuk/Buk/Huk.instance", "true"); |
95 |
|
96 |
b = new CntAction(); |
97 |
FileObject bfo = fo.createData("A3.instance"); |
98 |
bfo.setAttribute("instanceCreate", b); |
99 |
bfo.setAttribute("position", 98); |
100 |
} catch (IOException ex) { |
101 |
this.t = ex; |
102 |
} |
103 |
} |
104 |
|
105 |
private void check1() { |
106 |
try { |
107 |
RootNode.enableActionsOnExpand(); |
108 |
assertEquals("No action called", 0, a.cnt); |
109 |
assertEquals("No action called2", 0, b.cnt); |
110 |
|
111 |
FileObject huk = FileUtil.createData(FileUtil.getConfigRoot(), "Kuk/Buk/Huk.instance"); |
112 |
|
113 |
RootNode.enableActionsOnExpand(); |
114 |
assertEquals("CntAction called", 1, a.cnt); |
115 |
assertEquals("No Myaction", 0, b.cnt); |
116 |
} catch (Throwable ex) { |
117 |
this.t = ex; |
118 |
} |
119 |
} |
120 |
} |
121 |
|
122 |
Work w = new Work(); |
123 |
w.action = 0; |
124 |
FileUtil.runAtomicAction(w); |
125 |
w.action = 1; |
126 |
EventQueue.invokeAndWait(w); |
127 |
|
128 |
if (w.t != null) { |
129 |
throw w.t; |
130 |
} |
131 |
} |
132 |
|
133 |
public static final class CntAction extends AbstractAction { |
134 |
int cnt; |
135 |
|
136 |
public void actionPerformed(ActionEvent e) { |
137 |
assertEquals("noui", e.getActionCommand()); |
138 |
cnt++; |
139 |
} |
140 |
} |
141 |
} |