Fix importing an archive containing colons (:) in the names on Windows
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / StandardImportAndReadSmokeTest.java
index 38ec7184ae170cfee7787c7df7727b7ef0b20f29..77916f0d606aef5744f3de869ba0a183f42d9cc0 100644 (file)
@@ -13,6 +13,8 @@
 
 package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
 
+import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic;
+import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
@@ -22,6 +24,8 @@ import java.io.ByteArrayInputStream;
 import java.io.File;
 import java.io.IOException;
 import java.net.URISyntaxException;
+import java.nio.file.Files;
+import java.nio.file.Paths;
 import java.util.Collections;
 import java.util.Comparator;
 import java.util.List;
@@ -35,6 +39,7 @@ import org.eclipse.core.runtime.CoreException;
 import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.core.runtime.URIUtil;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.swt.widgets.Shell;
@@ -43,19 +48,19 @@ import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
 import org.eclipse.swtbot.swt.finder.results.VoidResult;
 import org.eclipse.swtbot.swt.finder.waits.Conditions;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
-import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation;
 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement;
+import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
@@ -66,6 +71,8 @@ import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
 import org.eclipse.ui.IWorkbench;
 import org.eclipse.ui.IWorkbenchWindow;
 import org.eclipse.ui.PlatformUI;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 import org.junit.Test;
 import org.junit.runner.RunWith;
 
@@ -93,6 +100,18 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
     private static final boolean IS_WIN32 = System.getProperty("os.name").startsWith("Windows");  //$NON-NLS-1$//$NON-NLS-2$
     private static final String URI_DEVICE_SEPARATOR = IS_WIN32 ? URI_SEPARATOR : "";
 
