From cdfe10e7096bf98050a9a32104e2756d4bfbe463 Mon Sep 17 00:00:00 2001 From: Patrick Tasse Date: Thu, 6 Oct 2016 16:53:42 -0400 Subject: [PATCH] releng: Add SWTBot integration tests for import wizard 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 Reviewed-on: https://git.eclipse.org/r/82677 Reviewed-by: Hudson CI Reviewed-by: Marc-Andre Laperle Tested-by: Marc-Andre Laperle --- .../swtbot/tests/SWTBotImportWizardUtils.java | 41 ++ .../META-INF/MANIFEST.MF | 3 +- .../ProjectExplorerTracesFolderTest.java | 373 +++++++++++++++++- .../TestDirectoryStructureUtil.java | 70 ++++ .../tracecompass-e4.5.target | 3 +- .../tracecompass-e4.6.target | 3 +- .../tracecompass-eStaging.target | 3 +- .../swtbot/tests/shared/ConditionHelpers.java | 9 +- .../ui/swtbot/tests/shared/SWTBotUtils.java | 20 + 9 files changed, 497 insertions(+), 28 deletions(-) diff --git a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/SWTBotImportWizardUtils.java b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/SWTBotImportWizardUtils.java index fcdddf7ccc..14ae8c17f6 100644 --- a/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/SWTBotImportWizardUtils.java +++ b/ctf/org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests/src/org/eclipse/tracecompass/tmf/ctf/ui/swtbot/tests/SWTBotImportWizardUtils.java @@ -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. * diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF b/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF index bea8fffa66..b98f9a873b 100644 --- a/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/META-INF/MANIFEST.MF @@ -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, diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTracesFolderTest.java b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTracesFolderTest.java index 050947dd33..292d5936b5 100644 --- a/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTracesFolderTest.java +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/ProjectExplorerTracesFolderTest.java @@ -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()); } + /** + *

+ * Action : Recursive import with preserved folder structure + *

+ * + *

+     * 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
+     * 
+ *

+ * 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); + } + + /** + *

+ * Action : Recursive import with preserved folder structure (Skip All) + *

+ * + *

+     * 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"
+     * 
+ *

+ * 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 + } + + /** + *

+ * Action : Recursive import with preserved folder structure (Rename All) + *

+ * + *

+     * 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"
+     * 
+ *

+ * 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); + } + + /** + *

+ * Action : Import from zip archive with preserved folder structure + *

+ * + *

+     * 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
+     * 
+ *

+ * 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); + } + + /** + *

+ * Action : Import from zip archive without preserved folder structure + * (Rename All) + *

+ * + *

+     * 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"
+     * 
+ *

+ * 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); + } + + /** + *

+ * Action : Import from zip archive specific traces + *

+ * + *

+     * 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
+     * 
+ *

+ * 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); + } + + /** + *

+ * Action : Import from tar.gz archive with preserved folder structure + *

+ * + *

+     * 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
+     * 
+ *

+ * 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); + } + + /** + *

+ * Action : Import from tar.gz archive without preserved folder structure (Rename All) + *

+ * + *

+     * 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"
+     * 
+ *

+ * 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); + } + + /** + *

+ * Action : Import from tar.gz archive specific traces + *

+ * + *

+     * 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
+     * 
+ *

+ * 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() { + 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() { boolean fDone = false; @Override public ImportConfirmation get() { @@ -889,31 +1215,38 @@ public class ProjectExplorerTracesFolderTest { } private static void importTrace(int optionFlags, Supplier 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 confirmationSuplier, String ... tracePaths) { + private static void importTrace(String archiveFile, String traceType, int optionFlags, Supplier 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); diff --git a/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java index d8d41b1586..bcad2e3474 100644 --- a/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java +++ b/releng/org.eclipse.tracecompass.integration.swtbot.tests/src/org/eclipse/tracecompass/integration/swtbot/tests/projectexplorer/TestDirectoryStructureUtil.java @@ -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 { * *

      * 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();
+                }
+            }
+        }
+    }
 }
diff --git a/releng/org.eclipse.tracecompass.target/tracecompass-e4.5.target b/releng/org.eclipse.tracecompass.target/tracecompass-e4.5.target
index ef7a363b74..0766d028a6 100644
--- a/releng/org.eclipse.tracecompass.target/tracecompass-e4.5.target
+++ b/releng/org.eclipse.tracecompass.target/tracecompass-e4.5.target
@@ -1,5 +1,5 @@
 
-
+
 
 
 
@@ -29,6 +29,7 @@
 
 
 
+
 
 
 
diff --git a/releng/org.eclipse.tracecompass.target/tracecompass-e4.6.target b/releng/org.eclipse.tracecompass.target/tracecompass-e4.6.target
index c619b14057..2daf7bf220 100644
--- a/releng/org.eclipse.tracecompass.target/tracecompass-e4.6.target
+++ b/releng/org.eclipse.tracecompass.target/tracecompass-e4.6.target
@@ -1,5 +1,5 @@
 
-
+
 
 
 
@@ -32,6 +32,7 @@
 
 
 
+
 
 
 
diff --git a/releng/org.eclipse.tracecompass.target/tracecompass-eStaging.target b/releng/org.eclipse.tracecompass.target/tracecompass-eStaging.target
index c1ea043698..48337f05ed 100644
--- a/releng/org.eclipse.tracecompass.target/tracecompass-eStaging.target
+++ b/releng/org.eclipse.tracecompass.target/tracecompass-eStaging.target
@@ -1,5 +1,5 @@
 
-
+
 
 
 
@@ -32,6 +32,7 @@
 
 
 
+
 
 
 
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java
index f34b4a2d18..5559e6db04 100644
--- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java
+++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/ConditionHelpers.java
@@ -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
diff --git a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java
index 48f24b5c98..b402c6b04e 100644
--- a/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java
+++ b/tmf/org.eclipse.tracecompass.tmf.ui.swtbot.tests/shared/org/eclipse/tracecompass/tmf/ui/swtbot/tests/shared/SWTBotUtils.java
@@ -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]'.
-- 
2.34.1