1 /*******************************************************************************
2 * Copyright (c) 2014 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Bernd Hufmann - Initial API and implementation
11 * (Extracted from ImportAndReadSmokeTest.java)
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
;
16 import static org
.junit
.Assert
.assertNotNull
;
17 import static org
.junit
.Assume
.assumeTrue
;
19 import java
.util
.List
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.apache
.log4j
.varia
.NullAppender
;
23 import org
.eclipse
.core
.runtime
.IPath
;
24 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
25 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
26 import org
.eclipse
.jface
.wizard
.Wizard
;
27 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
28 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
29 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
30 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
31 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
32 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
33 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
34 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotButton
;
35 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
36 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
37 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
38 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
39 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
40 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfTimeSynchSignal
;
41 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
42 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfTmfEvent
;
43 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.CtfTmfTrace
;
44 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTrace
;
45 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
46 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTracesFolder
;
47 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.SWTBotUtil
;
48 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.conditions
.ConditionHelpers
;
49 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.histogram
.HistogramView
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.statistics
.TmfStatisticsView
;
51 import org
.eclipse
.ui
.IEditorPart
;
52 import org
.eclipse
.ui
.IEditorReference
;
53 import org
.eclipse
.ui
.IPageLayout
;
54 import org
.eclipse
.ui
.IViewPart
;
55 import org
.eclipse
.ui
.IViewReference
;
56 import org
.eclipse
.ui
.PlatformUI
;
57 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
58 import org
.junit
.BeforeClass
;
59 import org
.junit
.runner
.RunWith
;
62 * Abstract SWTBot Smoke test class.
64 * @author Matthew Khouzam
65 * @author Bernd Hufmann
67 @RunWith(SWTBotJunit4ClassRunner
.class)
68 public abstract class AbstractImportAndReadSmokeTest
{
71 protected static final String TRACE_NAME
= "scp_dest";
73 protected static final String TRACE_FOLDER
= "synctraces";
74 /** Trace type name for generic CTF traces */
75 protected static final String TRACE_TYPE_NAME
= "Generic CTF Trace";
76 /** A Generic CTF Trace*/
77 protected static final CtfTmfTestTrace fTrace
= CtfTmfTestTrace
.SYNC_DEST
;
78 /** SWT BOT workbench reference */
79 protected static SWTWorkbenchBot fBot
;
81 protected static Wizard fWizard
;
83 /** The Log4j logger instance. */
84 protected static final Logger fLogger
= Logger
.getRootLogger();
86 /** Test Class setup */
88 public static void init() {
89 assumeTrue(fTrace
.exists());
90 SWTBotUtil
.failIfUIThread();
92 /* set up for swtbot */
93 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
94 fLogger
.addAppender(new NullAppender());
95 fBot
= new SWTWorkbenchBot();
97 SWTBotUtil
.closeView("welcome", fBot
);
99 SWTBotUtil
.switchToTracingPerspective();
100 /* finish waiting for eclipse to load */
101 SWTBotUtil
.waitForJobs();
105 * Creates a tracing projects
107 protected void createProject() {
108 SWTBotUtil
.focusMainWindow(fBot
.shells());
109 fBot
.menu("File").menu("New").menu("Project...").click();
111 fBot
.shell("New Project").setFocus();
112 SWTBotTree tree
= fBot
.tree();
114 final String tracingKey
= "Tracing";
115 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
116 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
118 tracingNode
.select();
119 final String projectKey
= "Tracing Project";
120 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(projectKey
, tracingNode
));
121 final SWTBotTreeItem tracingProject
= tracingNode
.getNode(projectKey
);
122 assertNotNull(tracingProject
);
124 tracingProject
.select();
125 tracingProject
.click();
127 SWTBotButton nextButton
= fBot
.button("Next >");
128 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
130 fBot
.shell("Tracing Project").setFocus();
132 final SWTBotText text
= fBot
.text();
133 text
.setText(getProjectName());
135 fBot
.button("Finish").click();
136 SWTBotUtil
.waitForJobs();
140 * Opens and get the TmfEventsEditor
143 * the trace element path (relative to Traces folder)
144 * @return TmfEventsEditor
146 protected TmfEventsEditor
openEditor(IPath elementPath
) {
147 final SWTBotView projectExplorerBot
= fBot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
148 projectExplorerBot
.setFocus();
150 final SWTBotTree tree
= fBot
.tree();
151 final SWTBotTreeItem treeItem
= tree
.getTreeItem(getProjectName());
154 String nodeName
= getFullNodeName(treeItem
, TmfTracesFolder
.TRACES_FOLDER_NAME
);
155 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(nodeName
, treeItem
));
156 SWTBotTreeItem tracesNode
= treeItem
.getNode(nodeName
);
159 SWTBotTreeItem currentNode
= tracesNode
;
160 for (String segment
: elementPath
.segments()) {
161 String fullNodeName
= getFullNodeName(currentNode
, segment
);
162 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(fullNodeName
, currentNode
));
163 SWTBotTreeItem newNode
= currentNode
.getNode(fullNodeName
);
165 newNode
.doubleClick();
166 currentNode
= newNode
;
169 SWTBotUtil
.delay(1000);
170 SWTBotUtil
.waitForJobs();
171 final String expectedTitle
= elementPath
.toString();
173 final IEditorPart iep
[] = new IEditorPart
[1];
174 UIThreadRunnable
.syncExec(new VoidResult() {
177 IEditorReference
[] ieds
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
180 for (IEditorReference ied
: ieds
) {
181 if (ied
.getTitle().equals(expectedTitle
)) {
182 iep
[0] = ied
.getEditor(true);
188 assertNotNull(iep
[0]);
189 return (TmfEventsEditor
) iep
[0];
192 private static String
getFullNodeName(final SWTBotTreeItem treeItem
, String prefix
) {
193 List
<String
> nodes
= treeItem
.getNodes();
194 String nodeName
= "";
195 for (String node
: nodes
) {
196 if (node
.startsWith(prefix
)) {
204 * Finishes the wizard
206 protected void importFinish() {
207 SWTBotShell shell
= fBot
.activeShell();
208 final SWTBotButton finishButton
= fBot
.button("Finish");
209 finishButton
.click();
210 fBot
.waitUntil(Conditions
.shellCloses(shell
));
211 SWTBotUtil
.waitForJobs();
215 * Gets the project Name
216 * @return the project name
218 protected abstract String
getProjectName();
220 // ---------------------------------------------
221 // Helpers for testing views
222 // ---------------------------------------------
225 * Verifies the properties view for a given view part
230 protected void testPropertyView(IViewPart vp
) {
231 PropertySheet pv
= (PropertySheet
) vp
;
236 * Verifies the Histogram View
242 protected void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
243 final CtfTmfEvent desiredEvent1
= getEvent(100);
244 UIThreadRunnable
.syncExec(new VoidResult() {
248 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
252 SWTBotUtil
.waitForJobs();
253 SWTBotUtil
.delay(1000);
255 final CtfTmfEvent desiredEvent2
= getEvent(10000);
256 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
257 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
258 for (SWTBotToolbarButton hvTool
: hvTools
) {
259 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
263 HistogramView hv
= (HistogramView
) vp
;
264 final TmfTimeSynchSignal signal
= new TmfTimeSynchSignal(hv
, desiredEvent1
.getTimestamp());
265 final TmfTimeSynchSignal signal2
= new TmfTimeSynchSignal(hv
, desiredEvent2
.getTimestamp());
266 hv
.updateTimeRange(100000);
267 SWTBotUtil
.waitForJobs();
268 hv
.currentTimeUpdated(signal
);
269 hv
.broadcast(signal
);
270 SWTBotUtil
.waitForJobs();
271 SWTBotUtil
.delay(1000);
273 hv
.updateTimeRange(1000000000);
274 SWTBotUtil
.waitForJobs();
275 hv
.currentTimeUpdated(signal2
);
276 hv
.broadcast(signal2
);
277 SWTBotUtil
.waitForJobs();
278 SWTBotUtil
.delay(1000);
283 * Verifies the statistics view
287 protected void testStatisticsView(IViewPart vp
) {
288 TmfStatisticsView sv
= (TmfStatisticsView
) vp
;
292 // ---------------------------------------------
294 // ---------------------------------------------
297 * Gets an event at a given rank
300 * @return the event at given rank
302 protected CtfTmfEvent
getEvent(int rank
) {
303 try (CtfTmfTrace trace
= fTrace
.getTrace()) {
304 ITmfContext ctx
= trace
.seekEvent(0);
305 for (int i
= 0; i
< rank
; i
++) {
308 return trace
.getNext(ctx
);
313 * Gets a view part based on view title
316 * @return the view part
318 protected IViewPart
getViewPart(final String viewTile
) {
319 final IViewPart
[] vps
= new IViewPart
[1];
320 UIThreadRunnable
.syncExec(new VoidResult() {
323 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
324 for (IViewReference viewRef
: viewRefs
) {
325 IViewPart vp
= viewRef
.getView(true);
326 if (vp
.getTitle().equals(viewTile
)) {