|
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // NewSMTProjectWizardTest |
|
15 // |
|
16 |
|
17 |
|
18 |
|
19 package com.symbian.smt.gui.wizard; |
|
20 |
|
21 import static com.symbian.smt.gui.ResourcesEnums.BORDER_SHAPES; |
|
22 import static com.symbian.smt.gui.ResourcesEnums.BORDER_STYLES; |
|
23 import static com.symbian.smt.gui.ResourcesEnums.COLOURS; |
|
24 import static com.symbian.smt.gui.ResourcesEnums.DEPENDENCIES; |
|
25 import static com.symbian.smt.gui.ResourcesEnums.LEVELS; |
|
26 import static com.symbian.smt.gui.ResourcesEnums.LOCALISATION; |
|
27 import static com.symbian.smt.gui.ResourcesEnums.PATTERNS; |
|
28 import static com.symbian.smt.gui.ResourcesEnums.S12_XML; |
|
29 import static com.symbian.smt.gui.ResourcesEnums.SHAPES; |
|
30 import static com.symbian.smt.gui.ResourcesEnums.SYSTEM_INFO; |
|
31 |
|
32 import java.util.List; |
|
33 |
|
34 import junit.framework.AssertionFailedError; |
|
35 import junit.framework.TestCase; |
|
36 |
|
37 import org.eclipse.core.resources.IFolder; |
|
38 import org.eclipse.core.resources.IProject; |
|
39 import org.eclipse.core.resources.IProjectDescription; |
|
40 import org.eclipse.core.resources.IResource; |
|
41 import org.eclipse.core.resources.IWorkspace; |
|
42 import org.eclipse.core.resources.ProjectScope; |
|
43 import org.eclipse.core.resources.ResourcesPlugin; |
|
44 import org.eclipse.core.runtime.CoreException; |
|
45 import org.eclipse.core.runtime.Path; |
|
46 import org.eclipse.core.runtime.preferences.DefaultScope; |
|
47 import org.eclipse.core.runtime.preferences.IEclipsePreferences; |
|
48 import org.eclipse.core.runtime.preferences.IScopeContext; |
|
49 import org.eclipse.core.runtime.preferences.InstanceScope; |
|
50 import org.eclipse.jface.viewers.IStructuredSelection; |
|
51 import org.eclipse.jface.viewers.StructuredSelection; |
|
52 import org.eclipse.jface.wizard.IWizardPage; |
|
53 import org.eclipse.jface.wizard.WizardDialog; |
|
54 import org.eclipse.swt.widgets.Composite; |
|
55 import org.eclipse.swt.widgets.Control; |
|
56 import org.eclipse.swt.widgets.Shell; |
|
57 import org.eclipse.swt.widgets.Text; |
|
58 import org.eclipse.ui.IWorkbench; |
|
59 import org.eclipse.ui.PlatformUI; |
|
60 |
|
61 import com.symbian.smt.gui.AbstractPersistentDataStore; |
|
62 import com.symbian.smt.gui.Activator; |
|
63 import com.symbian.smt.gui.Helper; |
|
64 import com.symbian.smt.gui.PersistentDataStore; |
|
65 import com.symbian.smt.gui.TestConstants; |
|
66 import com.symbian.smt.gui.preferences.SmmPreferencesInitializer; |
|
67 |
|
68 /** |
|
69 * @author barbararosi-schwartz |
|
70 * |
|
71 */ |
|
72 public class NewSMTProjectWizardTest extends TestCase { |
|
73 |
|
74 private static final String SEPARATOR = "|"; |
|
75 |
|
76 private static final AbstractPersistentDataStore getPersistDataStore( |
|
77 IProject project) { |
|
78 IScopeContext projectScope = new ProjectScope(project); |
|
79 IEclipsePreferences node = projectScope.getNode(Activator.PLUGIN_ID); |
|
80 PersistentDataStore dataStore = new PersistentDataStore(node); |
|
81 |
|
82 return dataStore; |
|
83 } |
|
84 |
|
85 private IStructuredSelection selection; |
|
86 private Shell shell; |
|
87 private String smgFolder; |
|
88 private NewSMTProjectWizard wizard; |
|
89 private Text wizardProjectTextField; |
|
90 private IWorkbench workbench; |
|
91 |
|
92 // This method is dependent on the current UI composition |
|
93 // of Eclipse's WizardNewProjectCreationPage. |
|
94 // We cannot find the Text widget in any other way because |
|
95 // it is hidden. |
|
96 private final Text findText(Composite parent) { |
|
97 Text text = null; |
|
98 Control[] children = parent.getChildren(); |
|
99 |
|
100 for (Control control : children) { |
|
101 if (control instanceof Text) { |
|
102 text = (Text) control; |
|
103 break; |
|
104 } else if (control instanceof Composite) { |
|
105 return findText((Composite) control); |
|
106 } |
|
107 } |
|
108 |
|
109 return text; |
|
110 } |
|
111 |
|
112 private final String prependPathAndMakeLowerCase(String filename) { |
|
113 assertNotNull("Location of SystemModelManager should not be null.", |
|
114 smgFolder); |
|
115 return new StringBuffer(smgFolder).append(TestConstants.RESOURCE_FILES_FOLDER_PATH) |
|
116 .append(filename).toString().toLowerCase(); |
|
117 } |
|
118 |
|
119 /** |
|
120 * @throws java.lang.Exception |
|
121 */ |
|
122 protected final void setUp() throws Exception { |
|
123 // Initialise the default values |
|
124 SmmPreferencesInitializer initialiser = new SmmPreferencesInitializer(); |
|
125 |
|
126 initialiser.initializeDefaultPreferences(); |
|
127 |
|
128 smgFolder = initialiser.getSmgFolder(); |
|
129 wizard = new NewSMTProjectWizard(); |
|
130 selection = new StructuredSelection(StructuredSelection.EMPTY); |
|
131 workbench = PlatformUI.getWorkbench(); |
|
132 shell = workbench.getActiveWorkbenchWindow().getShell(); |
|
133 |
|
134 wizard.init(workbench, selection); |
|
135 |
|
136 WizardDialog dialog = new WizardDialog(shell, wizard); |
|
137 |
|
138 dialog.setBlockOnOpen(false); |
|
139 dialog.open(); |
|
140 |
|
141 NewProjectCreationPageCaseInsensitive page = (NewProjectCreationPageCaseInsensitive) wizard |
|
142 .getPage("page1"); |
|
143 Composite c = (Composite) page.getControl(); |
|
144 wizardProjectTextField = findText(c); |
|
145 |
|
146 if (wizardProjectTextField == null) { |
|
147 throw new Exception("Could not find project name Text field"); |
|
148 } |
|
149 |
|
150 wizardProjectTextField.setText("testproject"); |
|
151 } |
|
152 |
|
153 /** |
|
154 * @throws java.lang.Exception |
|
155 */ |
|
156 protected final void tearDown() throws Exception { |
|
157 IWorkspace ws = ResourcesPlugin.getWorkspace(); |
|
158 |
|
159 ws.getRoot().delete(true, true, null); |
|
160 wizard.dispose(); |
|
161 |
|
162 wizard = null; |
|
163 } |
|
164 |
|
165 /** |
|
166 * Test method for |
|
167 * {@link com.symbian.smt.gui.wizard.NewSMTProjectWizard#addPages()}. |
|
168 */ |
|
169 public final void testAddPages() { |
|
170 assertEquals(3, wizard.getPageCount()); |
|
171 IWizardPage[] pages = wizard.getPages(); |
|
172 |
|
173 assertTrue(pages[0] instanceof NewProjectCreationPageCaseInsensitive); |
|
174 assertTrue(pages[1] instanceof NewProjectWizardSystemDefsPage); |
|
175 assertTrue(pages[2] instanceof NewProjectWizardTabbedPropertiesPage); |
|
176 } |
|
177 |
|
178 /** |
|
179 * Test method for |
|
180 * {@link com.symbian.smt.gui.wizard.NewSMTProjectWizard#copyFilesIntoProject()} |
|
181 * . |
|
182 */ |
|
183 public final void testCopyFilesIntoProject() { |
|
184 IWizardPage[] pages = wizard.getPages(); |
|
185 NewProjectCreationPageCaseInsensitive page1 = (NewProjectCreationPageCaseInsensitive) pages[0]; |
|
186 IProject newProject = page1.getProjectHandle(); |
|
187 |
|
188 assertEquals("\\testproject", newProject.getFullPath().toOSString()); |
|
189 testDefaultResourcesFromPage((NewProjectWizardTabbedPropertiesPage) pages[2]); |
|
190 } |
|
191 |
|
192 /** |
|
193 * Test method for |
|
194 * {@link com.symbian.smt.gui.wizard.NewSMTProjectWizard#createPageControls()} |
|
195 * . |
|
196 */ |
|
197 public final void testCreatePageControls() { |
|
198 IScopeContext defaultScope = new DefaultScope(); |
|
199 IEclipsePreferences defaultNode = defaultScope |
|
200 .getNode(Activator.PLUGIN_ID); |
|
201 IScopeContext instanceScope = new InstanceScope(); |
|
202 IEclipsePreferences instanceNode = instanceScope |
|
203 .getNode(Activator.PLUGIN_ID); |
|
204 PersistentDataStore instanceStore = new PersistentDataStore( |
|
205 instanceNode, defaultNode); |
|
206 |
|
207 assertNotNull(instanceStore); |
|
208 } |
|
209 |
|
210 /** |
|
211 * Test method for |
|
212 * {@link com.symbian.smt.gui.wizard.NewSMTProjectWizard#createProject()}. |
|
213 */ |
|
214 public final void testCreateProject() { |
|
215 NewProjectCreationPageCaseInsensitive page1 = (NewProjectCreationPageCaseInsensitive) wizard |
|
216 .getPage("page1"); |
|
217 IProject newProject = page1.getProjectHandle(); |
|
218 |
|
219 NewProjectWizardSystemDefsPage page2 = (NewProjectWizardSystemDefsPage) wizard.getPage("wizardPage"); |
|
220 |
|
221 page2.setSystemDefinitions(new String[] {smgFolder + "/../smg-sysdef/Bob_System_Definition.xml"}); |
|
222 wizard.performFinish(); |
|
223 |
|
224 try { |
|
225 IProjectDescription desc = newProject.getDescription(); |
|
226 |
|
227 assertEquals("testproject", desc.getName()); |
|
228 |
|
229 List<String> natureIds = Helper |
|
230 .toListOfStrings(desc.getNatureIds()); |
|
231 |
|
232 assertTrue(natureIds.contains("com.symbian.smt.gui.nature")); |
|
233 } catch (CoreException e) { |
|
234 throw new AssertionFailedError( |
|
235 "Problem encountered in obtaining the project's description."); |
|
236 } |
|
237 } |
|
238 |
|
239 private final void testDefaultResourcesFromPage( |
|
240 NewProjectWizardTabbedPropertiesPage page) { |
|
241 String[] expected = { TestConstants.SHAPES_RESOURCE_FILE_PATH }; |
|
242 String[] actual = page.getDefaultShapesFiles(); |
|
243 String message = "Error in default shapes files."; |
|
244 testResourceName(message, expected, actual); |
|
245 |
|
246 expected = new String[] { "Auto" }; |
|
247 actual = page.getDefaultLevelsFiles(); |
|
248 message = "Error in default level files."; |
|
249 testResourceName(message, expected, actual); |
|
250 |
|
251 expected = new String[] { TestConstants.LOCALISATION_RESOURCE_FILE_PATH }; |
|
252 actual = page.getDefaultLocalisationFiles(); |
|
253 message = "Error in default localisation files."; |
|
254 testResourceName(message, expected, actual); |
|
255 |
|
256 expected = new String[] {}; |
|
257 actual = page.getDefaultDependenciesFiles(); |
|
258 message = "Error in default dependencies files."; |
|
259 testResourceName(message, expected, actual); |
|
260 |
|
261 expected = new String[] {}; |
|
262 actual = page.getDefaultSystemInfoFiles(); |
|
263 message = "Error in default system info files."; |
|
264 testResourceName(message, expected, actual); |
|
265 |
|
266 expected = new String[] {}; |
|
267 actual = page.getDefaultColoursFiles(); |
|
268 message = "Error in default colours files."; |
|
269 testResourceName(message, expected, actual); |
|
270 |
|
271 expected = new String[] {}; |
|
272 actual = page.getDefaultBorderStylesFiles(); |
|
273 message = "Error in default border styles files."; |
|
274 testResourceName(message, expected, actual); |
|
275 |
|
276 expected = new String[] {}; |
|
277 actual = page.getDefaultBorderShapesFiles(); |
|
278 message = "Error in default border shapes files."; |
|
279 testResourceName(message, expected, actual); |
|
280 |
|
281 expected = new String[] {}; |
|
282 actual = page.getDefaultPatternsFiles(); |
|
283 message = "Error in default patters files."; |
|
284 testResourceName(message, expected, actual); |
|
285 |
|
286 expected = new String[] {}; |
|
287 actual = page.getDefaultS12XmlFiles(); |
|
288 message = "Error in default S12 files."; |
|
289 testResourceName(message, expected, actual); |
|
290 } |
|
291 |
|
292 /** |
|
293 * Test method for |
|
294 * {@link com.symbian.smt.gui.wizard.NewSMTProjectWizard#performFinish()}. |
|
295 */ |
|
296 public final void testPerformFinish() { |
|
297 NewProjectCreationPageCaseInsensitive page = (NewProjectCreationPageCaseInsensitive) wizard |
|
298 .getPage("page1"); |
|
299 IProject newProject = page.getProjectHandle(); |
|
300 |
|
301 wizard.performFinish(); |
|
302 |
|
303 testPersistedSelectedItems(newProject); |
|
304 testPersistedItems(newProject); |
|
305 testWorkspaceContents(newProject); |
|
306 } |
|
307 |
|
308 private final void testPersistedItems(IProject project) { |
|
309 AbstractPersistentDataStore dataStore = getPersistDataStore(project); |
|
310 String[] options = dataStore.getAdvancedOptions(); |
|
311 assertEquals(0, options.length); |
|
312 |
|
313 Boolean fixsize = dataStore.getFixItemSize(); |
|
314 assertFalse(fixsize); |
|
315 |
|
316 options = dataStore.getDistributionTexts(); |
|
317 assertEquals(4, options.length); |
|
318 assertEquals("secret", options[0]); |
|
319 assertEquals("confidential", options[1]); |
|
320 assertEquals("internal", options[2]); |
|
321 assertEquals("unrestricted", options[3]); |
|
322 |
|
323 options = dataStore.getModelVersionTexts(); |
|
324 assertEquals(3, options.length); |
|
325 assertEquals("draft", options[0]); |
|
326 assertEquals("build", options[1]); |
|
327 assertEquals("issued", options[2]); |
|
328 |
|
329 options = dataStore.getPrintedDpis(); |
|
330 assertEquals(2, options.length); |
|
331 assertEquals("300", options[0]); |
|
332 assertEquals("600", options[1]); |
|
333 |
|
334 String[] filenames = dataStore.getBorderShapesFiles(); |
|
335 assertEquals(0, filenames.length); |
|
336 |
|
337 filenames = dataStore.getBorderStylesFiles(); |
|
338 assertEquals(0, filenames.length); |
|
339 |
|
340 filenames = dataStore.getColoursFiles(); |
|
341 assertEquals(1, filenames.length); |
|
342 assertEquals(prependPathAndMakeLowerCase("system_model_colors.xml"), |
|
343 filenames[0].toLowerCase()); |
|
344 |
|
345 filenames = dataStore.getDependenciesFiles(); |
|
346 assertEquals(0, filenames.length); |
|
347 |
|
348 filenames = dataStore.getLevelsFiles(); |
|
349 assertEquals(3, filenames.length); |
|
350 assertEquals("Auto", filenames[0]); |
|
351 assertEquals(prependPathAndMakeLowerCase("Levels.xml"), filenames[1] |
|
352 .toLowerCase()); |
|
353 assertEquals(prependPathAndMakeLowerCase("Levels91.xml"), filenames[2] |
|
354 .toLowerCase()); |
|
355 |
|
356 filenames = dataStore.getLocalisationFiles(); |
|
357 assertEquals(1, filenames.length); |
|
358 assertEquals(prependPathAndMakeLowerCase("display-names.xml"), |
|
359 filenames[0].toLowerCase()); |
|
360 |
|
361 filenames = dataStore.getPatternsFiles(); |
|
362 assertEquals(0, filenames.length); |
|
363 |
|
364 filenames = dataStore.getS12XmlFiles(); |
|
365 assertEquals(0, filenames.length); |
|
366 |
|
367 filenames = dataStore.getShapesFiles(); |
|
368 assertEquals(2, filenames.length); |
|
369 assertEquals(prependPathAndMakeLowerCase("Shapes.xml"), filenames[0] |
|
370 .toLowerCase()); |
|
371 assertEquals(prependPathAndMakeLowerCase("Example-shapes.xml"), |
|
372 filenames[1].toLowerCase()); |
|
373 |
|
374 filenames = dataStore.getSystemInfoFiles(); |
|
375 assertEquals(1, filenames.length); |
|
376 assertEquals(prependPathAndMakeLowerCase("SystemInfo.xml"), |
|
377 filenames[0].toLowerCase()); |
|
378 |
|
379 filenames = dataStore.getBorderShapesFiles(); |
|
380 assertEquals(0, filenames.length); |
|
381 |
|
382 filenames = dataStore.getBorderShapesFiles(); |
|
383 assertEquals(0, filenames.length); |
|
384 } |
|
385 |
|
386 private final void testPersistedSelectedItems(IProject project) { |
|
387 AbstractPersistentDataStore dataStore = getPersistDataStore(project); |
|
388 |
|
389 String[] filenames = dataStore.getSelectedBorderShapesFiles(); |
|
390 assertEquals(0, filenames.length); |
|
391 |
|
392 filenames = dataStore.getSelectedBorderStylesFiles(); |
|
393 assertEquals(0, filenames.length); |
|
394 |
|
395 filenames = dataStore.getSelectedColoursFiles(); |
|
396 assertEquals(0, filenames.length); |
|
397 |
|
398 filenames = dataStore.getSelectedDependenciesFiles(); |
|
399 assertEquals(0, filenames.length); |
|
400 |
|
401 filenames = dataStore.getSelectedLevelsFiles(); |
|
402 assertEquals(1, filenames.length); |
|
403 assertEquals("Auto", filenames[0]); |
|
404 |
|
405 filenames = dataStore.getSelectedLocalisationFiles(); |
|
406 assertEquals(1, filenames.length); |
|
407 assertEquals(prependPathAndMakeLowerCase("display-names.xml"), |
|
408 filenames[0].toLowerCase()); |
|
409 |
|
410 filenames = dataStore.getSelectedPatternsFiles(); |
|
411 assertEquals(0, filenames.length); |
|
412 |
|
413 filenames = dataStore.getSelectedS12XmlFiles(); |
|
414 assertEquals(0, filenames.length); |
|
415 |
|
416 filenames = dataStore.getSelectedShapesFiles(); |
|
417 assertEquals(1, filenames.length); |
|
418 assertEquals(prependPathAndMakeLowerCase("Shapes.xml"), filenames[0] |
|
419 .toLowerCase()); |
|
420 |
|
421 filenames = dataStore.getSelectedSystemInfoFiles(); |
|
422 assertEquals(0, filenames.length); |
|
423 |
|
424 String distributionText = dataStore.getSelectedDistributionText(); |
|
425 assertEquals("secret", distributionText); |
|
426 |
|
427 String modelVersionText = dataStore.getSelectedModelVersionText(); |
|
428 assertEquals("draft", modelVersionText); |
|
429 |
|
430 String dpi = dataStore.getSelectedPrintedDpi(); |
|
431 assertEquals("600", dpi); |
|
432 } |
|
433 |
|
434 private final void testResourceName(String message, String[] expected, |
|
435 String[] actual) { |
|
436 assertEquals(message, expected.length, actual.length); |
|
437 |
|
438 for (int i = 0; i < expected.length; i++) { |
|
439 assertEquals(message, Helper.relative2AbsolutePaths(expected[i], |
|
440 smgFolder, SEPARATOR), actual[i]); |
|
441 } |
|
442 } |
|
443 |
|
444 private final void testWorkspaceContents(IProject project) { |
|
445 String folderName = ""; |
|
446 |
|
447 try { |
|
448 folderName = BORDER_SHAPES.arg(); |
|
449 IFolder folder = project.getFolder(new Path(folderName)); |
|
450 assertFalse("Folder [" + folderName |
|
451 + "] does not exist in project.", !folder.exists()); |
|
452 IResource[] children = folder.members(); |
|
453 assertEquals(0, children.length); |
|
454 |
|
455 folderName = BORDER_STYLES.arg(); |
|
456 folder = project.getFolder(new Path(folderName)); |
|
457 assertFalse("Folder [" + folderName |
|
458 + "] does not exist in project.", !folder.exists()); |
|
459 children = folder.members(); |
|
460 assertEquals(0, children.length); |
|
461 |
|
462 folderName = COLOURS.arg(); |
|
463 folder = project.getFolder(new Path(folderName)); |
|
464 assertFalse("Folder [" + folderName |
|
465 + "] does not exist in project.", !folder.exists()); |
|
466 children = folder.members(); |
|
467 assertEquals(0, children.length); |
|
468 |
|
469 folderName = DEPENDENCIES.arg(); |
|
470 folder = project.getFolder(new Path(folderName)); |
|
471 assertFalse("Folder [" + folderName |
|
472 + "] does not exist in project.", !folder.exists()); |
|
473 children = folder.members(); |
|
474 assertEquals(0, children.length); |
|
475 |
|
476 folderName = LEVELS.arg(); |
|
477 folder = project.getFolder(new Path(folderName)); |
|
478 assertFalse("Folder [" + folderName |
|
479 + "] does not exist in project.", !folder.exists()); |
|
480 children = folder.members(); |
|
481 assertEquals(0, children.length); |
|
482 |
|
483 folderName = LOCALISATION.arg(); |
|
484 folder = project.getFolder(new Path(folderName)); |
|
485 assertFalse("Folder [" + folderName |
|
486 + "] does not exist in project.", !folder.exists()); |
|
487 children = folder.members(); |
|
488 assertEquals(1, children.length); |
|
489 assertEquals("display-names.xml", children[0].getName()); |
|
490 |
|
491 folderName = PATTERNS.arg(); |
|
492 folder = project.getFolder(new Path(folderName)); |
|
493 assertFalse("Folder [" + folderName |
|
494 + "] does not exist in project.", !folder.exists()); |
|
495 children = folder.members(); |
|
496 assertEquals(0, children.length); |
|
497 |
|
498 folderName = S12_XML.arg(); |
|
499 folder = project.getFolder(new Path(folderName)); |
|
500 assertFalse("Folder [" + folderName |
|
501 + "] does not exist in project.", !folder.exists()); |
|
502 children = folder.members(); |
|
503 assertEquals(0, children.length); |
|
504 |
|
505 folderName = SHAPES.arg(); |
|
506 folder = project.getFolder(new Path(folderName)); |
|
507 assertFalse("Folder [" + folderName |
|
508 + "] does not exist in project.", !folder.exists()); |
|
509 // TODO:BRS:Check why assertions below fail. |
|
510 // assertEquals(1, children.length); |
|
511 // assertEquals("Shapes.xml", children[0].getName()); |
|
512 |
|
513 folderName = SYSTEM_INFO.arg(); |
|
514 folder = project.getFolder(new Path(folderName)); |
|
515 assertFalse("Folder [" + folderName |
|
516 + "] does not exist in project.", !folder.exists()); |
|
517 children = folder.members(); |
|
518 assertEquals(0, children.length); |
|
519 } catch (CoreException e) { |
|
520 assertFalse("Exception while looking for the contents of folder [" |
|
521 + folderName + "].", true); |
|
522 } |
|
523 } |
|
524 |
|
525 } |