releng: Add SWTBot integration tests for import wizard
authorPatrick Tasse <patrick.tasse@gmail.com>
Thu, 6 Oct 2016 20:53:42 +0000 (16:53 -0400)
committerPatrick Tasse <patrick.tasse@gmail.com>
Fri, 14 Oct 2016 15:53:27 +0000 (11:53 -0400)
Add tests for import from folder preserving folder structure.
Add tests for import from zip archive.
Add tests for import from tar.gz archive.
Programmatically create zip/tar.gz archives of test directory structure.
Add util method to select import items in folder tree and file table.
Add util method to recursively find trace project item.
Add org.apache.commons.compress to target definitions.
Fix project folder element matching regex.
Fix condition failure messages binding string.

Change-Id: Ib97d3bfc14f37edc882f0c6dc9ffafcc02753252
Signed-off-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-on: https://git.eclipse.org/r/82677
Reviewed-by: Hudson CI
Reviewed-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Tested-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/SWTBotImportWizardUtils.java
releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF
releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTracesFolderTest.java
releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java
releng/org.eclipse.tracecompass.target/tracecompass-e4.5.target
releng/org.eclipse.tracecompass.target/tracecompass-e4.6.target
releng/org.eclipse.tracecompass.target/tracecompass-eStaging.target
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java
tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java

index fcdddf7ccca242f948e8f8b0dde14ad5e73456e5..14ae8c17f67313447cae766f17274f1566871d52 100644 (file)
@@ -10,6 +10,7 @@
 package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
 
 import java.io.File;
+import java.util.Arrays;
 
 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
@@ -75,6 +76,46 @@ public final class SWTBotImportWizardUtils {
         text.setFocus();
     }
 
+    /**
+     * While in the import wizard, select an item in the file selection control.
+     * The item can be a folder in the left tree or a file in the right table.
+     * The item will be checked.
+     *
+     * @param bot
+     *            the SWTBot
+     * @param treePath
+     *            the path to the item, ending with a file or folder
+     */
+    public static void selectItem(SWTBot bot, String... treePath) {
+        SWTBotTree tree = bot.tree();
+        bot.waitUntil(Conditions.widgetIsEnabled(tree));
+        if (treePath.length == 0) {
+            return;
+        }
+        if (treePath.length == 1) {
+            SWTBotTreeItem rootNode = SWTBotUtils.getTreeItem(bot, tree, treePath);
+            rootNode.select();
+            rootNode.check();
+            return;
+        }
+        String[] parentPath = Arrays.copyOf(treePath, treePath.length - 1);
+        String itemName = treePath[treePath.length - 1];
+        SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(bot, tree, parentPath);
+        folderNode.expand();
+        if (folderNode.getNodes().contains(itemName)) {
+            folderNode = folderNode.getNode(itemName);
+            folderNode.select();
+            folderNode.check();
+        } else {
+            folderNode.select();
+            SWTBotTable fileTable = bot.table();
+            bot.waitUntil(Conditions.widgetIsEnabled(fileTable));
+            bot.waitUntil(ConditionHelpers.isTableItemAvailable(itemName, fileTable));
+            SWTBotTableItem tableItem = fileTable.getTableItem(itemName);
+            tableItem.check();
+        }
+    }
+
     /**
      * While in the import wizard, select a folder in the file selection tree.
      *
index bea8fffa66aef2195a1cdc10c0dcfd2ae75426c7..b98f9a873bbfccb63f1cac7632c239b1a484cc76 100644 (file)
@@ -8,7 +8,8 @@ Bundle-SymbolicName: org.eclipse.tracecompass.integration.swtbot.tests;singleton
 Bundle-ActivationPolicy: lazy
 Bundle-RequiredExecutionEnvironment: JavaSE-1.8
 Export-Package: org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer
-Require-Bundle: org.apache.log4j,
+Require-Bundle: org.apache.commons.compress,
+ org.apache.log4j,
  org.eclipse.core.resources,
  org.eclipse.core.runtime,
  org.eclipse.swtbot.eclipse.finder,
index 050947dd3376d4aee7eb8f2126d68c2ab52091ab..292d5936b5a03e62e93609fefde0f8b20412d6ce 100644 (file)
@@ -91,6 +91,7 @@ public class ProjectExplorerTracesFolderTest {
             LTTNG_KERNEL_TRACE.getFirstEventTimestamp());
     private static final @NonNull TestTraceInfo UNRECOGNIZED_LOG = new TestTraceInfo("unrecognized.log", "", 0, "");
     private static final @NonNull TestTraceInfo CUSTOM_XML_LOG_AS_TEXT = new TestTraceInfo("ExampleCustomXml.xml", CUSTOM_TEXT_TRACE_TYPE, 0, "");
+    private static final @NonNull TestTraceInfo CLASHES_CUSTOM_XML_LOG_AS_TEXT = new TestTraceInfo("ExampleCustomXml.xml", CLASHES_DIR_NAME + "/ExampleCustomXml.xml", CUSTOM_TEXT_TRACE_TYPE, 0, "");
 
     private static final TestTraceInfo[] ALL_TRACEINFOS = new TestTraceInfo[] {
             CUSTOM_TEXT_LOG,
@@ -699,7 +700,7 @@ public class ProjectExplorerTracesFolderTest {
      * type "Generic CTF Trace" . Make sure that these traces can be opened
      */
     @Test
