Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc-Andre Laperle2014-12-08 03:34:46 +0000
committerMarc-Andre Laperle2014-12-08 22:28:53 +0000
commit42909904f30693e9e02e14337750877e316907c7 (patch)
treea95aa2304422a514b8b1fc328a5bf725785a1072
parentc4b089fa5df559d08f16296f6593a6bcc5058395 (diff)
downloadorg.eclipse.linuxtools-42909904f30693e9e02e14337750877e316907c7.tar.gz
org.eclipse.linuxtools-42909904f30693e9e02e14337750877e316907c7.tar.xz
org.eclipse.linuxtools-42909904f30693e9e02e14337750877e316907c7.zip
Add utility method to open a trace in the editor using SWTBot only
Change-Id: Ia98e7c029b46fdae4489e24ddfc0ee8c41963eb3 Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com> Reviewed-on: https://git.eclipse.org/r/37715 Tested-by: Hudson CI Reviewed-by: Matthew Khouzam <matthew.khouzam@ericsson.com> Tested-by: Matthew Khouzam <matthew.khouzam@ericsson.com>
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/AbstractImportAndReadSmokeTest.java69
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/ImportAndReadSmokeTest.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java2
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java74
-rw-r--r--lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java2
5 files changed, 75 insertions, 74 deletions
diff --git a/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/AbstractImportAndReadSmokeTest.java b/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/AbstractImportAndReadSmokeTest.java
index 12803adb19..677bcec4bf 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/AbstractImportAndReadSmokeTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/AbstractImportAndReadSmokeTest.java
@@ -20,7 +20,6 @@ import java.util.List;
import org.apache.log4j.Logger;
import org.apache.log4j.varia.NullAppender;
-import org.eclipse.core.runtime.IPath;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.StructuredSelection;
import org.eclipse.jface.wizard.Wizard;
@@ -30,7 +29,6 @@ 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;
@@ -48,9 +46,6 @@ 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.ui.IEditorPart;
-import org.eclipse.ui.IEditorReference;
-import org.eclipse.ui.IPageLayout;
import org.eclipse.ui.IViewPart;
import org.eclipse.ui.IViewReference;
import org.eclipse.ui.PlatformUI;
@@ -137,70 +132,6 @@ public abstract class AbstractImportAndReadSmokeTest {
}
/**
- * Opens and get the TmfEventsEditor
- *
- * @param elementPath
- * the trace element path (relative to Traces folder)
- * @return TmfEventsEditor
- */
- protected TmfEventsEditor openEditor(IPath elementPath) {
- final SWTBotView projectExplorerBot = fBot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
- projectExplorerBot.setFocus();
-
- final SWTBotTree tree = fBot.tree();
- final SWTBotTreeItem treeItem = tree.getTreeItem(getProjectName());
- treeItem.expand();
-
- String nodeName = getFullNodeName(treeItem, TmfTracesFolder.TRACES_FOLDER_NAME);
- fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, treeItem));
- SWTBotTreeItem tracesNode = treeItem.getNode(nodeName);
- tracesNode.expand();
-
- 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;
- }
-
- SWTBotUtil.delay(1000);
- SWTBotUtil.waitForJobs();
- final String expectedTitle = elementPath.toString();
-
- final IEditorPart iep[] = new IEditorPart[1];
- UIThreadRunnable.syncExec(new VoidResult() {
- @Override
- public void run() {
- IEditorReference[] ieds = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
- assertNotNull(ieds);
- iep[0] = null;
- for (IEditorReference ied : ieds) {
- if (ied.getTitle().equals(expectedTitle)) {
- iep[0] = ied.getEditor(true);
- break;
- }
- }
- }
- });
- assertNotNull(iep[0]);
- return (TmfEventsEditor) iep[0];
- }
-
- private static String getFullNodeName(final SWTBotTreeItem treeItem, String prefix) {
- List<String> nodes = treeItem.getNodes();
- String nodeName = "";
- for (String node : nodes) {
- if (node.startsWith(prefix)) {
- nodeName = node;
- }
- }
- return nodeName;
- }
-
- /**
* Finishes the wizard
*/
protected void importFinish() {
diff --git a/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/ImportAndReadSmokeTest.java b/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/ImportAndReadSmokeTest.java
index 717eb5a9dd..1118f59ba0 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/ImportAndReadSmokeTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/ImportAndReadSmokeTest.java
@@ -61,7 +61,7 @@ public class ImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
batchImportSelectTrace();
importFinish();
- TmfEventsEditor tmfEd = openEditor(new Path(TRACE_NAME));
+ TmfEventsEditor tmfEd = SWTBotUtil.openEditor(fBot, getProjectName(), new Path(TRACE_NAME));
testHistogramView(getViewPart("Histogram"), tmfEd);
testPropertyView(getViewPart("Properties"));
diff --git a/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java b/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java
index 3b245d3ed2..a1a2046c7e 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ctf/ui/swtbot/tests/StandardImportAndReadSmokeTest.java
@@ -150,7 +150,7 @@ public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTe
importFinish();
checkOptions(options);
- TmfEventsEditor tmfEd = openEditor(getTraceElementPath(options));
+ TmfEventsEditor tmfEd = SWTBotUtil.openEditor(fBot, getProjectName(), getTraceElementPath(options));
if (testViews) {
testViews(tmfEd);
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java b/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java
index 55224d9c67..f81eb00ff2 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/SWTBotUtil.java
@@ -21,12 +21,14 @@ import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfOpenTraceHelper;
import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
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.conditions.ConditionHelpers;
import org.eclipse.linuxtools.tmf.ui.views.TracingPerspectiveFactory;
import org.eclipse.swt.widgets.Display;
@@ -246,7 +248,7 @@ public abstract class SWTBotUtil {
}
/**
- * Opens an editor and sets focus to the editor
+ * Finds an editor and sets focus to the editor
*
* @param bot
* the workbench bot
@@ -254,7 +256,7 @@ public abstract class SWTBotUtil {
* the editor name
* @return the corresponding SWTBotEditor
*/
- public static SWTBotEditor openEditor(SWTWorkbenchBot bot, String editorName) {
+ public static SWTBotEditor activateEditor(SWTWorkbenchBot bot, String editorName) {
Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(editorName);
final SWTBotEditor editorBot = bot.editor(matcher);
IEditorPart iep = editorBot.getReference().getEditor(true);
@@ -272,4 +274,72 @@ public abstract class SWTBotUtil {
assertNotNull(tmfEd);
return editorBot;
}
+
+ /**
+ * Opens a trace in an editor and get the TmfEventsEditor
+ *
+ * @param bot
+ * the workbench bot
+ * @param projectName
+ * the name of the project that contains the trace
+ * @param elementPath
+ * the trace element path (relative to Traces folder)
+ * @return TmfEventsEditor the opened editor
+ */
+ public static TmfEventsEditor openEditor(SWTWorkbenchBot bot, String projectName, IPath elementPath) {
+ final SWTBotView projectExplorerBot = bot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
+ projectExplorerBot.setFocus();
+
+ final SWTBotTree tree = bot.tree();
+ final SWTBotTreeItem treeItem = tree.getTreeItem(projectName);
+ treeItem.expand();
+
+ String nodeName = getFullNodeName(treeItem, TmfTracesFolder.TRACES_FOLDER_NAME);
+ bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(nodeName, treeItem));
+ SWTBotTreeItem tracesNode = treeItem.getNode(nodeName);
+ tracesNode.expand();
+
+ SWTBotTreeItem currentNode = tracesNode;
+ for (String segment : elementPath.segments()) {
+ String fullNodeName = getFullNodeName(currentNode, segment);
+ bot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(fullNodeName, currentNode));
+ SWTBotTreeItem newNode = currentNode.getNode(fullNodeName);
+ newNode.select();
+ newNode.doubleClick();
+ currentNode = newNode;
+ }
+
+ SWTBotUtil.delay(1000);
+ SWTBotUtil.waitForJobs();
+ final String expectedTitle = elementPath.toString();
+
+ final IEditorPart iep[] = new IEditorPart[1];
+ UIThreadRunnable.syncExec(new VoidResult() {
+ @Override
+ public void run() {
+ IEditorReference[] ieds = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
+ assertNotNull(ieds);
+ iep[0] = null;
+ for (IEditorReference ied : ieds) {
+ if (ied.getTitle().equals(expectedTitle)) {
+ iep[0] = ied.getEditor(true);
+ break;
+ }
+ }
+ }
+ });
+ assertNotNull(iep[0]);
+ return (TmfEventsEditor) iep[0];
+ }
+
+ private static String getFullNodeName(final SWTBotTreeItem treeItem, String prefix) {
+ List<String> nodes = treeItem.getNodes();
+ String nodeName = "";
+ for (String node : nodes) {
+ if (node.startsWith(prefix)) {
+ nodeName = node;
+ }
+ }
+ return nodeName;
+ }
}
diff --git a/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java b/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java
index 95e4c328c0..852101c113 100644
--- a/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java
+++ b/lttng/org.eclipse.linuxtools.tmf.ui.swtbot.tests/src/org/eclipse/linuxtools/tmf/ui/swtbot/tests/table/CollapseEventsInTableTest.java
@@ -129,7 +129,7 @@ public class CollapseEventsInTableTest {
public void test() {
SWTBotUtil.createProject(TRACE_PROJECT_NAME);
SWTBotUtil.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLLAPSE_TRACE_TYPE);
- SWTBotEditor editorBot = SWTBotUtil.openEditor(fBot, fTestFile.getName());
+ SWTBotEditor editorBot = SWTBotUtil.activateEditor(fBot, fTestFile.getName());
SWTBotTable tableBot = editorBot.bot().table();

Back to the top