tmf: Additional SWTBot tests for the standard import wizard
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Wed, 3 Sep 2014 04:45:56 +0000 (00:45 -0400)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Wed, 17 Sep 2014 19:14:05 +0000 (15:14 -0400)
Change-Id: Id776ed33768ddc640c8ba5f6c23c6e1ecd79ab33
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/33480
Tested-by: Hudson CI
Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
Reviewed-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
Tested-by: Bernd Hufmann <bernd.hufmann@ericsson.com>
org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/AbstractImportAndReadSmokeTest.java
org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/ImportAndReadSmokeTest.java
org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java
org.eclipse.linuxtools.tmf.ui/src/org/eclipse/linuxtools/internal/tmf/ui/project/wizards/importtrace/ImportTraceWizardPage.java

index 5b1838baf28ab877b52aa3aa90b6b4438f804c01..12803adb1950f32ec5940835371d4c504f3d3759 100644 (file)
@@ -30,6 +30,7 @@ import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfEvent;
 import org.eclipse.linuxtools.tmf.ctf.core.CtfTmfTrace;
 import org.eclipse.linuxtools.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
 import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder;
 import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil;
 import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
 import org.eclipse.linuxtools.tmf.ui.views.histogram.HistogramView;
@@ -137,9 +138,12 @@ public abstract class AbstractImportAndReadSmokeTest {
 
     /**
      * Opens and get the TmfEventsEditor
+     *
+     * @param elementPath
+     *            the trace element path (relative to Traces folder)
      * @return TmfEventsEditor
      */
-    protected TmfEventsEditor openEditor() {
+    protected TmfEventsEditor openEditor(IPath elementPath) {
         final SWTBotView projectExplorerBot = fBot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
         projectExplorerBot.setFocus();
 
@@ -147,29 +151,24 @@ public abstract class AbstractImportAndReadSmokeTest {
         final SWTBotTreeItem treeItem = tree.getTreeItem(getProjectName());
         treeItem.expand();
 
-        String nodeName = getFullNodeName(treeItem, "Traces");
+        String nodeName = getFullNodeName(treeItem, TmfTracesFolder.TRACES_FOLDER_NAME);
         fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, treeItem));
         SWTBotTreeItem tracesNode = treeItem.getNode(nodeName);
         tracesNode.expand();
 
-
-        SWTBotTreeItem traceParentNode = tracesNode;
-
-        if (supportsFolderStructure()) {
-            String nodeFolderName = getFullNodeName(tracesNode, TRACE_FOLDER);
-            fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeFolderName, tracesNode));
-            SWTBotTreeItem traceFolder = tracesNode.getNode(nodeFolderName);
-            traceFolder.select();
-            traceFolder.doubleClick();
-            traceParentNode = traceFolder;
+        SWTBotTreeItem currentNode = tracesNode;
+        for (String segment : elementPath.segments()) {
+            String fullNodeName = getFullNodeName(currentNode, segment);
+            fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(fullNodeName, currentNode));
+            SWTBotTreeItem newNode = currentNode.getNode(fullNodeName);
+            newNode.select();
+            newNode.doubleClick();
+            currentNode = newNode;
         }
 
-        fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(TRACE_NAME, traceParentNode));
-        traceParentNode.getNode(TRACE_NAME).select();
-        traceParentNode.getNode(TRACE_NAME).doubleClick();
         SWTBotUtil.delay(1000);
         SWTBotUtil.waitForJobs();