+    /** Test Class setup */
+    @BeforeClass
+    public static void beforeClass() {
+        createProject(TRACE_PROJECT_NAME);
+    }
+
+    /** Test Class tear down */
+    @AfterClass
+    public static void afterClass() {
+        SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
+    }
+
     /**
      * Test import from directory
      *
@@ -115,6 +134,28 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false);
     }
 
+    /**
+     * Test import from directory, create experiment
+     *
+     * @throws Exception
+     *             on error
+     */
+    @Test
+    public void testImportWithExperiment() throws Exception {
+        testImport(ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, false);
+    }
+
+    /**
+     * Test import from directory, create experiment (validate experiment name)
+     *
+     * @throws Exception
+     *             on error
+     */
+    @Test
+    public void testImportWithExperimentValidation() throws Exception {
+        testImport(ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, false, false, true, ImportConfirmation.CONTINUE);
+    }
+
     /**
      * Test import from directory, preserve folder structure
      *
@@ -146,10 +187,34 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testImportFromDirectoryOverwrite() throws Exception {
-        testImport(0, false, false);
+        testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
         testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
     }
 
+    /**
+     * Test import from directory, overwrite all
+     *
+     * @throws Exception
+     *             on error
+     */
+    @Test
+    public void testImportFromDirectoryOverwriteRenameAll() throws Exception {
+        testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
+        testImport(0, false, false, true, true, ImportConfirmation.RENAME_ALL);
+    }
+
+    /**
+     * Test import from directory, overwrite all
+     *
+     * @throws Exception
+     *             on error
+     */
+    @Test
+    public void testImportFromDirectoryOverwriteOverwriteAll() throws Exception {
+        testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
+        testImport(0, false, false, true, true, ImportConfirmation.OVERWRITE_ALL);
+    }
+
     /**
      * Test import from archive
      *
@@ -161,6 +226,17 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true);
     }
 
+    /**
+     * Test import from archive, create Experiment
+     *
+     * @throws Exception
+     *             on error
+     */
+    @Test
+    public void testImportFromArchiveWithExperiment() throws Exception {
+        testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE | ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, true);
+    }
+
     /**
      * Test import from directory, preserve folder structure
      * @throws Exception on error
@@ -178,7 +254,7 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testImportFromArchiveOverwrite() throws Exception {
-        testImport(0, false, true);
+        testImport(0, false, true, true, false, ImportConfirmation.CONTINUE);
         testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
     }
 
@@ -190,7 +266,7 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testExtractArchivesFromDirectory() throws Exception {
-        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false);
+        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
     }
 
     /**
@@ -199,7 +275,7 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testExtractArchivesFromDirectoryLinks() throws Exception {
-        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false);
+        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
     }
 
     /**
@@ -208,7 +284,7 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception {
-        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false);
+        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, false);
     }
 
     /**
@@ -219,7 +295,7 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testExtractArchivesFromArchive() throws Exception {
-        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, true);
+        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
     }
 
     /**
@@ -230,7 +306,7 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testExtractArchivesFromArchivePreserveFolder() throws Exception {
-        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true);
+        testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
     }
 
     /**
@@ -241,18 +317,18 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testEmptyArchive() throws Exception {
-        createProject();
         String testArchivePath = createEmptyArchive();
 
         openImportWizard();
-        selectImportFromArchive(testArchivePath);
+        SWTBotImportWizardUtils.selectImportFromArchive(fBot, testArchivePath);
         selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
-        setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
+        SWTBotImportWizardUtils.setOptions(fBot, 0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
         importFinish();
 
         assertNoTraces();
 
-        SWTBotUtils.deleteProject(getProjectName(), fBot);
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+        Files.delete(Paths.get(testArchivePath));
     }
 
     /**
@@ -263,18 +339,20 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testEmptyDirectory() throws Exception {
-        createProject();
-        String testDirectoryPath = createEmptyDirectory().getLocation().toOSString();
+        IFolder emptyDirectory = createEmptyDirectory();
+        String testDirectoryPath = emptyDirectory.getLocation().toOSString();
 
         openImportWizard();
-        selectImportFromDirectory(testDirectoryPath);
+        SWTBotImportWizardUtils.selectImportFromDirectory(fBot, testDirectoryPath);
         selectFolder(EMPTY_ARCHIVE_FOLDER);
-        setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
+        SWTBotImportWizardUtils.setOptions(fBot, 0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
         importFinish();
 
         assertNoTraces();
 
-        SWTBotUtils.deleteProject(getProjectName(), fBot);
+        Files.delete(Paths.get(testDirectoryPath));
+        emptyDirectory.delete(true, null);
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
     }
 
     /**
@@ -285,19 +363,19 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testEmptyFile() throws Exception {
-        createProject();
         IFolder folder = createEmptyDirectory();
         createEmptyFile(folder);
         String testDirectoryPath = folder.getLocation().toOSString();
         openImportWizard();
-        selectImportFromDirectory(testDirectoryPath);
-        selectFile(EMPTY_FILE_NAME, EMPTY_ARCHIVE_FOLDER);
-        setOptions(ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
+        SWTBotImportWizardUtils.selectImportFromDirectory(fBot, testDirectoryPath);
+        SWTBotImportWizardUtils.selectFile(fBot, EMPTY_FILE_NAME, EMPTY_ARCHIVE_FOLDER);
+        SWTBotImportWizardUtils.setOptions(fBot, ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
         importFinish();
 
         assertNoTraces();
 
-        SWTBotUtils.deleteProject(getProjectName(), fBot);
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+        folder.delete(true, null);
     }
 
     /**
@@ -308,18 +386,18 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testDirectoryWithEmptyArchive() throws Exception {
-        createProject();
-        createEmptyArchive();
+        String testArchivePath = createEmptyArchive();
 
         openImportWizard();
-        selectImportFromDirectory(getProjectResource().getLocation().toOSString());
-        selectFile(GENERATED_ARCHIVE_NAME, getProjectName());
-        setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
+        SWTBotImportWizardUtils.selectImportFromDirectory(fBot, getProjectResource().getLocation().toOSString());
+        SWTBotImportWizardUtils.selectFile(fBot, GENERATED_ARCHIVE_NAME, TRACE_PROJECT_NAME);
+        SWTBotImportWizardUtils.setOptions(fBot, 0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
         importFinish();
 
         assertNoTraces();
 
-        SWTBotUtils.deleteProject(getProjectName(), fBot);
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+        Files.delete(Paths.get(testArchivePath));
     }
 
     /**
@@ -330,7 +408,6 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testNestedEmptyArchive() throws Exception {
-        createProject();
         IProject project = getProjectResource();
 
         // Create the empty archive from an empty folder
@@ -346,19 +423,49 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         IFile renamedArchiveFile = archiveFile.getWorkspace().getRoot().getFile(dest);
 
         createArchive(renamedArchiveFile);
+        renamedArchiveFile.delete(true, null);
 
         openImportWizard();
-        selectImportFromArchive(testArchivePath);
+        SWTBotImportWizardUtils.selectImportFromArchive(fBot, testArchivePath);
         selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
-        setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
+        SWTBotImportWizardUtils.setOptions(fBot, 0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
         importFinish();
 
         assertNoTraces();
 
-        SWTBotUtils.deleteProject(getProjectName(), fBot);
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+        Files.delete(Paths.get(testArchivePath));
+    }
+
+    /**
+     * Test importing an archive with colons in the names. Those are invalid
+     * characters in Windows paths so this test makes sure that they are
+     * replaced properly with '_'
+     */
+    @Test
+    public void testArchiveWithColons() {
+        openImportWizard();
+        IPath absolutePath = Activator.getAbsolutePath(new Path("testfiles/testcolon.zip"));
+
+        SWTBotImportWizardUtils.selectImportFromArchive(fBot, absolutePath.toOSString());
+        String subFolderName = IS_WIN32 ? "folder_colon" : "folder:colon";
+        selectFolder(ARCHIVE_ROOT_ELEMENT_NAME, subFolderName);
+        SWTBotImportWizardUtils.setOptions(fBot, 0, "Test trace : XML Trace Stub");
+        importFinish();
+
+        TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
+        assertNotNull(tmfProject);
+        TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
+        assertNotNull(tracesFolder);
+        List<TmfTraceElement> traces = tracesFolder.getTraces();
+        assertTrue(traces.size() == 1);
+        String traceName = IS_WIN32 ? "trace_colon.xml" : "trace:colon.xml";
+        assertEquals(traceName, traces.get(0).getName());
+
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
     }
 
