8aabb21db37d62e49ac8627dc6ec8c1b7b8a4c4f
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / StandardImportAndReadSmokeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * Marc-Andre Laperle - Added tests for extracting archives during import
12 *******************************************************************************/
13
14 package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.io.ByteArrayInputStream;
22 import java.io.File;
23 import java.io.IOException;
24 import java.net.URISyntaxException;
25 import java.nio.file.Files;
26 import java.nio.file.Paths;
27 import java.util.Collections;
28 import java.util.Comparator;
29 import java.util.List;
30
31 import org.eclipse.core.resources.IFile;
32 import org.eclipse.core.resources.IFolder;
33 import org.eclipse.core.resources.IProject;
34 import org.eclipse.core.resources.IResource;
35 import org.eclipse.core.resources.ResourcesPlugin;
36 import org.eclipse.core.runtime.CoreException;
37 import org.eclipse.core.runtime.IPath;
38 import org.eclipse.core.runtime.Path;
39 import org.eclipse.core.runtime.URIUtil;
40 import org.eclipse.jface.viewers.StructuredSelection;
41 import org.eclipse.jface.wizard.WizardDialog;
42 import org.eclipse.swt.widgets.Shell;
43 import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
44 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
45 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
46 import org.eclipse.swtbot.swt.finder.results.VoidResult;
47 import org.eclipse.swtbot.swt.finder.waits.Conditions;
48 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
49 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
50 import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
51 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
52 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
53 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
54 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
55 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
56 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
57 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
58 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
59 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
60 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
61 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
62 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
63 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
64 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
65 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder;
66 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder;
67 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
68 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
69 import org.eclipse.ui.IWorkbench;
70 import org.eclipse.ui.IWorkbenchWindow;
71 import org.eclipse.ui.PlatformUI;
72 import org.junit.AfterClass;
73 import org.junit.BeforeClass;
74 import org.junit.Test;
75 import org.junit.runner.RunWith;
76
77 /**
78 * SWTBot Smoke test using ImportTraceWizard.
79 *
80 * @author Bernd Hufmann
81 */
82 @RunWith(SWTBotJunit4ClassRunner.class)
83 public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
84
85 private static final String TRACE_FOLDER_PARENT_PATH = "../../ctf/org.eclipse.tracecompass.ctf.core.tests/traces/";
86 private static final String ARCHIVE_FILE_NAME = "synctraces.tar.gz";
87 private static final String EMPTY_ARCHIVE_FOLDER = "emptyArchiveFolder";
88 private static final String EMPTY_FILE_NAME = "emptyFile";
89 private static final String TRACE_ARCHIVE_PATH = TRACE_FOLDER_PARENT_PATH + ARCHIVE_FILE_NAME;
90 private static final String TRACE_FOLDER_PARENT_NAME = "traces";
91 private static final String TRACE_PROJECT_NAME = "Tracing";
92
93 private static final String ARCHIVE_ROOT_ELEMENT_NAME = "/";
94 private static final String GENERATED_ARCHIVE_NAME = "testtraces.zip";
95 private static final String URI_SEPARATOR = "/";
96 private static final String URI_FILE_SCHEME = "file:";
97 private static final String URI_JAR_FILE_SCHEME = "jar:file:";
98 private static final boolean IS_WIN32 = System.getProperty("os.name").startsWith("Windows"); //$NON-NLS-1$//$NON-NLS-2$
99 private static final String URI_DEVICE_SEPARATOR = IS_WIN32 ? URI_SEPARATOR : "";
100
101 /** Test Class setup */
102 @BeforeClass
103 public static void beforeClass() {
104 createProject(TRACE_PROJECT_NAME);
105 }
106
107 /** Test Class tear down */
108 @AfterClass
109 public static void afterClass() {
110 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
111 }
112
113 /**
114 * Test import from directory
115 *
116 * @throws Exception
117 * on error
118 */
119 @Test
120 public void testImportFromDirectory() throws Exception {
121 testImport(0, false, false);
122 }
123
124 /**
125 * Test import from directory, create links
126 *
127 * @throws Exception
128 * on error
129 */
130 @Test
131 public void testImportFromDirectoryLinks() throws Exception {
132 testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false);
133 }
134
135 /**
136 * Test import from directory, preserve folder structure
137 *
138 * @throws Exception
139 * on error
140 */
141 @Test
142 public void testImportFromDirectoryPreserveFolder() throws Exception {
143 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, false);
144 }
145
146 /**
147 * Test import from directory, create links, preserve folder structure
148 *
149 * @throws Exception
150 * on error
151 */
152 @Test
153 public void testImportFromDirectoryLinksPreserveFolder() throws Exception {
154 int options = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
155 testImport(options, false, false);
156 }
157
158 /**
159 * Test import from directory, overwrite all
160 *
161 * @throws Exception
162 * on error
163 */
164 @Test
165 public void testImportFromDirectoryOverwrite() throws Exception {
166 testImport(0, false, false);
167 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
168 }
169
170 /**
171 * Test import from archive
172 *
173 * @throws Exception
174 * on error
175 */
176 @Test
177 public void testImportFromArchive() throws Exception {
178 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true);
179 }
180
181 /**
182 * Test import from directory, preserve folder structure
183 * @throws Exception on error
184 */
185 @Test
186 public void testImportFromArchivePreserveFolder() throws Exception {
187 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
188 }
189
190 /**
191 * Test import from directory, overwrite all
192 *
193 * @throws Exception
194 * on error
195 */
196 @Test
197 public void testImportFromArchiveOverwrite() throws Exception {
198 testImport(0, false, true);
199 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
200 }
201
202 /**
203 * Test import from directory containing archives
204 *
205 * @throws Exception
206 * on error
207 */
208 @Test
209 public void testExtractArchivesFromDirectory() throws Exception {
210 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
211 }
212
213 /**
214 * Test import from directory containing archives, create links
215 * @throws Exception on error
216 */
217 @Test
218 public void testExtractArchivesFromDirectoryLinks() throws Exception {
219 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
220 }
221
222 /**
223 * Test import from directory containing archives, create links, preserve folder structure
224 * @throws Exception on error
225 */
226 @Test
227 public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception {
228 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, false);
229 }
230
231 /**
232 * Test import from archive containing archives
233 *
234 * @throws Exception
235 * on error
236 */
237 @Test
238 public void testExtractArchivesFromArchive() throws Exception {
239 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
240 }
241
242 /**
243 * Test import from archive containing archives, preserve folder structure
244 *
245 * @throws Exception
246 * on error
247 */
248 @Test
249 public void testExtractArchivesFromArchivePreserveFolder() throws Exception {
250 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
251 }
252
253 /**
254 * Test import from an empty archive. This should not import anything.
255 *
256 * @throws Exception
257 * on error
258 */
259 @Test
260 public void testEmptyArchive() throws Exception {
261 String testArchivePath = createEmptyArchive();
262
263 openImportWizard();
264 selectImportFromArchive(testArchivePath);
265 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
266 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
267 importFinish();
268
269 assertNoTraces();
270
271 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
272 Files.delete(Paths.get(testArchivePath));
273 }
274
275 /**
276 * Test import from an empty directory. This should not import anything.
277 *
278 * @throws Exception
279 * on error
280 */
281 @Test
282 public void testEmptyDirectory() throws Exception {
283 IFolder emptyDirectory = createEmptyDirectory();
284 String testDirectoryPath = emptyDirectory.getLocation().toOSString();
285
286 openImportWizard();
287 selectImportFromDirectory(testDirectoryPath);
288 selectFolder(EMPTY_ARCHIVE_FOLDER);
289 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
290 importFinish();
291
292 assertNoTraces();
293
294 Files.delete(Paths.get(testDirectoryPath));
295 emptyDirectory.delete(true, null);
296 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
297 }
298
299 /**
300 * Test import from an directory with an empty file. This should not import anything.
301 *
302 * @throws Exception
303 * on error
304 */
305 @Test
306 public void testEmptyFile() throws Exception {
307 IFolder folder = createEmptyDirectory();
308 createEmptyFile(folder);
309 String testDirectoryPath = folder.getLocation().toOSString();
310 openImportWizard();
311 selectImportFromDirectory(testDirectoryPath);
312 selectFile(EMPTY_FILE_NAME, EMPTY_ARCHIVE_FOLDER);
313 setOptions(ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
314 importFinish();
315
316 assertNoTraces();
317
318 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
319 folder.delete(true, null);
320 }
321
322 /**
323 * Test import from a directory containing an empty archive. This should not import anything.
324 *
325 * @throws Exception
326 * on error
327 */
328 @Test
329 public void testDirectoryWithEmptyArchive() throws Exception {
330 String testArchivePath = createEmptyArchive();
331
332 openImportWizard();
333 selectImportFromDirectory(getProjectResource().getLocation().toOSString());
334 selectFile(GENERATED_ARCHIVE_NAME, TRACE_PROJECT_NAME);
335 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
336 importFinish();
337
338 assertNoTraces();
339
340 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
341 Files.delete(Paths.get(testArchivePath));
342 }
343
344 /**
345 * Test import from a nested empty archive. This should not import anything.
346 *
347 * @throws Exception
348 * on error
349 */
350 @Test
351 public void testNestedEmptyArchive() throws Exception {
352 IProject project = getProjectResource();
353
354 // Create the empty archive from an empty folder
355 String testArchivePath = createEmptyArchive();
356
357 // Rename archive so that we can create a new one with the same name
358 project.refreshLocal(IResource.DEPTH_ONE, null);
359 IFile[] files = project.getWorkspace().getRoot().findFilesForLocationURI(new File(testArchivePath).toURI());
360 IFile archiveFile = files[0];
361 String newEmptyArchiveName = "nested" + archiveFile.getName();
362 IPath dest = archiveFile.getFullPath().removeLastSegments(1).append(newEmptyArchiveName);
363 archiveFile.move(dest, true, null);
364 IFile renamedArchiveFile = archiveFile.getWorkspace().getRoot().getFile(dest);
365
366 createArchive(renamedArchiveFile);
367 renamedArchiveFile.delete(true, null);
368
369 openImportWizard();
370 selectImportFromArchive(testArchivePath);
371 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
372 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
373 importFinish();
374
375 assertNoTraces();
376
377 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
378 Files.delete(Paths.get(testArchivePath));
379 }
380
381 private static void assertNoTraces() {
382 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
383 assertNotNull(tmfProject);
384 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
385 assertNotNull(tracesFolder);
386 List<TmfTraceElement> traces = tracesFolder.getTraces();
387 assertTrue(traces.isEmpty());
388 }
389
390 private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception {
391 String expectedSourceLocation = null;
392 openImportWizard();
393 if (fromArchive) {
394 expectedSourceLocation = URI_JAR_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(TRACE_ARCHIVE_PATH).getCanonicalPath()) + "!" + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
395 selectImportFromArchive(TRACE_ARCHIVE_PATH);
396 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
397 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
398 assertFalse(checkBox.isEnabled());
399 } else {
400 String sourcePath = TRACE_FOLDER_PARENT_PATH + File.separator + TRACE_FOLDER + File.separator + TRACE_NAME;
401 expectedSourceLocation = URI_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(sourcePath).getCanonicalPath()) + URI_SEPARATOR;
402 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
403 selectFolder(new String [] {TRACE_FOLDER_PARENT_NAME, TRACE_FOLDER });
404 }
405
406 setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
407 importFinish();
408
409 IPath expectedElementPath = new Path(TRACE_NAME);
410 if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
411 expectedElementPath = new Path(TRACE_FOLDER).append(expectedElementPath);
412 }
413
414 checkOptions(options, expectedSourceLocation, expectedElementPath);
415 TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
416 if (testViews) {
417 testViews(tmfEd);
418 }
419
420 fBot.closeAllEditors();
421
422 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
423 }
424
425 private void testImportAndExtractArchives(int options, boolean testViews, boolean fromArchive) throws Exception {
426 String expectedSourceLocation;
427 IPath expectedElementPath;
428 String testArchivePath = null;
429 if (fromArchive) {
430 testArchivePath = createNestedArchive();
431 openImportWizard();
432 selectImportFromArchive(testArchivePath);
433 selectFile(ARCHIVE_FILE_NAME, ARCHIVE_ROOT_ELEMENT_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME);
434
435 expectedSourceLocation = URI_JAR_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(testArchivePath).getCanonicalPath()) + "!" + URI_SEPARATOR + TRACE_PROJECT_NAME + URI_SEPARATOR + TRACE_FOLDER_PARENT_NAME + URI_SEPARATOR + ARCHIVE_FILE_NAME
436 + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
437 expectedElementPath = new Path(TRACE_PROJECT_NAME).append(TRACE_FOLDER_PARENT_NAME).append(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
438 } else {
439 openImportWizard();
440 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
441 selectFile(ARCHIVE_FILE_NAME, TRACE_FOLDER_PARENT_NAME);
442 expectedElementPath = new Path(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
443 expectedSourceLocation = URI_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(TRACE_FOLDER_PARENT_PATH).getCanonicalPath()) + URI_SEPARATOR + ARCHIVE_FILE_NAME + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
444 }
445
446 if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) == 0) {
447 expectedElementPath = new Path(TRACE_NAME);
448 }
449
450 setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
451 importFinish();
452 // Archives should never be imported as links
453 int expectedOptions = options & ~ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
454 checkOptions(expectedOptions, expectedSourceLocation, expectedElementPath);
455
456 TmfEventsEditor editor = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
457 if (testViews) {
458 testViews(editor);
459 }
460
461 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
462 if (testArchivePath != null) {
463 Files.delete(Paths.get(testArchivePath));
464 }
465 }
466
467 /**
468 * Create a temporary archive containing a nested archive. For example,
469 * testtraces.zip/synctraces.tar.gz can be used to test a nested archive.
470 */
471 private static String createNestedArchive() throws IOException, CoreException, URISyntaxException {
472 // Link to the test traces folder. We use a link so that we can safely
473 // delete the entire project when we are done.
474 IProject project = getProjectResource();
475 String canonicalPath = new File(TRACE_FOLDER_PARENT_PATH).getCanonicalPath();
476 IFolder folder = project.getFolder(TRACE_FOLDER_PARENT_NAME);
477 folder.createLink(new Path(canonicalPath), IResource.REPLACE, null);
478 IFile file = folder.getFile(ARCHIVE_FILE_NAME);
479 String archivePath = createArchive(file);
480 folder.delete(true, null);
481 return archivePath;
482 }
483
484 /**
485 * Create the empty archive from an empty folder
486 */
487 private static String createEmptyArchive() throws CoreException, URISyntaxException {
488 IFolder tempEmptyDirectory = createEmptyDirectory();
489 String archivePath = createArchive(tempEmptyDirectory);
490 tempEmptyDirectory.delete(true, null);
491 return archivePath;
492 }
493
494 private static IFolder createEmptyDirectory() throws CoreException {
495 IProject project = getProjectResource();
496 IFolder folder = project.getFolder(EMPTY_ARCHIVE_FOLDER);
497 folder.create(true, true, null);
498 return folder;
499 }
500
501 private static void createEmptyFile(IFolder folder) throws CoreException {
502 // Create empty file
503 IFile file = folder.getFile(EMPTY_FILE_NAME);
504 file.create(new ByteArrayInputStream(new byte[0]), true, null);
505 }
506
507 /**
508 * Create a temporary archive from the specified resource.
509 */
510 private static String createArchive(IResource sourceResource) throws URISyntaxException {
511 IPath exportedPath = sourceResource.getFullPath();
512
513 SWTBotTreeItem traceFilesProject = SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME);
514 traceFilesProject.contextMenu("Export...").click();
515
516 fBot.waitUntil(Conditions.shellIsActive("Export"));
517 SWTBotShell activeShell = fBot.activeShell();
518 SWTBotTree exportWizardsTree = fBot.tree();
519 SWTBotTreeItem treeItem = SWTBotUtils.getTreeItem(fBot, exportWizardsTree, "General", "Archive File");
520 treeItem.select();
521 fBot.button("Next >").click();
522 fBot.button("&Deselect All").click();
523 try {
524 fBot.checkBox("Resolve and export linked resources").select();
525 } catch (WidgetNotFoundException e) {
526 // Ignore, doesn't exist pre-4.6M5
527 }
528
529 if (sourceResource instanceof IFile) {
530 String[] folderPath = exportedPath.removeLastSegments(1).segments();
531 String fileName = exportedPath.lastSegment();
532 selectFile(fileName, folderPath);
533 } else {
534 selectFolder(exportedPath.segments());
535 }
536
537 String workspacePath = URIUtil.toFile(URIUtil.fromString(System.getProperty("osgi.instance.area"))).getAbsolutePath();
538 final String archiveDestinationPath = workspacePath + File.separator + TRACE_PROJECT_NAME + File.separator + GENERATED_ARCHIVE_NAME;
539 fBot.comboBox().setText(archiveDestinationPath);
540 fBot.button("&Finish").click();
541 fBot.waitUntil(Conditions.shellCloses(activeShell));
542 return archiveDestinationPath;
543 }
544
545 private void testViews(TmfEventsEditor editor) {
546 testHistogramView(getViewPart("Histogram"), editor);
547 testPropertyView(getViewPart("Properties"));
548 testStatisticsView(getViewPart("Statistics"));
549 }
550
551 private static void openImportWizard() {
552 fWizard = new ImportTraceWizard();
553
554 UIThreadRunnable.asyncExec(new VoidResult() {
555 @Override
556 public void run() {
557 final IWorkbench workbench = PlatformUI.getWorkbench();
558 // Fire the Import Trace Wizard
559 if (workbench != null) {
560 final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
561 Shell shell = activeWorkbenchWindow.getShell();
562 assertNotNull(shell);
563 ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
564 WizardDialog dialog = new WizardDialog(shell, fWizard);
565 dialog.open();
566 }
567 }
568 });
569
570 fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
571 }
572
573 private static void selectImportFromDirectory(String directoryPath) {
574 SWTBotRadio button = fBot.radio("Select roo&t directory:");
575 button.click();
576
577 SWTBotCombo sourceCombo = fBot.comboBox();
578 File traceFolderParent = new File(directoryPath);
579 sourceCombo.setText(traceFolderParent.getAbsolutePath());
580
581 SWTBotText text = fBot.text();
582 text.setFocus();
583 }
584
585 private static void selectImportFromArchive(String archivePath) {
586 SWTBotRadio button = fBot.radio("Select &archive file:");
587 button.click();
588
589 SWTBotCombo sourceCombo = fBot.comboBox(1);
590
591 sourceCombo.setText(new File(archivePath).getAbsolutePath());
592
593 SWTBotText text = fBot.text();
594 text.setFocus();
595 }
596
597 private static void selectFolder(String... treePath) {
598 selectFolder(true, treePath);
599 }
600
601 private static void selectFolder(boolean check, String... treePath) {
602 SWTBotTree tree = fBot.tree();
603 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
604 SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, tree, treePath);
605 if (check) {
606 folderNode.check();
607 } else {
608 folderNode.select();
609 }
610 }
611
612 private static void selectFile(String fileName, String... folderTreePath) {
613 selectFolder(false, folderTreePath);
614
615 SWTBotTable fileTable = fBot.table();
616 fBot.waitUntil(Conditions.widgetIsEnabled(fileTable));
617 fBot.waitUntil(ConditionHelpers.isTableItemAvailable(fileName, fileTable));
618 SWTBotTableItem tableItem = fileTable.getTableItem(fileName);
619 tableItem.check();
620 }
621
622 private static void setOptions(int optionFlags, String traceTypeName) {
623 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
624 if (checkBox.isEnabled()) {
625 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) {
626 checkBox.select();
627 } else {
628 checkBox.deselect();
629 }
630 }
631
632 checkBox = fBot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure);
633 if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
634 checkBox.select();
635 } else {
636 checkBox.deselect();
637 }
638
639 checkBox = fBot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized);
640 if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
641 checkBox.select();
642 } else {
643 checkBox.deselect();
644 }
645
646 checkBox = fBot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace);
647 if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) {
648 checkBox.select();
649 } else {
650 checkBox.deselect();
651 }
652
653 SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
654 if (traceTypeName != null && !traceTypeName.isEmpty()) {
655 comboBox.setSelection(traceTypeName);
656 } else {
657 comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
658 }
659 }
660
661 private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
662 IProject project = getProjectResource();
663 assertTrue(project.exists());
664 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
665 assertNotNull(tmfProject);
666 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
667 assertNotNull(tracesFolder);
668 List<TmfTraceElement> traces = tracesFolder.getTraces();
669 assertFalse(traces.isEmpty());
670 Collections.sort(traces, new Comparator<TmfTraceElement>() {
671 @Override
672 public int compare(TmfTraceElement arg0, TmfTraceElement arg1) {
673 return arg0.getElementPath().compareTo(arg1.getElementPath());
674 }
675 });
676
677 TmfTraceElement tmfTraceElement = traces.get(0);
678 IResource traceResource = tmfTraceElement.getResource();
679
680 assertEquals((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0, traceResource.isLinked());
681
682 // i.e. /Tracing/Traces
683 IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPath);
684 assertEquals(expectedPath, traceResource.getFullPath());
685
686 String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
687 assertNotNull(sourceLocation);
688 assertEquals(expectedSourceLocation, sourceLocation);
689 }
690
691 private static IProject getProjectResource() {
692 return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
693 }
694 }
This page took 0.046488 seconds and 4 git commands to generate.