1 19 20 package org.netbeans.modules.apisupport.project.ui.wizard.action; 21 22 import java.io.File ; 23 import java.util.Arrays ; 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 39 public class DataModelTest extends LayerTestBase { 40 41 public DataModelTest(String name) { 42 super(name); 43 } 44 45 protected void setUp() throws Exception { 46 super.setUp(); 47 TestBase.initializeBuildProperties(getWorkDir(), getDataDir()); 48 } 49 50 public void testDataModelGenarationForAlwaysEnabledActions() throws Exception { 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 data.setAlwaysEnabled(true); 58 59 data.setCategory("Actions/Tools"); 61 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 data.setToolbarEnabled(true); 69 data.setToolbar("Toolbars/Edit"); 70 data.setToolbarPosition(new Position("org-openide-actions-FindAction.instance", null)); 71 data.setKeyboardShortcutEnabled(true); 73 data.setKeyStroke("DA-B"); 74 75 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 [] {"src/org/example/module1/BeepAction.java", "src/org/example/module1/Bundle.properties"}), 83 Arrays.asList(cmf.getCreatedPaths())); 84 assertEquals( 85 Arrays.asList(new String [] {"nbproject/project.xml", "src/org/example/module1/resources/layer.xml"}), 86 Arrays.asList(cmf.getModifiedPaths())); 87 88 cmf.run(); 89 90 String [] supposedContent = new String [] { 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 (getWorkDir(), "module1/src/org/example/module1/resources/layer.xml")); 134 } 135 136 public void testDataModelGenarationForConditionallyEnabledActions() throws Exception { 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 data.setAlwaysEnabled(false); 144 data.setCookieClasses(new String [] {DataModel.PREDEFINED_COOKIE_CLASSES[1], DataModel.PREDEFINED_COOKIE_CLASSES[2]}); 145 data.setMultiSelection(false); 146 147 data.setCategory("Actions/Tools"); 149 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 data.setToolbarEnabled(true); 157 data.setToolbar("Toolbars/Edit"); 158 data.setToolbarPosition(new Position("org-openide-actions-FindAction.instance", null)); 159 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 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 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 [] {"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 [] {"nbproject/project.xml", "src/org/example/module1/resources/layer.xml"}), 183 Arrays.asList(cmf.getModifiedPaths())); 184 185 cmf.run(); 186 187 String [] supposedContent = new String [] { 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 (getWorkDir(), "module1/src/org/example/module1/resources/layer.xml")); 258 } 259 260 } 261 262 | Popular Tags |