-    private void assertNoTraces() {
+    private static void assertNoTraces() {
         TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
         assertNotNull(tmfProject);
         TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
@@ -368,59 +475,88 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
     }
 
     private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception {
-        createProject();
+        testImport(options, testViews, fromArchive, true, true, ImportConfirmation.CONTINUE);
+    }
+
+    private void testImport(int options, boolean testViews, boolean fromArchive, boolean defaultExperiment, boolean clearTraces, ImportConfirmation confirmationMode) throws Exception {
         String expectedSourceLocation = null;
+
+        @NonNull String experimentName;
+        if (fromArchive) {
+            experimentName = checkNotNull(new Path(ARCHIVE_FILE_NAME).lastSegment());
+        } else {
+            experimentName = checkNotNull(new Path(TRACE_FOLDER_PARENT_PATH).lastSegment());
+        }
+
+        if (!defaultExperiment) {
+            SWTBotUtils.createExperiment(fBot, TRACE_PROJECT_NAME, experimentName);
+        }
+
         openImportWizard();
         if (fromArchive) {
             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;
-            selectImportFromArchive(TRACE_ARCHIVE_PATH);
+            SWTBotImportWizardUtils.selectImportFromArchive(fBot, TRACE_ARCHIVE_PATH);
             selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
             SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
             assertFalse(checkBox.isEnabled());
         } else {
             String sourcePath = TRACE_FOLDER_PARENT_PATH + File.separator + TRACE_FOLDER + File.separator + TRACE_NAME;
             expectedSourceLocation = URI_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(sourcePath).getCanonicalPath()) + URI_SEPARATOR;
-            selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
+            SWTBotImportWizardUtils.selectImportFromDirectory(fBot, TRACE_FOLDER_PARENT_PATH);
             selectFolder(new String [] {TRACE_FOLDER_PARENT_NAME, TRACE_FOLDER });
         }
 
-        setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
-        importFinish();
+        SWTBotImportWizardUtils.setOptions(fBot, options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
+
+        if (!defaultExperiment) {
+            experimentName = verifyExperimentNameHandling(experimentName);
+        }
+        checkFinishButton(true);
+
+        importFinish(confirmationMode);
 
         IPath expectedElementPath = new Path(TRACE_NAME);
         if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
             expectedElementPath = new Path(TRACE_FOLDER).append(expectedElementPath);
         }
 
-        checkOptions(options, expectedSourceLocation, expectedElementPath);
-        TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, getProjectName(), expectedElementPath);
+        if (confirmationMode == ImportConfirmation.RENAME_ALL) {
+            IPath expectedElementPathRenamed = new Path(TRACE_NAME + "(2)");
+            checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName, expectedElementPathRenamed);
+        } else {
+            checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName, null);
+        }
+
+        TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
         if (testViews) {
             testViews(tmfEd);
         }
 
         fBot.closeAllEditors();
 
-        SWTBotUtils.deleteProject(getProjectName(), fBot);
+        SWTBotUtils.clearExperimentFolder(fBot, TRACE_PROJECT_NAME);
+        if (clearTraces) {
+            SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+        }
     }
 
