tmf: Bug 494689: fix failing name conflict handling in trace import
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / AbstractImportAndReadSmokeTest.java
index 5dfdb1b578a6a9b6df00d879f2a9cac148e3afcf..204fef13e81d7dab7484dad7443b88341114f49d 100644 (file)
 package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
 
 import static org.junit.Assert.assertNotNull;
-import static org.junit.Assume.assumeTrue;
+import static org.junit.Assert.assertTrue;
 
 import java.util.List;
 
 import org.apache.log4j.Logger;
 import org.apache.log4j.varia.NullAppender;
+import org.eclipse.jdt.annotation.NonNull;
 import org.eclipse.jface.viewers.SelectionChangedEvent;
 import org.eclipse.jface.viewers.StructuredSelection;
 import org.eclipse.jface.wizard.Wizard;
@@ -36,11 +37,13 @@ import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
+import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation;
 import org.eclipse.tracecompass.internal.tmf.ui.views.statistics.TmfStatisticsViewImpl;
+import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
-import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
+import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
@@ -69,8 +72,8 @@ public abstract class AbstractImportAndReadSmokeTest {
     protected static final String TRACE_FOLDER = "synctraces";
     /** Trace type name for generic CTF traces */
     protected static final String TRACE_TYPE_NAME = "Generic CTF Trace";
-    /** A Generic CTF Trace*/
-    protected static final CtfTmfTestTrace fTrace = CtfTmfTestTrace.SYNC_DEST;
+    /** A Generic CTF Trace */
+    protected static final @NonNull CtfTestTrace fTrace = CtfTestTrace.SYNC_DEST;
     /** SWT BOT workbench reference */
     protected static SWTWorkbenchBot fBot;
     /** Wizard to use */
@@ -82,8 +85,7 @@ public abstract class AbstractImportAndReadSmokeTest {
     /** Test Class setup */
     @BeforeClass
     public static void init() {
-        assumeTrue(fTrace.exists());
-        SWTBotUtils.failIfUIThread();
+        SWTBotUtils.initialize();
 
         /* set up for swtbot */
         SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
@@ -108,8 +110,11 @@ public abstract class AbstractImportAndReadSmokeTest {
 
     /**
      * Creates a tracing projects
+     *
+     * @param traceProjectName
+     *            the name of the test project
      */
-    protected void createProject() {
+    protected static void createProject(String traceProjectName) {
         SWTBotUtils.focusMainWindow(fBot.shells());
         fBot.menu("File").menu("New").menu("Project...").click();
 
@@ -135,7 +140,7 @@ public abstract class AbstractImportAndReadSmokeTest {
         fBot.shell("Tracing Project").setFocus();
 
         final SWTBotText text = fBot.text();
-        text.setText(getProjectName());
+        text.setText(traceProjectName);
 
         fBot.button("Finish").click();
         SWTBotUtils.waitForJobs();
@@ -145,18 +150,48 @@ public abstract class AbstractImportAndReadSmokeTest {
      * Finishes the wizard
      */
     protected void importFinish() {
+        importFinish(ImportConfirmation.CONTINUE);
+    }
+
+    /**
+     * Finishes the wizard
+     *
+     * @param confirmationMode
+     *            a confirmation value
+     *            Note: Only {@link ImportConfirmation#RENAME_ALL},
+     *            {@link ImportConfirmation#OVERWRITE_ALL},
+     *            {@link ImportConfirmation#CONTINUE} are supported
+     */
+    protected void importFinish(ImportConfirmation confirmationMode) {
         SWTBotShell shell = fBot.activeShell();
         final SWTBotButton finishButton = fBot.button("Finish");
         finishButton.click();
+        if (confirmationMode == ImportConfirmation.RENAME_ALL) {
+            fBot.waitUntil(Conditions.shellIsActive("Confirmation"));
+            SWTBotShell shell2 = fBot.activeShell();
+            SWTBotButton button = shell2.bot().button("Rename All");
+            button.click();
+        } else if (confirmationMode == ImportConfirmation.OVERWRITE_ALL) {
+            fBot.waitUntil(Conditions.shellIsActive("Confirmation"));
+            SWTBotShell shell2 = fBot.activeShell();
+            SWTBotButton button = shell2.bot().button("Overwrite All");
+            button.click();
+        }
         fBot.waitUntil(Conditions.shellCloses(shell));
         SWTBotUtils.waitForJobs();
     }
 
     /**
-     * Gets the project Name
-     * @return the project name
+     * Checks finish button enablement
+     *
+     * @param isEnabled
+     *            state to check against
+     *
      */
-    protected abstract String getProjectName();
+    protected void checkFinishButton(boolean isEnabled) {
+        final SWTBotButton finishButton = fBot.button("Finish");
+        assertTrue(finishButton.isEnabled() == isEnabled);
+    }
 
     // ---------------------------------------------
     // Helpers for testing views
@@ -175,6 +210,7 @@ public abstract class AbstractImportAndReadSmokeTest {
 
     /**
      * Verifies the Histogram View
+     *
      * @param vp
      *            the view part
      * @param tmfEd
@@ -222,6 +258,7 @@ public abstract class AbstractImportAndReadSmokeTest {
 
     /**
      * Verifies the statistics view
+     *
      * @param vp
      *            the view part
      */
@@ -242,20 +279,18 @@ public abstract class AbstractImportAndReadSmokeTest {
      * @return the event at given rank
      */
     protected CtfTmfEvent getEvent(int rank) {
-        CtfTmfTrace trace = fTrace.getTrace();
-        ITmfContext ctx = trace.seekEvent(0);
-        for (int i = 0; i < rank; i++) {
-            trace.getNext(ctx);
-        }
+        CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(fTrace);
+        ITmfContext ctx = trace.seekEvent(rank);
         CtfTmfEvent ret = trace.getNext(ctx);
-        trace.dispose();
+        ctx.dispose();
         return ret;
     }
 
     /**
      * Gets a view part based on view title
+     *
      * @param viewTile
-     *              a view title
+     *            a view title
      * @return the view part
      */
     protected IViewPart getViewPart(final String viewTile) {
This page took 0.026106 seconds and 5 git commands to generate.