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
.junit
.Assert
.assertEquals
;
17 import static org
.junit
.Assert
.assertFalse
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertTrue
;
21 import java
.io
.ByteArrayInputStream
;
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
;
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
;
78 * SWTBot Smoke test using ImportTraceWizard.
80 * @author Bernd Hufmann
82 @RunWith(SWTBotJunit4ClassRunner
.class)
83 public class StandardImportAndReadSmokeTest
extends AbstractImportAndReadSmokeTest
{
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";
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
: "";
101 /** Test Class setup */
103 public static void beforeClass() {
104 createProject(TRACE_PROJECT_NAME
);
107 /** Test Class tear down */
109 public static void afterClass() {
110 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
114 * Test import from directory
120 public void testImportFromDirectory() throws Exception
{
121 testImport(0, false, false);
125 * Test import from directory, create links
131 public void testImportFromDirectoryLinks() throws Exception
{
132 testImport(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
, false, false);
136 * Test import from directory, preserve folder structure
142 public void testImportFromDirectoryPreserveFolder() throws Exception
{
143 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, false);
147 * Test import from directory, create links, preserve folder structure
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);
159 * Test import from directory, overwrite all
165 public void testImportFromDirectoryOverwrite() throws Exception
{
166 testImport(0, false, false);
167 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
171 * Test import from archive
177 public void testImportFromArchive() throws Exception
{
178 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, true, true);
182 * Test import from directory, preserve folder structure
183 * @throws Exception on error
186 public void testImportFromArchivePreserveFolder() throws Exception
{
187 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
191 * Test import from directory, overwrite all
197 public void testImportFromArchiveOverwrite() throws Exception
{
198 testImport(0, false, true);
199 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
203 * Test import from directory containing archives
209 public void testExtractArchivesFromDirectory() throws Exception
{
210 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
214 * Test import from directory containing archives, create links
215 * @throws Exception on error
218 public void testExtractArchivesFromDirectoryLinks() throws Exception
{
219 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
223 * Test import from directory containing archives, create links, preserve folder structure
224 * @throws Exception on error
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);
232 * Test import from archive containing archives
238 public void testExtractArchivesFromArchive() throws Exception
{
239 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
243 * Test import from archive containing archives, preserve folder structure
249 public void testExtractArchivesFromArchivePreserveFolder() throws Exception
{
250 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
254 * Test import from an empty archive. This should not import anything.
260 public void testEmptyArchive() throws Exception
{
261 String testArchivePath
= createEmptyArchive();
264 selectImportFromArchive(testArchivePath
);
265 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
266 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
271 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
272 Files
.delete(Paths
.get(testArchivePath
));
276 * Test import from an empty directory. This should not import anything.
282 public void testEmptyDirectory() throws Exception
{
283 IFolder emptyDirectory
= createEmptyDirectory();
284 String testDirectoryPath
= emptyDirectory
.getLocation().toOSString();
287 selectImportFromDirectory(testDirectoryPath
);
288 selectFolder(EMPTY_ARCHIVE_FOLDER
);
289 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
294 Files
.delete(Paths
.get(testDirectoryPath
));
295 emptyDirectory
.delete(true, null);
296 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
300 * Test import from an directory with an empty file. This should not import anything.
306 public void testEmptyFile() throws Exception
{
307 IFolder folder
= createEmptyDirectory();
308 createEmptyFile(folder
);
309 String testDirectoryPath
= folder
.getLocation().toOSString();
311 selectImportFromDirectory(testDirectoryPath
);
312 selectFile(EMPTY_FILE_NAME
, EMPTY_ARCHIVE_FOLDER
);
313 setOptions(ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
318 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
319 folder
.delete(true, null);
323 * Test import from a directory containing an empty archive. This should not import anything.
329 public void testDirectoryWithEmptyArchive() throws Exception
{
330 String testArchivePath
= createEmptyArchive();
333 selectImportFromDirectory(getProjectResource().getLocation().toOSString());
334 selectFile(GENERATED_ARCHIVE_NAME
, TRACE_PROJECT_NAME
);
335 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
340 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
341 Files
.delete(Paths
.get(testArchivePath
));
345 * Test import from a nested empty archive. This should not import anything.
351 public void testNestedEmptyArchive() throws Exception
{
352 IProject project
= getProjectResource();
354 // Create the empty archive from an empty folder
355 String testArchivePath
= createEmptyArchive();
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
);
366 createArchive(renamedArchiveFile
);
367 renamedArchiveFile
.delete(true, null);
370 selectImportFromArchive(testArchivePath
);
371 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
372 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
377 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
378 Files
.delete(Paths
.get(testArchivePath
));
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());
390 private void testImport(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
391 String expectedSourceLocation
= null;
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());
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
});
406 setOptions(options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
409 IPath expectedElementPath
= new Path(TRACE_NAME
);
410 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
411 expectedElementPath
= new Path(TRACE_FOLDER
).append(expectedElementPath
);
414 checkOptions(options
, expectedSourceLocation
, expectedElementPath
);
415 TmfEventsEditor tmfEd
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
420 fBot
.closeAllEditors();
422 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
425 private void testImportAndExtractArchives(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
426 String expectedSourceLocation
;
427 IPath expectedElementPath
;
428 String testArchivePath
= null;
430 testArchivePath
= createNestedArchive();
432 selectImportFromArchive(testArchivePath
);
433 selectFile(ARCHIVE_FILE_NAME
, ARCHIVE_ROOT_ELEMENT_NAME
, TRACE_PROJECT_NAME
, TRACE_FOLDER_PARENT_NAME
);
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
);
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
;
446 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) == 0) {
447 expectedElementPath
= new Path(TRACE_NAME
);
450 setOptions(options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
452 // Archives should never be imported as links
453 int expectedOptions
= options
& ~ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
454 checkOptions(expectedOptions
, expectedSourceLocation
, expectedElementPath
);
456 TmfEventsEditor editor
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
461 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
462 if (testArchivePath
!= null) {
463 Files
.delete(Paths
.get(testArchivePath
));
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.
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);
485 * Create the empty archive from an empty folder
487 private static String
createEmptyArchive() throws CoreException
, URISyntaxException
{
488 IFolder tempEmptyDirectory
= createEmptyDirectory();
489 String archivePath
= createArchive(tempEmptyDirectory
);
490 tempEmptyDirectory
.delete(true, null);
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);
501 private static void createEmptyFile(IFolder folder
) throws CoreException
{
503 IFile file
= folder
.getFile(EMPTY_FILE_NAME
);
504 file
.create(new ByteArrayInputStream(new byte[0]), true, null);
508 * Create a temporary archive from the specified resource.
510 private static String
createArchive(IResource sourceResource
) throws URISyntaxException
{
511 IPath exportedPath
= sourceResource
.getFullPath();
513 SWTBotTreeItem traceFilesProject
= SWTBotUtils
.selectProject(fBot
, TRACE_PROJECT_NAME
);
514 traceFilesProject
.contextMenu("Export...").click();
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");
521 fBot
.button("Next >").click();
522 fBot
.button("&Deselect All").click();
524 fBot
.checkBox("Resolve and export linked resources").select();
525 } catch (WidgetNotFoundException e
) {
526 // Ignore, doesn't exist pre-4.6M5
529 if (sourceResource
instanceof IFile
) {
530 String
[] folderPath
= exportedPath
.removeLastSegments(1).segments();
531 String fileName
= exportedPath
.lastSegment();
532 selectFile(fileName
, folderPath
);
534 selectFolder(exportedPath
.segments());
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
;
545 private void testViews(TmfEventsEditor editor
) {
546 testHistogramView(getViewPart("Histogram"), editor
);
547 testPropertyView(getViewPart("Properties"));
548 testStatisticsView(getViewPart("Statistics"));
551 private static void openImportWizard() {
552 fWizard
= new ImportTraceWizard();
554 UIThreadRunnable
.asyncExec(new VoidResult() {
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
);
570 fBot
.waitUntil(ConditionHelpers
.isWizardReady(fWizard
));
573 private static void selectImportFromDirectory(String directoryPath
) {
574 SWTBotRadio button
= fBot
.radio("Select roo&t directory:");
577 SWTBotCombo sourceCombo
= fBot
.comboBox();
578 File traceFolderParent
= new File(directoryPath
);
579 sourceCombo
.setText(traceFolderParent
.getAbsolutePath());
581 SWTBotText text
= fBot
.text();
585 private static void selectImportFromArchive(String archivePath
) {
586 SWTBotRadio button
= fBot
.radio("Select &archive file:");
589 SWTBotCombo sourceCombo
= fBot
.comboBox(1);
591 sourceCombo
.setText(new File(archivePath
).getAbsolutePath());
593 SWTBotText text
= fBot
.text();
597 private static void selectFolder(String
... treePath
) {
598 selectFolder(true, treePath
);
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
);
612 private static void selectFile(String fileName
, String
... folderTreePath
) {
613 selectFolder(false, folderTreePath
);
615 SWTBotTable fileTable
= fBot
.table();
616 fBot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
617 fBot
.waitUntil(ConditionHelpers
.isTableItemAvailable(fileName
, fileTable
));
618 SWTBotTableItem tableItem
= fileTable
.getTableItem(fileName
);
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) {
632 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_PreserveFolderStructure
);
633 if ((optionFlags
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
639 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_ImportUnrecognized
);
640 if ((optionFlags
& ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
) != 0) {
646 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_OverwriteExistingTrace
);
647 if ((optionFlags
& ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
) != 0) {
653 SWTBotCombo comboBox
= fBot
.comboBoxWithLabel(Messages
.ImportTraceWizard_TraceType
);
654 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
655 comboBox
.setSelection(traceTypeName
);
657 comboBox
.setSelection(ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
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
>() {
672 public int compare(TmfTraceElement arg0
, TmfTraceElement arg1
) {
673 return arg0
.getElementPath().compareTo(arg1
.getElementPath());
677 TmfTraceElement tmfTraceElement
= traces
.get(0);
678 IResource traceResource
= tmfTraceElement
.getResource();
680 assertEquals((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0, traceResource
.isLinked());
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());
686 String sourceLocation
= traceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
687 assertNotNull(sourceLocation
);
688 assertEquals(expectedSourceLocation
, sourceLocation
);
691 private static IProject
getProjectResource() {
692 return ResourcesPlugin
.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME
);