-    private void testImportAndExtractArchives(int options, boolean fromArchive) throws Exception {
-        createProject();
-
+    private void testImportAndExtractArchives(int options, boolean testViews, boolean fromArchive) throws Exception {
         String expectedSourceLocation;
         IPath expectedElementPath;
+        String testArchivePath = null;
         if (fromArchive) {
-            String testArchivePath = createNestedArchive();
+            testArchivePath = createNestedArchive();
             openImportWizard();
-            selectImportFromArchive(testArchivePath);
-            selectFile(ARCHIVE_FILE_NAME, ARCHIVE_ROOT_ELEMENT_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME);
+            SWTBotImportWizardUtils.selectImportFromArchive(fBot, testArchivePath);
+            SWTBotImportWizardUtils.selectFile(fBot, ARCHIVE_FILE_NAME, ARCHIVE_ROOT_ELEMENT_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME);
 
             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
                     + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
             expectedElementPath = new Path(TRACE_PROJECT_NAME).append(TRACE_FOLDER_PARENT_NAME).append(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
         } else {
             openImportWizard();
-            selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
-            selectFile(ARCHIVE_FILE_NAME, TRACE_FOLDER_PARENT_NAME);
+            SWTBotImportWizardUtils.selectImportFromDirectory(fBot, TRACE_FOLDER_PARENT_PATH);
+            SWTBotImportWizardUtils.selectFile(fBot, ARCHIVE_FILE_NAME, TRACE_FOLDER_PARENT_NAME);
             expectedElementPath = new Path(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
             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;
         }
@@ -429,23 +565,30 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
             expectedElementPath = new Path(TRACE_NAME);
         }
 
-        setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
+        SWTBotImportWizardUtils.setOptions(fBot, options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
         importFinish();
         // Archives should never be imported as links
         int expectedOptions = options & ~ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
         checkOptions(expectedOptions, expectedSourceLocation, expectedElementPath);
 
         TmfEventsEditor editor = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
-        testViews(editor);
+        if (testViews) {
+            testViews(editor);
+        }
 
-        SWTBotUtils.deleteProject(getProjectName(), fBot);
+        SWTBotUtils.clearExperimentFolder(fBot, TRACE_PROJECT_NAME);
+
+        SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
+        if (testArchivePath != null) {
+            Files.delete(Paths.get(testArchivePath));
+        }
     }
 
     /**
      * Create a temporary archive containing a nested archive. For example,
      * testtraces.zip/synctraces.tar.gz can be used to test a nested archive.
      */
-    private String createNestedArchive() throws IOException, CoreException, URISyntaxException {
+    private static String createNestedArchive() throws IOException, CoreException, URISyntaxException {
         // Link to the test traces folder. We use a link so that we can safely
         // delete the entire project when we are done.
         IProject project = getProjectResource();
@@ -453,17 +596,22 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         IFolder folder = project.getFolder(TRACE_FOLDER_PARENT_NAME);
         folder.createLink(new Path(canonicalPath), IResource.REPLACE, null);
         IFile file = folder.getFile(ARCHIVE_FILE_NAME);
-        return createArchive(file);
+        String archivePath = createArchive(file);
+        folder.delete(true, null);
+        return archivePath;
     }
 
     /**
      * Create the empty archive from an empty folder
      */
-    private String createEmptyArchive() throws CoreException, URISyntaxException {
-        return createArchive(createEmptyDirectory());
+    private static String createEmptyArchive() throws CoreException, URISyntaxException {
+        IFolder tempEmptyDirectory = createEmptyDirectory();
+        String archivePath = createArchive(tempEmptyDirectory);
+        tempEmptyDirectory.delete(true, null);
+        return archivePath;
     }
 
-    private IFolder createEmptyDirectory() throws CoreException {
+    private static IFolder createEmptyDirectory() throws CoreException {
         IProject project = getProjectResource();
         IFolder folder = project.getFolder(EMPTY_ARCHIVE_FOLDER);
         folder.create(true, true, null);
@@ -492,11 +640,18 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         treeItem.select();
         fBot.button("Next >").click();
         fBot.button("&Deselect All").click();
+        try {
+            String resolveLinkedResLabel = "Resolve and export linked resources";
+            fBot.waitUntil(Conditions.waitForWidget(withMnemonic(resolveLinkedResLabel)), 100);
+            fBot.checkBox(resolveLinkedResLabel).select();
+        } catch (TimeoutException e) {
+            // Ignore, doesn't exist pre-4.6M5
+        }
 
         if (sourceResource instanceof IFile) {
             String[] folderPath = exportedPath.removeLastSegments(1).segments();
             String fileName = exportedPath.lastSegment();
-            selectFile(fileName, folderPath);
+            SWTBotImportWizardUtils.selectFile(fBot, fileName, folderPath);
         } else {
             selectFolder(exportedPath.segments());
         }
@@ -537,95 +692,17 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
     }
 
-    private static void selectImportFromDirectory(String directoryPath) {
-        SWTBotRadio button = fBot.radio("Select roo&t directory:");
-        button.click();
-
-        SWTBotCombo sourceCombo = fBot.comboBox();
-        File traceFolderParent = new File(directoryPath);
-        sourceCombo.setText(traceFolderParent.getAbsolutePath());
-
-        SWTBotText text = fBot.text();
-        text.setFocus();
-    }
-
-    private static void selectImportFromArchive(String archivePath) {
-        SWTBotRadio button = fBot.radio("Select &archive file:");
-        button.click();
-
-        SWTBotCombo sourceCombo = fBot.comboBox(1);
 
-        sourceCombo.setText(new File(archivePath).getAbsolutePath());
-
-        SWTBotText text = fBot.text();
-        text.setFocus();
-    }
 
     private static void selectFolder(String... treePath) {
-        selectFolder(true, treePath);
+        SWTBotImportWizardUtils.selectFolder(fBot, true, treePath);
     }
 
-    private static void selectFolder(boolean check, String... treePath) {
-        SWTBotTree tree = fBot.tree();
-        fBot.waitUntil(Conditions.widgetIsEnabled(tree));
-        SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, tree, treePath);
-        if (check) {
-            folderNode.check();
-        } else {
-            folderNode.select();
-        }
+    private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
+        checkOptions(optionFlags, expectedSourceLocation, expectedElementPath, null, null);
     }
 
-    private static void selectFile(String fileName, String... folderTreePath) {
-        selectFolder(false, folderTreePath);
-
-        SWTBotTable fileTable = fBot.table();
-        fBot.waitUntil(Conditions.widgetIsEnabled(fileTable));
-        fBot.waitUntil(ConditionHelpers.isTableItemAvailable(fileName, fileTable));
-        SWTBotTableItem tableItem = fileTable.getTableItem(fileName);
-        tableItem.check();
-    }
-
-    private static void setOptions(int optionFlags, String traceTypeName) {
-        SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
-        if (checkBox.isEnabled()) {
-            if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) {
-                checkBox.select();
-            } else {
-                checkBox.deselect();
-            }
-        }
-
-        checkBox = fBot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure);
-        if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
-            checkBox.select();
-        } else {
-            checkBox.deselect();
-        }
-
-        checkBox = fBot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized);
-        if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
-            checkBox.select();
-        } else {
-            checkBox.deselect();
-        }
-
-        checkBox = fBot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace);
-        if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) {
-            checkBox.select();
-        } else {
-            checkBox.deselect();
-        }
-
-        SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
-        if (traceTypeName != null && !traceTypeName.isEmpty()) {
-            comboBox.setSelection(traceTypeName);
-        } else {
-            comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
-        }
-    }
-
-    private void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
+    private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath, String experimentName, IPath expectedElementPathRenamed) throws CoreException {
         IProject project = getProjectResource();
         assertTrue(project.exists());
         TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
@@ -650,17 +727,53 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPath);
         assertEquals(expectedPath, traceResource.getFullPath());
 