-        final String expectedTitle = supportsFolderStructure() ? TRACE_FOLDER + IPath.SEPARATOR + TRACE_NAME : TRACE_NAME;
+        final String expectedTitle = elementPath.toString();
 
         final IEditorPart iep[] = new IEditorPart[1];
         UIThreadRunnable.syncExec(new VoidResult() {
@@ -218,13 +217,6 @@ public abstract class AbstractImportAndReadSmokeTest {
      */
     protected abstract String getProjectName();
 
-    /**
-     * Returns whether or not that test support folder structure
-     *
-     * @return true if the test supports folder structure, false otherwise
-     */
-    protected abstract boolean supportsFolderStructure();
-
     // ---------------------------------------------
     // Helpers for testing views
     // ---------------------------------------------
index c3e8a3140cdf61c1108fba0e6391bba1ee523f22..717eb5a9dd0666f4aaa61406c62f965328ebd8e3 100644 (file)
@@ -16,6 +16,7 @@ package org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests;
 
 import static org.junit.Assert.assertNotNull;
 
+import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.IWizardPage;
 import org.eclipse.jface.wizard.WizardDialog;
@@ -60,7 +61,7 @@ public class ImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
         batchImportSelectTrace();
         importFinish();
 
-        TmfEventsEditor tmfEd = openEditor();
+        TmfEventsEditor tmfEd = openEditor(new Path(TRACE_NAME));
 
         testHistogramView(getViewPart("Histogram"), tmfEd);
         testPropertyView(getViewPart("Properties"));
@@ -138,9 +139,4 @@ public class ImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
     protected String getProjectName() {
         return TRACE_PROJECT_NAME;
     }
-
-    @Override
-    protected boolean supportsFolderStructure() {
-        return false;
-    }
 }
index d32d3e23da8888600404ff4615df43a41af913e9..3b245d3ed2d5e5555351680b7bfaf6b5a87dc765 100644 (file)
 
 package org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests;
 
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
 import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
 
 import java.io.File;
-
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.IPath;
 import org.eclipse.core.runtime.Path;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.WizardDialog;
 import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
+import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
+import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.Messages;
 import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
+import org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder;
 import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil;
 import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
 import org.eclipse.swt.widgets.Shell;
@@ -28,6 +45,7 @@ import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
 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.SWTBotText;
@@ -52,24 +70,45 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
     private static final String TRACE_PROJECT_NAME = "Tracing";
 
     /**
-     * Main test case
+     * Test import from directory
      */
     @Test
     public void testImportFromDirectory() {
-        createProject();
+        testImport(0, false, false);
+    }
 
-        importOpenWizard();
-        importAddDirectory();
-        importFinish();
+    /**
+     * Test import from directory, create links
+     */
+    @Test
+    public void testImportFromDirectoryLinks() {
+        testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false);
+    }
 
-        TmfEventsEditor tmfEd = openEditor();
+    /**
+     * Test import from directory, preserve folder structure
+     */
+    @Test
+    public void testImportFromDirectoryPreserveFolder() {
+        testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, false);
+    }
 
-        testHistogramView(getViewPart("Histogram"), tmfEd);
-        testPropertyView(getViewPart("Properties"));
-        testStatisticsView(getViewPart("Statistics"));
-        fBot.closeAllEditors();
+    /**
+     * Test import from directory, create links, preserve folder structure
+     */
+    @Test
+    public void testImportFromDirectoryLinksPreserveFolder() {
+        int options = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
+        testImport(options, false, false);
+    }
 
-        SWTBotUtil.deleteProject(getProjectName(), fBot);
+    /**
+     * Test import from directory, overwrite all
+     */
+    @Test
+    public void testImportFromDirectoryOverwrite() {
+        testImport(0, false, false);
+        testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
     }
 
     /**
@@ -77,39 +116,54 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
      */
     @Test
     public void testImportFromArchive() {
+        testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true);
+    }
+
+    /**
+     * Test import from directory, preserve folder structure
+     */
+    @Test
+    public void testImportFromArchivePreserveFolder() {
+        testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
+    }
+
+    /**
+     * Test import from directory, overwrite all
+     */
+    @Test
+    public void testImportFromArchiveOverwrite() {
+        testImport(0, false, true);
+        testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
+    }
+
+    private void testImport(int options, boolean testViews, boolean fromArchive) {
         createProject();
 
         importOpenWizard();
+        if (fromArchive) {
+            importAddArchive();
+        } else {
+            importAddDirectory();
+        }
 
-        importAddArchive();
+        setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
         importFinish();
 
-        TmfEventsEditor tmfEd = openEditor();
+        checkOptions(options);
+        TmfEventsEditor tmfEd = openEditor(getTraceElementPath(options));
+        if (testViews) {
+            testViews(tmfEd);
+        }
 
-        testHistogramView(getViewPart("Histogram"), tmfEd);
-        testPropertyView(getViewPart("Properties"));
-        testStatisticsView(getViewPart("Statistics"));
         fBot.closeAllEditors();
 
         SWTBotUtil.deleteProject(getProjectName(), fBot);
     }
 
