1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Marc-Andre Laperle - Added tests for extracting archives during import
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
;
16 import static org
.eclipse
.swtbot
.swt
.finder
.matchers
.WidgetMatcherFactory
.withMnemonic
;
17 import static org
.eclipse
.tracecompass
.common
.core
.NonNullUtils
.checkNotNull
;
18 import static org
.junit
.Assert
.assertEquals
;
19 import static org
.junit
.Assert
.assertFalse
;
20 import static org
.junit
.Assert
.assertNotNull
;
21 import static org
.junit
.Assert
.assertTrue
;
23 import java
.io
.ByteArrayInputStream
;
25 import java
.io
.IOException
;
26 import java
.net
.URISyntaxException
;
27 import java
.nio
.file
.Files
;
28 import java
.nio
.file
.Paths
;
29 import java
.util
.Collections
;
30 import java
.util
.Comparator
;
31 import java
.util
.List
;
33 import org
.eclipse
.core
.resources
.IFile
;
34 import org
.eclipse
.core
.resources
.IFolder
;
35 import org
.eclipse
.core
.resources
.IProject
;
36 import org
.eclipse
.core
.resources
.IResource
;
37 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
38 import org
.eclipse
.core
.runtime
.CoreException
;
39 import org
.eclipse
.core
.runtime
.IPath
;
40 import org
.eclipse
.core
.runtime
.Path
;
41 import org
.eclipse
.core
.runtime
.URIUtil
;
42 import org
.eclipse
.jdt
.annotation
.NonNull
;
43 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
44 import org
.eclipse
.jface
.wizard
.WizardDialog
;
45 import org
.eclipse
.swt
.widgets
.Shell
;
46 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
47 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
48 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
49 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
50 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCheckBox
;
51 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCombo
;
52 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotRadio
;
53 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
54 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
55 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTableItem
;
56 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
57 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
58 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
59 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.TimeoutException
;
60 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizard
;
61 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizardPage
;
62 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.Messages
;
63 import org
.eclipse
.tracecompass
.tmf
.core
.TmfCommonConstants
;
64 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfExperimentElement
;
66 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectElement
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceElement
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceFolder
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTracesFolder
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
74 import org
.eclipse
.ui
.IWorkbench
;
75 import org
.eclipse
.ui
.IWorkbenchWindow
;
76 import org
.eclipse
.ui
.PlatformUI
;
77 import org
.junit
.AfterClass
;
78 import org
.junit
.BeforeClass
;
79 import org
.junit
.Test
;
80 import org
.junit
.runner
.RunWith
;
83 * SWTBot Smoke test using ImportTraceWizard.
85 * @author Bernd Hufmann
87 @RunWith(SWTBotJunit4ClassRunner
.class)
88 public class StandardImportAndReadSmokeTest
extends AbstractImportAndReadSmokeTest
{
90 private static final String TRACE_FOLDER_PARENT_PATH
= "../../ctf/org.eclipse.tracecompass.ctf.core.tests/traces/";
91 private static final String ARCHIVE_FILE_NAME
= "synctraces.tar.gz";
92 private static final String EMPTY_ARCHIVE_FOLDER
= "emptyArchiveFolder";
93 private static final String EMPTY_FILE_NAME
= "emptyFile";
94 private static final String TRACE_ARCHIVE_PATH
= TRACE_FOLDER_PARENT_PATH
+ ARCHIVE_FILE_NAME
;
95 private static final String TRACE_FOLDER_PARENT_NAME
= "traces";
96 private static final String TRACE_PROJECT_NAME
= "Tracing";
98 private static final String ARCHIVE_ROOT_ELEMENT_NAME
= "/";
99 private static final String GENERATED_ARCHIVE_NAME
= "testtraces.zip";
100 private static final String URI_SEPARATOR
= "/";
101 private static final String URI_FILE_SCHEME
= "file:";
102 private static final String URI_JAR_FILE_SCHEME
= "jar:file:";
103 private static final boolean IS_WIN32
= System
.getProperty("os.name").startsWith("Windows"); //$NON-NLS-1$//$NON-NLS-2$
104 private static final String URI_DEVICE_SEPARATOR
= IS_WIN32 ? URI_SEPARATOR
: "";
106 /** Test Class setup */
108 public static void beforeClass() {
109 createProject(TRACE_PROJECT_NAME
);
112 /** Test Class tear down */
114 public static void afterClass() {
115 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
119 * Test import from directory
125 public void testImportFromDirectory() throws Exception
{
126 testImport(0, false, false);
130 * Test import from directory, create links
136 public void testImportFromDirectoryLinks() throws Exception
{
137 testImport(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
, false, false);
141 * Test import from directory, create experiment
147 public void testImportWithExperiment() throws Exception
{
148 testImport(ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, false);
152 * Test import from directory, create experiment (validate experiment name)
158 public void testImportWithExperimentValidation() throws Exception
{
159 testImport(ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, false, false);
163 * Test import from directory, preserve folder structure
169 public void testImportFromDirectoryPreserveFolder() throws Exception
{
170 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, false);
174 * Test import from directory, create links, preserve folder structure
180 public void testImportFromDirectoryLinksPreserveFolder() throws Exception
{
181 int options
= ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
;
182 testImport(options
, false, false);
186 * Test import from directory, overwrite all
192 public void testImportFromDirectoryOverwrite() throws Exception
{
193 testImport(0, false, false);
194 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
198 * Test import from archive
204 public void testImportFromArchive() throws Exception
{
205 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, true, true);
209 * Test import from archive, create Experiment
215 public void testImportFromArchiveWithExperiment() throws Exception
{
216 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
| ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, true);
220 * Test import from directory, preserve folder structure
221 * @throws Exception on error
224 public void testImportFromArchivePreserveFolder() throws Exception
{
225 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
229 * Test import from directory, overwrite all
235 public void testImportFromArchiveOverwrite() throws Exception
{
236 testImport(0, false, true);
237 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
241 * Test import from directory containing archives
247 public void testExtractArchivesFromDirectory() throws Exception
{
248 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
252 * Test import from directory containing archives, create links
253 * @throws Exception on error
256 public void testExtractArchivesFromDirectoryLinks() throws Exception
{
257 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
261 * Test import from directory containing archives, create links, preserve folder structure
262 * @throws Exception on error
265 public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception
{
266 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, true, false);
270 * Test import from archive containing archives
276 public void testExtractArchivesFromArchive() throws Exception
{
277 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
281 * Test import from archive containing archives, preserve folder structure
287 public void testExtractArchivesFromArchivePreserveFolder() throws Exception
{
288 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
292 * Test import from an empty archive. This should not import anything.
298 public void testEmptyArchive() throws Exception
{
299 String testArchivePath
= createEmptyArchive();
302 selectImportFromArchive(testArchivePath
);
303 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
304 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
309 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
310 Files
.delete(Paths
.get(testArchivePath
));
314 * Test import from an empty directory. This should not import anything.
320 public void testEmptyDirectory() throws Exception
{
321 IFolder emptyDirectory
= createEmptyDirectory();
322 String testDirectoryPath
= emptyDirectory
.getLocation().toOSString();
325 selectImportFromDirectory(testDirectoryPath
);
326 selectFolder(EMPTY_ARCHIVE_FOLDER
);
327 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
332 Files
.delete(Paths
.get(testDirectoryPath
));
333 emptyDirectory
.delete(true, null);
334 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
338 * Test import from an directory with an empty file. This should not import anything.
344 public void testEmptyFile() throws Exception
{
345 IFolder folder
= createEmptyDirectory();
346 createEmptyFile(folder
);
347 String testDirectoryPath
= folder
.getLocation().toOSString();
349 selectImportFromDirectory(testDirectoryPath
);
350 selectFile(EMPTY_FILE_NAME
, EMPTY_ARCHIVE_FOLDER
);
351 setOptions(ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
356 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
357 folder
.delete(true, null);
361 * Test import from a directory containing an empty archive. This should not import anything.
367 public void testDirectoryWithEmptyArchive() throws Exception
{
368 String testArchivePath
= createEmptyArchive();
371 selectImportFromDirectory(getProjectResource().getLocation().toOSString());
372 selectFile(GENERATED_ARCHIVE_NAME
, TRACE_PROJECT_NAME
);
373 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
378 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
379 Files
.delete(Paths
.get(testArchivePath
));
383 * Test import from a nested empty archive. This should not import anything.
389 public void testNestedEmptyArchive() throws Exception
{
390 IProject project
= getProjectResource();
392 // Create the empty archive from an empty folder
393 String testArchivePath
= createEmptyArchive();
395 // Rename archive so that we can create a new one with the same name
396 project
.refreshLocal(IResource
.DEPTH_ONE
, null);
397 IFile
[] files
= project
.getWorkspace().getRoot().findFilesForLocationURI(new File(testArchivePath
).toURI());
398 IFile archiveFile
= files
[0];
399 String newEmptyArchiveName
= "nested" + archiveFile
.getName();
400 IPath dest
= archiveFile
.getFullPath().removeLastSegments(1).append(newEmptyArchiveName
);
401 archiveFile
.move(dest
, true, null);
402 IFile renamedArchiveFile
= archiveFile
.getWorkspace().getRoot().getFile(dest
);
404 createArchive(renamedArchiveFile
);
405 renamedArchiveFile
.delete(true, null);
408 selectImportFromArchive(testArchivePath
);
409 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
410 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
415 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
416 Files
.delete(Paths
.get(testArchivePath
));
419 private static void assertNoTraces() {
420 TmfProjectElement tmfProject
= TmfProjectRegistry
.getProject(getProjectResource(), true);
421 assertNotNull(tmfProject
);
422 TmfTraceFolder tracesFolder
= tmfProject
.getTracesFolder();
423 assertNotNull(tracesFolder
);
424 List
<TmfTraceElement
> traces
= tracesFolder
.getTraces();
425 assertTrue(traces
.isEmpty());
428 private void testImport(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
429 testImport(options
, testViews
, fromArchive
, true);
432 private void testImport(int options
, boolean testViews
, boolean fromArchive
, boolean defaultExperiment
) throws Exception
{
433 String expectedSourceLocation
= null;
435 @NonNull String experimentName
;
437 experimentName
= checkNotNull(new Path(ARCHIVE_FILE_NAME
).lastSegment());
439 experimentName
= checkNotNull(new Path(TRACE_FOLDER_PARENT_PATH
).lastSegment());
442 if (!defaultExperiment
) {
443 SWTBotUtils
.createExperiment(fBot
, TRACE_PROJECT_NAME
, experimentName
);
448 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
;
449 selectImportFromArchive(TRACE_ARCHIVE_PATH
);
450 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
451 SWTBotCheckBox checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_CreateLinksInWorkspace
);
452 assertFalse(checkBox
.isEnabled());
454 String sourcePath
= TRACE_FOLDER_PARENT_PATH
+ File
.separator
+ TRACE_FOLDER
+ File
.separator
+ TRACE_NAME
;
455 expectedSourceLocation
= URI_FILE_SCHEME
+ URI_DEVICE_SEPARATOR
+ new Path(new File(sourcePath
).getCanonicalPath()) + URI_SEPARATOR
;
456 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH
);
457 selectFolder(new String
[] {TRACE_FOLDER_PARENT_NAME
, TRACE_FOLDER
});
460 setOptions(options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
462 if (!defaultExperiment
) {
463 experimentName
= verifyExperimentNameHandling(experimentName
);
465 checkFinishButton(true);
469 IPath expectedElementPath
= new Path(TRACE_NAME
);
470 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
471 expectedElementPath
= new Path(TRACE_FOLDER
).append(expectedElementPath
);
474 checkOptions(options
, expectedSourceLocation
, expectedElementPath
, experimentName
);
475 TmfEventsEditor tmfEd
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
480 fBot
.closeAllEditors();
482 SWTBotUtils
.clearExperimentFolder(fBot
, TRACE_PROJECT_NAME
);
483 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
486 private void testImportAndExtractArchives(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
487 String expectedSourceLocation
;
488 IPath expectedElementPath
;
489 String testArchivePath
= null;
491 testArchivePath
= createNestedArchive();
493 selectImportFromArchive(testArchivePath
);
494 selectFile(ARCHIVE_FILE_NAME
, ARCHIVE_ROOT_ELEMENT_NAME
, TRACE_PROJECT_NAME
, TRACE_FOLDER_PARENT_NAME
);
496 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
497 + URI_SEPARATOR
+ TRACE_FOLDER
+ URI_SEPARATOR
+ TRACE_NAME
+ URI_SEPARATOR
;
498 expectedElementPath
= new Path(TRACE_PROJECT_NAME
).append(TRACE_FOLDER_PARENT_NAME
).append(ARCHIVE_FILE_NAME
).append(TRACE_FOLDER
).append(TRACE_NAME
);
501 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH
);
502 selectFile(ARCHIVE_FILE_NAME
, TRACE_FOLDER_PARENT_NAME
);
503 expectedElementPath
= new Path(ARCHIVE_FILE_NAME
).append(TRACE_FOLDER
).append(TRACE_NAME
);
504 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
;
507 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) == 0) {
508 expectedElementPath
= new Path(TRACE_NAME
);
511 setOptions(options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
513 // Archives should never be imported as links
514 int expectedOptions
= options
& ~ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
515 checkOptions(expectedOptions
, expectedSourceLocation
, expectedElementPath
);
517 TmfEventsEditor editor
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
522 SWTBotUtils
.clearExperimentFolder(fBot
, TRACE_PROJECT_NAME
);
524 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
525 if (testArchivePath
!= null) {
526 Files
.delete(Paths
.get(testArchivePath
));
531 * Create a temporary archive containing a nested archive. For example,
532 * testtraces.zip/synctraces.tar.gz can be used to test a nested archive.
534 private static String
createNestedArchive() throws IOException
, CoreException
, URISyntaxException
{
535 // Link to the test traces folder. We use a link so that we can safely
536 // delete the entire project when we are done.
537 IProject project
= getProjectResource();
538 String canonicalPath
= new File(TRACE_FOLDER_PARENT_PATH
).getCanonicalPath();
539 IFolder folder
= project
.getFolder(TRACE_FOLDER_PARENT_NAME
);
540 folder
.createLink(new Path(canonicalPath
), IResource
.REPLACE
, null);
541 IFile file
= folder
.getFile(ARCHIVE_FILE_NAME
);
542 String archivePath
= createArchive(file
);
543 folder
.delete(true, null);
548 * Create the empty archive from an empty folder
550 private static String
createEmptyArchive() throws CoreException
, URISyntaxException
{
551 IFolder tempEmptyDirectory
= createEmptyDirectory();
552 String archivePath
= createArchive(tempEmptyDirectory
);
553 tempEmptyDirectory
.delete(true, null);
557 private static IFolder
createEmptyDirectory() throws CoreException
{
558 IProject project
= getProjectResource();
559 IFolder folder
= project
.getFolder(EMPTY_ARCHIVE_FOLDER
);
560 folder
.create(true, true, null);
564 private static void createEmptyFile(IFolder folder
) throws CoreException
{
566 IFile file
= folder
.getFile(EMPTY_FILE_NAME
);
567 file
.create(new ByteArrayInputStream(new byte[0]), true, null);
571 * Create a temporary archive from the specified resource.
573 private static String
createArchive(IResource sourceResource
) throws URISyntaxException
{
574 IPath exportedPath
= sourceResource
.getFullPath();
576 SWTBotTreeItem traceFilesProject
= SWTBotUtils
.selectProject(fBot
, TRACE_PROJECT_NAME
);
577 traceFilesProject
.contextMenu("Export...").click();
579 fBot
.waitUntil(Conditions
.shellIsActive("Export"));
580 SWTBotShell activeShell
= fBot
.activeShell();
581 SWTBotTree exportWizardsTree
= fBot
.tree();
582 SWTBotTreeItem treeItem
= SWTBotUtils
.getTreeItem(fBot
, exportWizardsTree
, "General", "Archive File");
584 fBot
.button("Next >").click();
585 fBot
.button("&Deselect All").click();
587 String resolveLinkedResLabel
= "Resolve and export linked resources";
588 fBot
.waitUntil(Conditions
.waitForWidget(withMnemonic(resolveLinkedResLabel
)), 100);
589 fBot
.checkBox(resolveLinkedResLabel
).select();
590 } catch (TimeoutException e
) {
591 // Ignore, doesn't exist pre-4.6M5
594 if (sourceResource
instanceof IFile
) {
595 String
[] folderPath
= exportedPath
.removeLastSegments(1).segments();
596 String fileName
= exportedPath
.lastSegment();
597 selectFile(fileName
, folderPath
);
599 selectFolder(exportedPath
.segments());
602 String workspacePath
= URIUtil
.toFile(URIUtil
.fromString(System
.getProperty("osgi.instance.area"))).getAbsolutePath();
603 final String archiveDestinationPath
= workspacePath
+ File
.separator
+ TRACE_PROJECT_NAME
+ File
.separator
+ GENERATED_ARCHIVE_NAME
;
604 fBot
.comboBox().setText(archiveDestinationPath
);
605 fBot
.button("&Finish").click();
606 fBot
.waitUntil(Conditions
.shellCloses(activeShell
));
607 return archiveDestinationPath
;
610 private void testViews(TmfEventsEditor editor
) {
611 testHistogramView(getViewPart("Histogram"), editor
);
612 testPropertyView(getViewPart("Properties"));
613 testStatisticsView(getViewPart("Statistics"));
616 private static void openImportWizard() {
617 fWizard
= new ImportTraceWizard();
619 UIThreadRunnable
.asyncExec(new VoidResult() {
622 final IWorkbench workbench
= PlatformUI
.getWorkbench();
623 // Fire the Import Trace Wizard
624 if (workbench
!= null) {
625 final IWorkbenchWindow activeWorkbenchWindow
= workbench
.getActiveWorkbenchWindow();
626 Shell shell
= activeWorkbenchWindow
.getShell();
627 assertNotNull(shell
);
628 ((ImportTraceWizard
) fWizard
).init(PlatformUI
.getWorkbench(), StructuredSelection
.EMPTY
);
629 WizardDialog dialog
= new WizardDialog(shell
, fWizard
);
635 fBot
.waitUntil(ConditionHelpers
.isWizardReady(fWizard
));
638 private static void selectImportFromDirectory(String directoryPath
) {
639 SWTBotRadio button
= fBot
.radio("Select roo&t directory:");
642 SWTBotCombo sourceCombo
= fBot
.comboBox();
643 File traceFolderParent
= new File(directoryPath
);
644 sourceCombo
.setText(traceFolderParent
.getAbsolutePath());
646 SWTBotText text
= fBot
.text();
650 private static void selectImportFromArchive(String archivePath
) {
651 SWTBotRadio button
= fBot
.radio("Select &archive file:");
654 SWTBotCombo sourceCombo
= fBot
.comboBox(1);
656 sourceCombo
.setText(new File(archivePath
).getAbsolutePath());
658 SWTBotText text
= fBot
.text();
662 private static void selectFolder(String
... treePath
) {
663 selectFolder(true, treePath
);
666 private static void selectFolder(boolean check
, String
... treePath
) {
667 SWTBotTree tree
= fBot
.tree();
668 fBot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
669 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(fBot
, tree
, treePath
);
677 private static void selectFile(String fileName
, String
... folderTreePath
) {
678 selectFolder(false, folderTreePath
);
680 SWTBotTable fileTable
= fBot
.table();
681 fBot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
682 fBot
.waitUntil(ConditionHelpers
.isTableItemAvailable(fileName
, fileTable
));
683 SWTBotTableItem tableItem
= fileTable
.getTableItem(fileName
);
687 private static void setOptions(int optionFlags
, String traceTypeName
) {
688 SWTBotCheckBox checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_CreateLinksInWorkspace
);
689 if (checkBox
.isEnabled()) {
690 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0) {
697 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_PreserveFolderStructure
);
698 if ((optionFlags
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
704 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_ImportUnrecognized
);
705 if ((optionFlags
& ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
) != 0) {
711 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_OverwriteExistingTrace
);
712 if ((optionFlags
& ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
) != 0) {
718 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_CreateExperiment
);
719 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
) != 0) {
725 SWTBotCombo comboBox
= fBot
.comboBoxWithLabel(Messages
.ImportTraceWizard_TraceType
);
726 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
727 comboBox
.setSelection(traceTypeName
);
729 comboBox
.setSelection(ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
733 private static void checkOptions(int optionFlags
, String expectedSourceLocation
, IPath expectedElementPath
) throws CoreException
{
734 checkOptions(optionFlags
, expectedSourceLocation
, expectedElementPath
, null);
737 private static void checkOptions(int optionFlags
, String expectedSourceLocation
, IPath expectedElementPath
, String experimentName
) throws CoreException
{
738 IProject project
= getProjectResource();
739 assertTrue(project
.exists());
740 TmfProjectElement tmfProject
= TmfProjectRegistry
.getProject(project
, true);
741 assertNotNull(tmfProject
);
742 TmfTraceFolder tracesFolder
= tmfProject
.getTracesFolder();
743 assertNotNull(tracesFolder
);
744 List
<TmfTraceElement
> traces
= tracesFolder
.getTraces();
745 assertFalse(traces
.isEmpty());
746 Collections
.sort(traces
, new Comparator
<TmfTraceElement
>() {
748 public int compare(TmfTraceElement arg0
, TmfTraceElement arg1
) {
749 return arg0
.getElementPath().compareTo(arg1
.getElementPath());
753 TmfTraceElement tmfTraceElement
= traces
.get(0);
754 IResource traceResource
= tmfTraceElement
.getResource();
756 assertEquals((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0, traceResource
.isLinked());
758 // i.e. /Tracing/Traces
759 IPath expectedPath
= Path
.ROOT
.append(new Path(TRACE_PROJECT_NAME
)).append(TmfTracesFolder
.TRACES_FOLDER_NAME
).append(expectedElementPath
);
760 assertEquals(expectedPath
, traceResource
.getFullPath());
762 String sourceLocation
= traceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
763 assertNotNull(sourceLocation
);
764 assertEquals(expectedSourceLocation
, sourceLocation
);
766 TmfExperimentFolder expFolder
= tmfProject
.getExperimentsFolder();
767 assertNotNull(expFolder
);
768 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
) != 0) {
769 if (experimentName
!= null) {
770 TmfExperimentElement expElement
= expFolder
.getExperiment(experimentName
);
771 assertNotNull(expElement
);
772 assertEquals(2, expElement
.getTraces().size());
775 assertTrue(expFolder
.getExperiments().size() == 0);
779 private static IProject
getProjectResource() {
780 return ResourcesPlugin
.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME
);
783 private @NonNull String
verifyExperimentNameHandling(String aExperimentName
) {
784 String experimentName
= aExperimentName
;
786 // experiment already exists
787 checkFinishButton(false);
789 SWTBotText expText
= fBot
.textInGroup("Options");
791 // Invalid experiment name (only whitespaces)
792 expText
.setText(String
.valueOf(' '));
793 checkFinishButton(false);
795 // Invalid experiment name
796 expText
.setText(String
.valueOf('/'));
797 checkFinishButton(false);
799 // Set valid experiment name
800 experimentName
+= '_';
801 expText
.setText(experimentName
);
802 return experimentName
;