KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > wizard > action > DataModelTest


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

19
20 package org.netbeans.modules.apisupport.project.ui.wizard.action;
21
22 import java.io.File JavaDoc;
23 import java.util.Arrays JavaDoc;
24 import org.netbeans.modules.apisupport.project.CreatedModifiedFiles;
25 import org.netbeans.modules.apisupport.project.CreatedModifiedFilesTest;
26 import org.netbeans.modules.apisupport.project.NbModuleProject;
27 import org.netbeans.modules.apisupport.project.TestBase;
28 import org.netbeans.modules.apisupport.project.layers.LayerTestBase;
29 import org.netbeans.modules.apisupport.project.ui.wizard.action.DataModel.Position;
30 import org.netbeans.modules.project.uiapi.ProjectChooserFactory;
31 import org.openide.WizardDescriptor;
32 import org.openide.WizardDescriptor.Panel;
33
34 /**
35  * Tests {@link DataModel}.
36  *
37  * @author Martin Krauskopf
38  */

39 public class DataModelTest extends LayerTestBase {
40     
41     public DataModelTest(String JavaDoc name) {
42         super(name);
43     }
44     
45     protected void setUp() throws Exception JavaDoc {
46         super.setUp();
47         TestBase.initializeBuildProperties(getWorkDir(), getDataDir());
48     }
49     
50     public void testDataModelGenarationForAlwaysEnabledActions() throws Exception JavaDoc {
51         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
52         WizardDescriptor wd = new WizardDescriptor(new Panel[] {});
53         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
54         DataModel data = new DataModel(wd);
55         
56         // first panel data (Action Type)
57
data.setAlwaysEnabled(true);
58         
59         // second panel data (GUI Registration)
60
data.setCategory("Actions/Tools");
61         // global menu item
62
data.setGlobalMenuItemEnabled(true);
63         data.setGMIParentMenu("Menu/Help/Tutorials");
64         data.setGMIPosition(new Position("quick-start.url", "prj-import-guide.url"));
65         data.setGMISeparatorBefore(true);
66         data.setGMISeparatorAfter(true);
67         // global toolbar button
68
data.setToolbarEnabled(true);
69         data.setToolbar("Toolbars/Edit");
70         data.setToolbarPosition(new Position("org-openide-actions-FindAction.instance", null));
71         // global keyboard shortcut
72
data.setKeyboardShortcutEnabled(true);
73         data.setKeyStroke("DA-B");
74         
75         // third panel data (Name, Icon, and Location)
76
data.setClassName("BeepAction");
77         data.setDisplayName("Beep");
78         data.setPackageName("org.example.module1");
79         
80         CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
81         assertEquals(
82                 Arrays.asList(new String JavaDoc[] {"src/org/example/module1/BeepAction.java", "src/org/example/module1/Bundle.properties"}),
83                 Arrays.asList(cmf.getCreatedPaths()));
84         assertEquals(
85                 Arrays.asList(new String JavaDoc[] {"nbproject/project.xml", "src/org/example/module1/resources/layer.xml"}),
86                 Arrays.asList(cmf.getModifiedPaths()));
87         
88         cmf.run();
89         
90         String JavaDoc[] supposedContent = new String JavaDoc[] {
91             "<filesystem>",
92                     "<folder name=\"Actions\">",
93                     "<folder name=\"Tools\">",
94                     "<file name=\"org-example-module1-BeepAction.instance\"/>",
95                     "</folder>",
96                     "</folder>",
97                     "<folder name=\"Menu\">",
98                     "<folder name=\"Help\">",
99                     "<folder name=\"Tutorials\">",
100                     "<attr name=\"quick-start.url/org-example-module1-separatorBefore.instance\" boolvalue=\"true\"/>",
101                     "<file name=\"org-example-module1-separatorBefore.instance\">",
102                     "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
103                     "</file>",
104                     "<attr name=\"org-example-module1-separatorBefore.instance/org-example-module1-BeepAction.shadow\" boolvalue=\"true\"/>",
105                     "<file name=\"org-example-module1-BeepAction.shadow\">",
106                     "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
107                     "</file>",
108                     "<attr name=\"org-example-module1-BeepAction.shadow/org-example-module1-separatorAfter.instance\" boolvalue=\"true\"/>",
109                     "<file name=\"org-example-module1-separatorAfter.instance\">",
110                     "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
111                     "</file>",
112                     "<attr name=\"org-example-module1-separatorAfter.instance/prj-import-guide.url\" boolvalue=\"true\"/>",
113                     "</folder>",
114                     "</folder>",
115                     "</folder>",
116                     "<folder name=\"Shortcuts\">",
117                     "<file name=\"DA-B.shadow\">",
118                     "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
119                     "</file>",
120                     "</folder>",
121                     "<folder name=\"Toolbars\">",
122                     "<folder name=\"Edit\">",
123                     "<attr name=\"org-openide-actions-FindAction.instance/org-example-module1-BeepAction.shadow\" boolvalue=\"true\"/>",
124                     "<file name=\"org-example-module1-BeepAction.shadow\">",
125                     "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
126                     "</file>",
127                     "</folder>",
128                     "</folder>",
129                     "</filesystem>"
130         };
131         
132         CreatedModifiedFilesTest.assertLayerContent(supposedContent,
133                 new File JavaDoc(getWorkDir(), "module1/src/org/example/module1/resources/layer.xml"));
134     }
135     
136     public void testDataModelGenarationForConditionallyEnabledActions() throws Exception JavaDoc {
137         NbModuleProject project = TestBase.generateStandaloneModule(getWorkDir(), "module1");
138         WizardDescriptor wd = new WizardDescriptor(new Panel[] {});
139         wd.putProperty(ProjectChooserFactory.WIZARD_KEY_PROJECT, project);
140         DataModel data = new DataModel(wd);
141         
142         // first panel data (Action Type)
143
data.setAlwaysEnabled(false);
144         data.setCookieClasses(new String JavaDoc[] {DataModel.PREDEFINED_COOKIE_CLASSES[1], DataModel.PREDEFINED_COOKIE_CLASSES[2]});
145         data.setMultiSelection(false);
146         
147         // second panel data (GUI Registration)
148
data.setCategory("Actions/Tools");
149         // global menu item
150
data.setGlobalMenuItemEnabled(true);
151         data.setGMIParentMenu("Menu/Help/Tutorials");
152         data.setGMIPosition(new Position("quick-start.url", "prj-import-guide.url"));
153         data.setGMISeparatorBefore(true);
154         data.setGMISeparatorAfter(true);
155         // global toolbar button
156
data.setToolbarEnabled(true);
157         data.setToolbar("Toolbars/Edit");
158         data.setToolbarPosition(new Position("org-openide-actions-FindAction.instance", null));
159         // file type context menu item
160
data.setFileTypeContextEnabled(true);
161         data.setFTContextType("Loaders/text/x-java/Actions");
162         data.setFTContextPosition(new Position(null, "OpenAction.instance"));
163         data.setFTContextSeparatorBefore(false);
164         data.setFTContextSeparatorAfter(true);
165         // editor context menu item
166
data.setEditorContextEnabled(true);
167         data.setEdContextType("Editors/text/x-java/Popup");
168         data.setEdContextPosition(new Position(null, "generate-goto-popup"));
169         data.setEdContextSeparatorBefore(false);
170         data.setEdContextSeparatorAfter(true);
171         
172         // third panel data (Name, Icon, and Location)
173
data.setClassName("BeepAction");
174         data.setDisplayName("Beep");
175         data.setPackageName("org.example.module1");
176         
177         CreatedModifiedFiles cmf = data.getCreatedModifiedFiles();
178         assertEquals("new files",
179                 Arrays.asList(new String JavaDoc[] {"src/org/example/module1/BeepAction.java", "src/org/example/module1/Bundle.properties"}),
180                 Arrays.asList(cmf.getCreatedPaths()));
181         assertEquals("modified files",
182                 Arrays.asList(new String JavaDoc[] {"nbproject/project.xml", "src/org/example/module1/resources/layer.xml"}),
183                 Arrays.asList(cmf.getModifiedPaths()));
184
185         cmf.run();
186         
187         String JavaDoc[] supposedContent = new String JavaDoc[] {
188             "<filesystem>",
189                     "<folder name=\"Actions\">",
190                     "<folder name=\"Tools\">",
191                     "<file name=\"org-example-module1-BeepAction.instance\"/>",
192                     "</folder>",
193                     "</folder>",
194                     "<folder name=\"Editors\">",
195                     "<folder name=\"text\">",
196                     "<folder name=\"x-java\">",
197                     "<folder name=\"Popup\">",
198                     "<file name=\"org-example-module1-BeepAction.shadow\">",
199                     "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
200                     "</file>",
201                     "<attr name=\"org-example-module1-BeepAction.shadow/org-example-module1-separatorAfter.instance\" boolvalue=\"true\"/>",
202                     "<file name=\"org-example-module1-separatorAfter.instance\">",
203                     "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
204                     "</file>",
205                     "<attr name=\"org-example-module1-separatorAfter.instance/generate-goto-popup\" boolvalue=\"true\"/>",
206                     "</folder>",
207                     "</folder>",
208                     "</folder>",
209                     "</folder>",
210                     "<folder name=\"Loaders\">",
211                     "<folder name=\"text\">",
212                     "<folder name=\"x-java\">",
213                     "<folder name=\"Actions\">",
214                     "<file name=\"org-example-module1-BeepAction.shadow\">",
215                     "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
216                     "</file>",
217                     "<attr name=\"org-example-module1-BeepAction.shadow/org-example-module1-separatorAfter.instance\" boolvalue=\"true\"/>",
218                     "<file name=\"org-example-module1-separatorAfter.instance\">",
219                     "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
220                     "</file>",
221                     "<attr name=\"org-example-module1-separatorAfter.instance/OpenAction.instance\" boolvalue=\"true\"/>",
222                     "</folder>",
223                     "</folder>",
224                     "</folder>",
225                     "</folder>",
226                     "<folder name=\"Menu\">",
227                     "<folder name=\"Help\">",
228                     "<folder name=\"Tutorials\">",
229                     "<attr name=\"quick-start.url/org-example-module1-separatorBefore.instance\" boolvalue=\"true\"/>",
230                     "<file name=\"org-example-module1-separatorBefore.instance\">",
231                     "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
232                     "</file>",
233                     "<attr name=\"org-example-module1-separatorBefore.instance/org-example-module1-BeepAction.shadow\" boolvalue=\"true\"/>",
234                     "<file name=\"org-example-module1-BeepAction.shadow\">",
235                     "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
236                     "</file>",
237                     "<attr name=\"org-example-module1-BeepAction.shadow/org-example-module1-separatorAfter.instance\" boolvalue=\"true\"/>",
238                     "<file name=\"org-example-module1-separatorAfter.instance\">",
239                     "<attr name=\"instanceClass\" stringvalue=\"javax.swing.JSeparator\"/>",
240                     "</file>",
241                     "<attr name=\"org-example-module1-separatorAfter.instance/prj-import-guide.url\" boolvalue=\"true\"/>",
242                     "</folder>",
243                     "</folder>",
244                     "</folder>",
245                     "<folder name=\"Toolbars\">",
246                     "<folder name=\"Edit\">",
247                     "<attr name=\"org-openide-actions-FindAction.instance/org-example-module1-BeepAction.shadow\" boolvalue=\"true\"/>",
248                     "<file name=\"org-example-module1-BeepAction.shadow\">",
249                     "<attr name=\"originalFile\" stringvalue=\"Actions/Tools/org-example-module1-BeepAction.instance\"/>",
250                     "</file>",
251                     "</folder>",
252                     "</folder>",
253                     "</filesystem>"
254         };
255         
256         CreatedModifiedFilesTest.assertLayerContent(supposedContent,
257                 new File JavaDoc(getWorkDir(), "module1/src/org/example/module1/resources/layer.xml"));
258     }
259     
260 }
261
262
Popular Tags