-    private static void importAddArchive() {
-        SWTBotRadio button = fBot.radio("Select &archive file:");
-        button.click();
-
-        SWTBotCombo sourceCombo = fBot.comboBox(1);
-
-        sourceCombo.setText(new File(TRACE_ARCHIVE_PATH).getAbsolutePath());
-
-        SWTBotText text = fBot.text();
-        text.setFocus();
-
-        SWTBotTree tree = fBot.tree();
-        fBot.waitUntil(Conditions.widgetIsEnabled(tree));
-        final SWTBotTreeItem genericCtfTreeItem = tree.getTreeItem("/");
-        fBot.waitUntil(Conditions.widgetIsEnabled(genericCtfTreeItem));
-        genericCtfTreeItem.check();
+    private void testViews(TmfEventsEditor editor) {
+        testHistogramView(getViewPart("Histogram"), editor);
+        testPropertyView(getViewPart("Properties"));
+        testStatisticsView(getViewPart("Statistics"));
     }
 
     private static void importOpenWizard() {
@@ -159,14 +213,103 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
         folderNode.check();
     }
 
-    @Override
-    protected String getProjectName() {
-        return TRACE_PROJECT_NAME;
+    private static void importAddArchive() {
+        SWTBotRadio button = fBot.radio("Select &archive file:");
+        button.click();
+
+        SWTBotCombo sourceCombo = fBot.comboBox(1);
+
+        sourceCombo.setText(new File(TRACE_ARCHIVE_PATH).getAbsolutePath());
+
+        SWTBotText text = fBot.text();
+        text.setFocus();
+
+        SWTBotTree tree = fBot.tree();
+        fBot.waitUntil(Conditions.widgetIsEnabled(tree));
+        final SWTBotTreeItem genericCtfTreeItem = tree.getTreeItem("/");
+        fBot.waitUntil(Conditions.widgetIsEnabled(genericCtfTreeItem));
+        genericCtfTreeItem.check();
+
+        SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
+        assertFalse(checkBox.isEnabled());
     }
 
-    @Override
-    protected boolean supportsFolderStructure() {
-        return true;
+    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 static void checkOptions(int optionFlags) {
+        IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
+        assertTrue(project.exists());
+        TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
+        assertNotNull(tmfProject);
+        TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
+        assertNotNull(tracesFolder);
+        List<TmfTraceElement> traces = tracesFolder.getTraces();
+        assertFalse(traces.isEmpty());
+        Collections.sort(traces, new Comparator<TmfTraceElement>() {
+            @Override
+            public int compare(TmfTraceElement arg0, TmfTraceElement arg1) {
+                return arg0.getElementPath().compareTo(arg1.getElementPath());
+            }
+        });
+
+        TmfTraceElement tmfTraceElement = traces.get(0);
+        IResource traceResource = tmfTraceElement.getResource();
+
+        assertEquals((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0, traceResource.isLinked());
+
+        // i.e. /Tracing/Traces
+        IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME);
+        expectedPath = expectedPath.append(getTraceElementPath(optionFlags));
+        assertEquals(expectedPath, traceResource.getFullPath());
+    }
+
+    private static IPath getTraceElementPath(int optionFlags) {
+        IPath traceElementPath = new Path("");
+        if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
+            traceElementPath = traceElementPath.append(TRACE_FOLDER);
+        }
+        return traceElementPath.append(TRACE_NAME);
+    }
+
+    @Override
+    protected String getProjectName() {
+        return TRACE_PROJECT_NAME;
+    }
 }
index d1d9edb25081369fc62fdbc378d3c940abcba561..e08932b72f63e7b534e89f92d2d97b5704e7ace7 100644 (file)
@@ -152,24 +152,24 @@ public class ImportTraceWizardPage extends WizardResourceImportPage {
      * detection will occur instead of setting a specific trace type when
      * importing the traces.
      */
-    protected static final String TRACE_TYPE_AUTO_DETECT = Messages.ImportTraceWizard_AutoDetection;
+    public static final String TRACE_TYPE_AUTO_DETECT = Messages.ImportTraceWizard_AutoDetection;
 
     /**
      * Preserve the folder structure of the import traces.
      */
-    protected static final int OPTION_PRESERVE_FOLDER_STRUCTURE = 1 << 1;
+    public static final int OPTION_PRESERVE_FOLDER_STRUCTURE = 1 << 1;
     /**
      * Create links to the trace files instead of copies.
      */
-    protected static final int OPTION_CREATE_LINKS_IN_WORKSPACE = 1 << 2;
+    public static final int OPTION_CREATE_LINKS_IN_WORKSPACE = 1 << 2;
     /**
      * Import files that were not recognized as the selected trace type.
      */
-    protected static final int OPTION_IMPORT_UNRECOGNIZED_TRACES = 1 << 3;
+    public static final int OPTION_IMPORT_UNRECOGNIZED_TRACES = 1 << 3;
     /**
      * Overwrite existing resources without prompting.
      */
-    protected static final int OPTION_OVERWRITE_EXISTING_RESOURCES = 1 << 4;
+    public static final int OPTION_OVERWRITE_EXISTING_RESOURCES = 1 << 4;
 
     // ------------------------------------------------------------------------
     // Attributes
This page took 0.031395 seconds and 5 git commands to generate.