+        if (expectedElementPathRenamed != null) {
+            IPath expectedPathRenamed = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPathRenamed);
+            IResource traceResourceRenamed = traces.get(1).getResource();
+            assertEquals(expectedPathRenamed, traceResourceRenamed.getFullPath());
+        }
+
         String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
         assertNotNull(sourceLocation);
         assertEquals(expectedSourceLocation, sourceLocation);
+
+        TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
+        assertNotNull(expFolder);
+        if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT) != 0) {
+            if (experimentName != null) {
+                TmfExperimentElement expElement = expFolder.getExperiment(experimentName);
+                assertNotNull(expElement);
+                assertEquals(2, expElement.getTraces().size());
+            }
+        } else {
+            assertTrue(expFolder.getExperiments().size() == 0);
+        }
     }
 
-    @Override
-    protected String getProjectName() {
-        return TRACE_PROJECT_NAME;
+    private static IProject getProjectResource() {
+        return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
     }
 
-    private IProject getProjectResource() {
-        return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
+    private @NonNull String verifyExperimentNameHandling(String aExperimentName) {
+        String experimentName = aExperimentName;
+
+        // experiment already exists
+        checkFinishButton(false);
+
+        SWTBotText expText = fBot.textInGroup("Options");
+
+        // Invalid experiment name (only whitespaces)
+        expText.setText(String.valueOf(' '));
+        checkFinishButton(false);
+
+        // Invalid experiment name
+        expText.setText(String.valueOf('/'));
+        checkFinishButton(false);
+
+        // Set valid experiment name
+        experimentName += '_';
+        expText.setText(experimentName);
+        return experimentName;
     }
+
 }
This page took 0.038092 seconds and 5 git commands to generate.