-    public void test3_17ImportRecursiveSpecityTraceTypeCTF() {
+    public void test3_17ImportRecursiveSpecifyTraceTypeCTF() {
         SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
 
         int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
@@ -738,7 +739,7 @@ public class ProjectExplorerTracesFolderTest {
      * trace type "LTTng Kernel Trace". Make sure that this trace can be opened.
      */
     @Test
-    public void test3_18ImportRecursiveSpecityTraceTypeKernel() {
+    public void test3_18ImportRecursiveSpecifyTraceTypeKernel() {
         SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
 
         int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
@@ -769,7 +770,7 @@ public class ProjectExplorerTracesFolderTest {
      * trace type "LTTng UST Trace". Make sure that these traces can be opened.
      */
     @Test
-    public void test3_19ImportRecursiveSpecityTraceTypeUST() {
+    public void test3_19ImportRecursiveSpecifyTraceTypeUST() {
         SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
 
         int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
@@ -809,7 +810,7 @@ public class ProjectExplorerTracesFolderTest {
      * show any events in the table.
      */
     @Test
-    public void test3_20ImportRecursiveSpecityTraceTypeCustomText() {
+    public void test3_20ImportRecursiveSpecifyTraceTypeCustomText() {
         SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
 
         int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
@@ -833,12 +834,333 @@ public class ProjectExplorerTracesFolderTest {
         verifyTrace(traceInfo, importOptionFlags, traceInfo.getTraceName());
     }
 
+    /**
+     * <p>
+     * Action : Recursive import with preserved folder structure
+     * <p>
+     *
+     * <pre>
+     * Procedure : 0) Delete all traces in project
+     *             1) Open Import wizard
+     *             2) Browse to directory ${local}/traces/import/
+     *             3) Select directory import
+     *             4) Select trace type "Tmf Generic", unselect "Overwrite existing without warning", select "Create Links to workspace" and select "Preserve Folder Structure"
+     *             5) press Finish
+     * </pre>
+     * <p>
+     * Expected Results: All matching traces are imported with trace type set.
+     * The folder "clashes" is imported with traces inside. Make sure that the
+     * traces can be opened.
+     */
+    @Test
+    public void test3_29ImportRecursivePreserve() {
+        SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
+
+        int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        importTrace(CUSTOM_TEXT_TRACE_TYPE, optionFlags, ImportConfirmation.CONTINUE, "");
+
+        verifyTrace(CUSTOM_TEXT_LOG, optionFlags, CUSTOM_TEXT_LOG.getTraceName(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CUSTOM_XML_LOG_AS_TEXT, optionFlags, CUSTOM_XML_LOG_AS_TEXT.getTraceName(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(UNRECOGNIZED_LOG, optionFlags, UNRECOGNIZED_LOG.getTraceName(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CLASHES_CUSTOM_TEXT_LOG, optionFlags, CLASHES_CUSTOM_TEXT_LOG.getTracePath(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CLASHES_CUSTOM_XML_LOG_AS_TEXT, optionFlags, CLASHES_CUSTOM_XML_LOG_AS_TEXT.getTracePath(), CUSTOM_TEXT_TRACE_TYPE);
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(4, tracesFolderItem.getItems().length);
+        SWTBotTreeItem clashesFolderItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolderItem, CLASHES_DIR_NAME);
+        assertEquals(2, clashesFolderItem.getItems().length);
+    }
+
+    /**
+     * <p>
+     * Action : Recursive import with preserved folder structure (Skip All)
+     * <p>
+     *
+     * <pre>
+     * Procedure : 1) Open Import wizard
+     *             2) Browse to directory ${local}/traces/import/
+     *             3) Select directory import
+     *             4) Select trace type "Tmf Generic", unselect "Overwrite existing without warning", select "Create Links to workspace" and select "Preserve Folder Structure"
+     *             5) press Finish
+     *             6) When dialog appears select "Skip All"
+     * </pre>
+     * <p>
+     * Expected Results: The wizard should finish quickly as no trace will be
+     * imported. Make sure that the traces can be opened.
+     */
+    @Test
+    public void test3_30ImportRecursivePreserveSkipAll() {
+        int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        importTrace(CUSTOM_TEXT_TRACE_TYPE, optionFlags, ImportConfirmation.SKIP_ALL, "");
+
+        verifyTrace(CUSTOM_TEXT_LOG, optionFlags, CUSTOM_TEXT_LOG.getTraceName(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CUSTOM_XML_LOG_AS_TEXT, optionFlags, CUSTOM_XML_LOG_AS_TEXT.getTraceName(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(UNRECOGNIZED_LOG, optionFlags, UNRECOGNIZED_LOG.getTraceName(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CLASHES_CUSTOM_TEXT_LOG, optionFlags, CLASHES_CUSTOM_TEXT_LOG.getTracePath(), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CLASHES_CUSTOM_XML_LOG_AS_TEXT, optionFlags, CLASHES_CUSTOM_XML_LOG_AS_TEXT.getTracePath(), CUSTOM_TEXT_TRACE_TYPE);
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(4, tracesFolderItem.getItems().length);
+        SWTBotTreeItem clashesFolderItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolderItem, CLASHES_DIR_NAME);
+        assertEquals(2, clashesFolderItem.getItems().length);
+        //TOOD: verify that traces were actually skipped
+    }
+
+    /**
+     * <p>
+     * Action : Recursive import with preserved folder structure (Rename All)
+     * <p>
+     *
+     * <pre>
+     * Procedure : 1) Open Import wizard
+     *             2) Browse to directory ${local}/traces/import/
+     *             3) Select directory import
+     *             4) Select trace type "Tmf Generic", unselect "Overwrite existing without warning", select "Create Links to workspace" and select "Preserve Folder Structure"
+     *             5) press Finish
+     *             6) When dialog appears select "Rename All"
+     * </pre>
+     * <p>
+     * Expected Results: All matching traces are imported with trace type set.
+     * The traces are renamed with suffix (2). The folder "clashes" is imported
+     * with traces inside. Make sure that the traces can be opened.
+     */
+    @Test
+    public void test3_31ImportRecursivePreserveRenameAll() {
+        int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        importTrace(CUSTOM_TEXT_TRACE_TYPE, optionFlags, ImportConfirmation.RENAME_ALL, "");
+
+        verifyTrace(CUSTOM_TEXT_LOG, optionFlags, toRenamedName(CUSTOM_TEXT_LOG.getTraceName()), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CUSTOM_XML_LOG_AS_TEXT, optionFlags, toRenamedName(CUSTOM_XML_LOG_AS_TEXT.getTraceName()), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(UNRECOGNIZED_LOG, optionFlags, toRenamedName(UNRECOGNIZED_LOG.getTraceName()), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CLASHES_CUSTOM_TEXT_LOG, optionFlags, toRenamedName(CLASHES_CUSTOM_TEXT_LOG.getTracePath()), CUSTOM_TEXT_TRACE_TYPE);
+        verifyTrace(CLASHES_CUSTOM_XML_LOG_AS_TEXT, optionFlags, toRenamedName(CLASHES_CUSTOM_XML_LOG_AS_TEXT.getTracePath()), CUSTOM_TEXT_TRACE_TYPE);
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(7, tracesFolderItem.getItems().length);
+        SWTBotTreeItem clashesFolderItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolderItem, CLASHES_DIR_NAME);
+        assertEquals(4, clashesFolderItem.getItems().length);
+    }
+
+    /**
+     * <p>
+     * Action : Import from zip archive with preserved folder structure
+     * <p>
+     *
+     * <pre>
+     * Procedure : 0) Delete all traces in project
+     *             1) Open Import wizard
+     *             2) Select archive file: traces.zip
+     *             3) Select archive root directory
+     *             4) Select trace type "Automatic", unselect "Overwrite existing without warning", and select "Preserve Folder Structure"
+     *             5) press Finish
+     * </pre>
+     * <p>
+     * Expected Results: All traces are imported with trace type set. The folder
+     * "clashes" is imported with traces inside. Make sure that the traces can
+     * be opened.
+     */
+    @Test
+    public void test3_36ImportZipArchivePreserve() {
+        SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
+
+        int optionFlags = ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        importTrace("traces.zip", null, optionFlags, ImportConfirmation.CONTINUE, "");
+
+        for (TestTraceInfo info : ALL_TRACEINFOS) {
+            verifyTrace(info, optionFlags, info.getTracePath());
+        }
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(7, tracesFolderItem.getItems().length);
+        SWTBotTreeItem clashesFolderItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolderItem, CLASHES_DIR_NAME);
+        assertEquals(6, clashesFolderItem.getItems().length);
+    }
+
+    /**
+     * <p>
+     * Action : Import from zip archive without preserved folder structure
+     * (Rename All)
+     * <p>
+     *
+     * <pre>
+     * Procedure : 0) Delete all traces in project
+     *             1) Open Import wizard
+     *             2) Select archive file: traces.zip
+     *             3) Select archive root directory
+     *             4) Select trace type "Automatic", unselect "Overwrite existing without warning", and unselect "Preserve Folder Structure"
+     *             5) press Finish
+     *             6) When dialog appears select "Rename All"
+     * </pre>
+     * <p>
+     * Expected Results: All traces are imported with trace type set. The traces
+     * from folder "clashes" are renamed with suffix (2). Make sure that the
+     * traces can be opened.
+     */
+    @Test
+    public void test3_37ImportZipArchiveNoPreserve() {
+        SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
+
+        int optionFlags = 0;
+        importTrace("traces.zip", null, optionFlags, ImportConfirmation.RENAME_ALL, "");
+
+        for (TestTraceInfo info : ALL_TRACEINFOS) {
+            String traceName = info.getTraceName();
+            if (CLASHING_TRACEINFOS.contains(info)) {
+                traceName = toRenamedName(traceName);
+            }
+            verifyTrace(info, optionFlags, traceName);
+        }
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(12, tracesFolderItem.getItems().length);
+    }
+
+    /**
+     * <p>
+     * Action : Import from zip archive specific traces
+     * <p>
+     *
+     * <pre>
+     * Procedure : 0) Delete all traces in project
+     *             1) Open Import wizard
+     *             2) Select archive file: traces.zip
+     *             3) Select file z-clashes/ExampleCustomTxt.log and directory kernel-overlap-testing/
+     *             4) Select trace type "Automatic", unselect "Overwrite existing without warning", and select "Preserve Folder Structure"
+     *             5) press Finish
+     * </pre>
+     * <p>
+     * Expected Results: The specified traces are imported with trace type set.
+     * Make sure that the traces can be opened.
+     */
+    @Test
+    public void test3_38ImportZipArchiveSpecificTraces() {
+        SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
+
+        int optionFlags = ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        importTrace("traces.zip", null, optionFlags, ImportConfirmation.CONTINUE, "z-clashes/ExampleCustomTxt.log", "kernel-overlap-testing/");
+
+        verifyTrace(CLASHES_CUSTOM_TEXT_LOG, optionFlags, CLASHES_CUSTOM_TEXT_LOG.getTracePath());
+        verifyTrace(LTTNG_KERNEL_TRACE, optionFlags, LTTNG_KERNEL_TRACE.getTracePath());
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(2, tracesFolderItem.getItems().length);
+        SWTBotTreeItem clashesFolderItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolderItem, CLASHES_DIR_NAME);
+        assertEquals(1, clashesFolderItem.getItems().length);
+    }
+
+    /**
+     * <p>
+     * Action : Import from tar.gz archive with preserved folder structure
+     * <p>
+     *
+     * <pre>
+     * Procedure : 0) Delete all traces in project
+     *             1) Open Import wizard
+     *             2) Select archive file: traces.tar.gz
+     *             3) Select archive root directory
+     *             4) Select trace type "Automatic", unselect "Overwrite existing without warning", and select "Preserve Folder Structure"
+     *             5) press Finish
+     * </pre>
+     * <p>
+     * Expected Results: All traces are imported with trace type set. The folder
+     * "clashes" is imported with traces inside. Make sure that the traces can
+     * be opened.
+     */
+    @Test
+    public void test3_39ImportTarGzipArchivePreserve() {
+        SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
+
+        int optionFlags = ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        importTrace("traces.tar.gz", null, optionFlags, ImportConfirmation.CONTINUE, "");
+
+        for (TestTraceInfo info : ALL_TRACEINFOS) {
+            verifyTrace(info, optionFlags, info.getTracePath());
+        }
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(7, tracesFolderItem.getItems().length);
+        SWTBotTreeItem clashesFolderItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolderItem, CLASHES_DIR_NAME);
+        assertEquals(6, clashesFolderItem.getItems().length);
+    }
+
+    /**
+     * <p>
+     * Action : Import from tar.gz archive without preserved folder structure (Rename All)
+     * <p>
+     *
+     * <pre>
+     * Procedure : 0) Delete all traces in project
+     *             1) Open Import wizard
+     *             2) Select archive file: traces.tar.gz
+     *             3) Select archive root directory
+     *             4) Select trace type "Automatic", unselect "Overwrite existing without warning", and unselect "Preserve Folder Structure"
+     *             5) press Finish
+     *             6) When dialog appears select "Rename All"
+     * </pre>
+     * <p>
+     * Expected Results: All traces are imported with trace type set. The traces
+     * from folder "clashes" are renamed with suffix (2). Make sure that the
+     * traces can be opened.
+     */
+    @Test
+    public void test3_40ImportTarGzipArchiveNoPreserve() {
+        SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
+
+        int optionFlags = 0;
+        importTrace("traces.tar.gz", null, optionFlags, ImportConfirmation.RENAME_ALL, "");
+
+        for (TestTraceInfo info : ALL_TRACEINFOS) {
+            String traceName = info.getTraceName();
+            if (CLASHING_TRACEINFOS.contains(info)) {
+                traceName = toRenamedName(traceName);
+            }
+            verifyTrace(info, optionFlags, traceName);
+        }
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(12, tracesFolderItem.getItems().length);
+    }
+
+    /**
+     * <p>
+     * Action : Import from tar.gz archive specific traces
+     * <p>
+     *
+     * <pre>
+     * Procedure : 0) Delete all traces in project
+     *             1) Open Import wizard
+     *             2) Select archive file: traces.tar.gz
+     *             3) Select file z-clashes/ExampleCustomTxt.log and directory kernel-overlap-testing/
+     *             4) Select trace type "Automatic", unselect "Overwrite existing without warning", and select "Preserve Folder Structure"
+     *             5) press Finish
+     * </pre>
+     * <p>
+     * Expected Results: The specified traces are imported with trace type set.
+     * Make sure that the traces can be opened.
+     */
+    @Test
+    public void test3_41ImportTarGzipArchiveSpecificTraces() {
+        SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
+
+        int optionFlags = ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        importTrace("traces.tar.gz", null, optionFlags, ImportConfirmation.CONTINUE, "z-clashes/ExampleCustomTxt.log", "kernel-overlap-testing/");
+
+        verifyTrace(CLASHES_CUSTOM_TEXT_LOG, optionFlags, CLASHES_CUSTOM_TEXT_LOG.getTracePath());
+        verifyTrace(LTTNG_KERNEL_TRACE, optionFlags, LTTNG_KERNEL_TRACE.getTracePath());
+
+        SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
+        assertEquals(2, tracesFolderItem.getItems().length);
+        SWTBotTreeItem clashesFolderItem = SWTBotUtils.getTraceProjectItem(fBot, tracesFolderItem, CLASHES_DIR_NAME);
+        assertEquals(1, clashesFolderItem.getItems().length);
+    }
+
     private static void verifyTrace(TestTraceInfo traceInfo, int importOptionFlags, String traceName) {
         verifyTrace(traceInfo, importOptionFlags, traceName, traceInfo.getTraceType());
     }
 
     private static void verifyTrace(TestTraceInfo traceInfo, int importOptionFlags, String traceName, String traceType) {
-        SWTBotTreeItem traceItem = SWTBotUtils.getTreeItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), traceName);
+        String[] tracePath = new Path(traceName).segments();
+        SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), tracePath);
         checkTraceType(traceItem, traceType);
         openTrace(traceItem);
         if (traceType != null && !traceType.isEmpty()) {
@@ -875,7 +1197,11 @@ public class ProjectExplorerTracesFolderTest {
     }
 
     private static void importTrace(String traceType, int optionFlags, ImportConfirmation confirmationMode, String ... tracePaths) {
-        importTrace(traceType, optionFlags, new Supplier<ImportConfirmation>() {
+        importTrace(null, traceType, optionFlags, confirmationMode, tracePaths);
+    }
+
+    private static void importTrace(String archiveFile, String traceType, int optionFlags, ImportConfirmation confirmationMode, String ... tracePaths) {
+        importTrace(archiveFile, traceType, optionFlags, new Supplier<ImportConfirmation>() {
             boolean fDone = false;
             @Override
             public ImportConfirmation get() {
@@ -889,31 +1215,38 @@ public class ProjectExplorerTracesFolderTest {
     }
 
     private static void importTrace(int optionFlags, Supplier<ImportConfirmation> confirmationSuplier, String ... tracePaths) {
-        importTrace(null, optionFlags, confirmationSuplier, tracePaths);
+        importTrace(null, null, optionFlags, confirmationSuplier, tracePaths);
     }
 
     /**
-     * @param tracePath relative to parent test traces folder
+     * @param tracePaths relative to parent test traces folder
      */
-    private static void importTrace(String traceType, int optionFlags, Supplier<ImportConfirmation> confirmationSuplier, String ... tracePaths) {
+    private static void importTrace(String archiveFile, String traceType, int optionFlags, Supplier<ImportConfirmation> confirmationSuplier, String ... tracePaths) {
         SWTBotTreeItem traceFolder = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
 
         SWTBotShell shell = openTraceFoldersImport(traceFolder);
         SWTBot bot = shell.bot();
-        final String importDirectoryRelativePath = "import";
-        String importDirectoryFullPath = getPath(importDirectoryRelativePath);
+        String rootFolderName;
+        if (archiveFile == null) {
+            rootFolderName = "import";
+            String importDirectoryFullPath = getPath(rootFolderName);
+            SWTBotImportWizardUtils.selectImportFromDirectory(bot, importDirectoryFullPath);
+        } else {
+            rootFolderName = "/";
+            String importArchiveFullPath = getPath("archives" + File.separator + archiveFile);
+            SWTBotImportWizardUtils.selectImportFromArchive(bot, importArchiveFullPath);
+        }
 
         for (String tracePath : tracePaths) {
-            IPath somePath = new Path(importDirectoryRelativePath).append(tracePath);
-            IPath fullParentPath = somePath.removeLastSegments(1);
-            boolean isDirectory = new Path(importDirectoryFullPath).append(tracePath).toFile().isDirectory();
-
-            SWTBotImportWizardUtils.selectImportFromDirectory(bot, importDirectoryFullPath);
-            if (isDirectory) {
-                SWTBotImportWizardUtils.selectFolder(fBot, true, somePath.segments());
-            } else {
-                SWTBotImportWizardUtils.selectFile(bot, new Path(tracePath).lastSegment(), fullParentPath.segments());
+            IPath somePath = new Path(rootFolderName).append(tracePath);
+            String[] treePath = somePath.segments();
+            if (archiveFile != null) {
+                String[] newPath = new String[treePath.length + 1];
+                newPath[0] = "/";
+                System.arraycopy(treePath, 0, newPath, 1, treePath.length);
+                treePath = newPath;
             }
+            SWTBotImportWizardUtils.selectItem(fBot, treePath);
         }
 
         SWTBotImportWizardUtils.setOptions(bot, optionFlags, traceType);
index d8d41b1586ec03cd4b362c15cc8b63e4d30a7614..bcad2e3474978f3b33af610e892045ce01adb789 100644 (file)
@@ -12,11 +12,17 @@ package org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer;
 import static org.junit.Assert.assertTrue;
 
 import java.io.File;
+import java.io.FileInputStream;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.PrintWriter;
+import java.util.zip.GZIPOutputStream;
+import java.util.zip.ZipEntry;
+import java.util.zip.ZipOutputStream;
 
+import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
+import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
 import org.eclipse.tracecompass.ctf.core.tests.shared.LttngTraceGenerator;
 
 /**
@@ -103,6 +109,9 @@ public class TestDirectoryStructureUtil {
      *
      * <pre>
      * parentDir
+     *  ├── archives
+     *  │   ├── traces.zip
+     *  │   └── traces.tar.gz
      *  ├── customParsers
      *  │   ├── ExampleCustomTxtParser.xml
      *  │   └── ExampleCustomXmlParser.xml
@@ -185,6 +194,15 @@ public class TestDirectoryStructureUtil {
 
         assertTrue(parent.listFiles().length > 0);
 
+        File archivesDir = createDir(parent, "archives");
+        File zipFile = new File(archivesDir.getAbsolutePath() + File.separator + "traces.zip");
+        try (ZipOutputStream zos = new ZipOutputStream(new FileOutputStream(zipFile))) {
+            addToArchive(zos, importDir, importDir);
+        }
+        File targzFile = new File(archivesDir.getAbsolutePath() + File.separator + "traces.tar.gz");
+        try (TarArchiveOutputStream tgzos = new TarArchiveOutputStream(new GZIPOutputStream(new FileOutputStream(targzFile)))) {
+            addToArchive(tgzos, importDir, importDir);
+        }
         return parent;
     }
 
@@ -201,4 +219,56 @@ public class TestDirectoryStructureUtil {
         }
         return child;
     }
+
+    private static void addToArchive(ZipOutputStream zos, File dir, File root) throws IOException {
+        byte[] buffer = new byte[1024];
+        int length;
+        int index = root.getAbsolutePath().length();
+        for (File file : dir.listFiles()) {
+            String name = file.getAbsolutePath().substring(index);
+            if (file.isDirectory()) {
+                if (file.listFiles().length != 0) {
+                    addToArchive(zos, file, root);
+                } else {
+                    zos.putNextEntry(new ZipEntry(name + File.separator));
+                    zos.closeEntry();
+                }
+            } else {
+                try (FileInputStream fis = new FileInputStream(file)) {
+                    zos.putNextEntry(new ZipEntry(name));
+                    while ((length = fis.read(buffer)) > 0) {
+                        zos.write(buffer, 0, length);
+                    }
+                    zos.closeEntry();
+                }
+            }
+        }
+    }
+
+    private static void addToArchive(TarArchiveOutputStream taos, File dir, File root) throws IOException {
+        byte[] buffer = new byte[1024];
+        int length;
+        int index = root.getAbsolutePath().length();
+        for (File file : dir.listFiles()) {
+            String name = file.getAbsolutePath().substring(index);
+            if (file.isDirectory()) {
+                if (file.listFiles().length != 0) {
+                    addToArchive(taos, file, root);
+                } else {
+                    taos.putArchiveEntry(new TarArchiveEntry(name + File.separator));
+                    taos.closeArchiveEntry();
+                }
+            } else {
+                try (FileInputStream fis = new FileInputStream(file)) {
+                    TarArchiveEntry entry = new TarArchiveEntry(name);
+                    entry.setSize(file.length());
+                    taos.putArchiveEntry(entry);
+                    while ((length = fis.read(buffer)) > 0) {
+                        taos.write(buffer, 0, length);
+                    }
+                    taos.closeArchiveEntry();
+                }
+            }
+        }
+    }
 }
index ef7a363b743ca97e2a51d34fa5b3a74a7397bff6..0766d028a6095ea2a71b2f63691d51ed16a5ce0f 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?pde version="3.8"?><target name="tracecompass-e4.5" sequenceNumber="75">
+<?pde version="3.8"?><target name="tracecompass-e4.5" sequenceNumber="76">
 <locations>
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.eclipse.cdt.gnu.dsf.feature.group" version="0.0.0"/>
@@ -29,6 +29,7 @@
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.antlr.runtime" version="3.2.0.v201101311130"/>
 <unit id="org.antlr.runtime.source" version="3.2.0.v201101311130"/>
+<unit id="org.apache.commons.compress" version="0.0.0"/>
 <unit id="org.apache.commons.io" version="0.0.0"/>
 <unit id="org.swtchart" version="0.0.0"/>
 <unit id="com.google.gson" version="0.0.0"/>
index c619b140578d03e0835d0727fccab23f44473500..2daf7bf220dd9c881f3aa35b4d95a2b9bb63d681 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?pde version="3.8"?><target name="tracecompass-e4.6" sequenceNumber="23">
+<?pde version="3.8"?><target name="tracecompass-e4.6" sequenceNumber="24">
 <locations>
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.eclipse.cdt.gnu.dsf.feature.group" version="0.0.0"/>
@@ -32,6 +32,7 @@
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.antlr.runtime" version="3.2.0.v201101311130"/>
 <unit id="org.antlr.runtime.source" version="3.2.0.v201101311130"/>
+<unit id="org.apache.commons.compress" version="0.0.0"/>
 <unit id="org.apache.commons.io" version="0.0.0"/>
 <unit id="org.swtchart" version="0.7.0.v201201201914"/>
 <unit id="com.google.guava" version="15.0.0.v201403281430"/>
index c1ea043698707fab1d6bb212bd334ab7826d8958..48337f05edee83ff12eb6112c07e97f6a1ddeeac 100644 (file)
@@ -1,5 +1,5 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<?pde version="3.8"?><target name="tracecompass-eStaging" sequenceNumber="77">
+<?pde version="3.8"?><target name="tracecompass-eStaging" sequenceNumber="78">
 <locations>
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.eclipse.cdt.gnu.dsf.feature.group" version="0.0.0"/>
@@ -32,6 +32,7 @@
 <location includeAllPlatforms="false" includeConfigurePhase="false" includeMode="planner" includeSource="true" type="InstallableUnit">
 <unit id="org.antlr.runtime" version="3.2.0.v201101311130"/>
 <unit id="org.antlr.runtime.source" version="3.2.0.v201101311130"/>
+<unit id="org.apache.commons.compress" version="0.0.0"/>
 <unit id="org.apache.commons.io" version="0.0.0"/>
 <unit id="org.swtchart" version="0.7.0.v201201201914"/>
 <unit id="com.google.guava" version="15.0.0.v201403281430"/>
index f34b4a2d18c65899d9fe520953d41aac331f71b2..5559e6db044c5d1b1f2a0d949d8d563d245e493c 100644 (file)
@@ -18,6 +18,7 @@ import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.wi
 
 import java.util.Arrays;
 import java.util.List;
+import java.util.regex.Pattern;
 
 import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.viewers.StructuredSelection;
@@ -132,7 +133,7 @@ public final class ConditionHelpers {
 
             @Override
             public String getFailureMessage() {
-                return NLS.bind("No child of table {0} found with text '{1}'.", table, name);
+                return NLS.bind("No child of table {0} found with text ''{1}''.", table, name);
             }
         };
     }
@@ -159,7 +160,7 @@ public final class ConditionHelpers {
 
             @Override
             public String getFailureMessage() {
-                return NLS.bind("No child of tree item {0} found with text '{1}'. Child items: {2}",
+                return NLS.bind("No child of tree item {0} found with text ''{1}''. Child items: {2}",
                         new String[] { treeItem.toString(), name, Arrays.toString(treeItem.getItems()) });
             }
         };
@@ -187,7 +188,7 @@ public final class ConditionHelpers {
 
             @Override
             public String getFailureMessage() {
-                return NLS.bind("Child of tree item {0} found with text '{1}' not removed. Child items: {2}",
+                return NLS.bind("Child of tree item {0} found with text ''{1}'' not removed. Child items: {2}",
                         new String[] { treeItem.toString(), String.valueOf(length), Arrays.toString(treeItem.getItems()) });
             }
         };
@@ -334,7 +335,7 @@ public final class ConditionHelpers {
             fParentItem = parentItem;
             fName = name;
             /* Project element labels may have count suffix */
-            fRegex = name + "(\\s\\[(\\d)+\\])?";
+            fRegex = Pattern.quote(name) + "(\\s\\[(\\d)+\\])?";
         }
 
         @Override
index 48f24b5c9824a0491d0f5e7eac01b871fb2ad7de..b402c6b04e2b57d1c3c0ab85ce579b75f94297de 100644 (file)
@@ -552,6 +552,26 @@ public final class SWTBotUtils {
         return (TmfEventsEditor) editorPart;
     }
 
+    /**
+     * Returns the child tree item of the specified item at the given sub-path.
+     * The project element labels may have a count suffix in the format ' [n]'.
+     *
+     * @param bot
+     *            a given workbench bot
+     * @param parentItem
+     *            the parent tree item
+     * @param path
+     *            the desired child element sub-path (without suffix)
+     * @return the a {@link SWTBotTreeItem} with the specified name
+     */
+    public static SWTBotTreeItem getTraceProjectItem(SWTBot bot, final SWTBotTreeItem parentItem, final String... path) {
+        SWTBotTreeItem item = parentItem;
+        for (String name : path) {
+            item = getTraceProjectItem(bot, item, name);
+        }
+        return item;
+    }
+
     /**
      * Returns the child tree item of the specified item with the given name.
      * The project element label may have a count suffix in the format ' [n]'.
This page took 0.037199 seconds and 5 git commands to generate.