1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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
.Assert
.assertTrue
;
19 import java
.util
.List
;
21 import org
.apache
.log4j
.Logger
;
22 import org
.apache
.log4j
.varia
.NullAppender
;
23 import org
.eclipse
.jdt
.annotation
.NonNull
;
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
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportConfirmation
;
41 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.views
.statistics
.TmfStatisticsViewImpl
;
42 import org
.eclipse
.tracecompass
.testtraces
.ctf
.CtfTestTrace
;
43 import org
.eclipse
.tracecompass
.tmf
.core
.signal
.TmfSelectionRangeUpdatedSignal
;
44 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.ITmfContext
;
45 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.event
.CtfTmfEvent
;
46 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.tests
.shared
.CtfTmfTestTraceUtils
;
47 import org
.eclipse
.tracecompass
.tmf
.ctf
.core
.trace
.CtfTmfTrace
;
48 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
49 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
50 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
51 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.histogram
.HistogramView
;
52 import org
.eclipse
.ui
.IViewPart
;
53 import org
.eclipse
.ui
.IViewReference
;
54 import org
.eclipse
.ui
.PlatformUI
;
55 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
56 import org
.junit
.AfterClass
;
57 import org
.junit
.BeforeClass
;
58 import org
.junit
.runner
.RunWith
;
61 * Abstract SWTBot Smoke test class.
63 * @author Matthew Khouzam
64 * @author Bernd Hufmann
66 @RunWith(SWTBotJunit4ClassRunner
.class)
67 public abstract class AbstractImportAndReadSmokeTest
{
70 protected static final String TRACE_NAME
= "scp_dest";
72 protected static final String TRACE_FOLDER
= "synctraces";
73 /** Trace type name for generic CTF traces */
74 protected static final String TRACE_TYPE_NAME
= "Generic CTF Trace";
75 /** A Generic CTF Trace */
76 protected static final @NonNull CtfTestTrace fTrace
= CtfTestTrace
.SYNC_DEST
;
77 /** SWT BOT workbench reference */
78 protected static SWTWorkbenchBot fBot
;
80 protected static Wizard fWizard
;
82 /** The Log4j logger instance. */
83 protected static final Logger fLogger
= Logger
.getRootLogger();
85 /** Test Class setup */
87 public static void init() {
88 SWTBotUtils
.initialize();
90 /* set up for swtbot */
91 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
92 fLogger
.removeAllAppenders();
93 fLogger
.addAppender(new NullAppender());
94 fBot
= new SWTWorkbenchBot();
96 SWTBotUtils
.closeView("welcome", fBot
);
98 SWTBotUtils
.switchToTracingPerspective();
99 /* finish waiting for eclipse to load */
100 SWTBotUtils
.waitForJobs();
104 * Test Class teardown
107 public static void terminate() {
108 fLogger
.removeAllAppenders();
112 * Creates a tracing projects
114 * @param traceProjectName
115 * the name of the test project
117 protected static void createProject(String traceProjectName
) {
118 SWTBotUtils
.focusMainWindow(fBot
.shells());
119 fBot
.menu("File").menu("New").menu("Project...").click();
121 fBot
.shell("New Project").setFocus();
122 SWTBotTree tree
= fBot
.tree();
124 final String tracingKey
= "Tracing";
125 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
126 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
128 tracingNode
.select();
129 final String projectKey
= "Tracing Project";
130 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(projectKey
, tracingNode
));
131 final SWTBotTreeItem tracingProject
= tracingNode
.getNode(projectKey
);
132 assertNotNull(tracingProject
);
134 tracingProject
.select();
135 tracingProject
.click();
137 SWTBotButton nextButton
= fBot
.button("Next >");
138 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
140 fBot
.shell("Tracing Project").setFocus();
142 final SWTBotText text
= fBot
.text();
143 text
.setText(traceProjectName
);
145 fBot
.button("Finish").click();
146 SWTBotUtils
.waitForJobs();
150 * Finishes the wizard
152 protected void importFinish() {
153 importFinish(ImportConfirmation
.CONTINUE
);
157 * Finishes the wizard
159 * @param confirmationMode
160 * a confirmation value
161 * Note: Only {@link ImportConfirmation#RENAME_ALL},
162 * {@link ImportConfirmation#OVERWRITE_ALL},
163 * {@link ImportConfirmation#CONTINUE} are supported
165 protected void importFinish(ImportConfirmation confirmationMode
) {
166 SWTBotShell shell
= fBot
.activeShell();
167 final SWTBotButton finishButton
= fBot
.button("Finish");
168 finishButton
.click();
169 if (confirmationMode
== ImportConfirmation
.RENAME_ALL
) {
170 fBot
.waitUntil(Conditions
.shellIsActive("Confirmation"));
171 SWTBotShell shell2
= fBot
.activeShell();
172 SWTBotButton button
= shell2
.bot().button("Rename All");
174 } else if (confirmationMode
== ImportConfirmation
.OVERWRITE_ALL
) {
175 fBot
.waitUntil(Conditions
.shellIsActive("Confirmation"));
176 SWTBotShell shell2
= fBot
.activeShell();
177 SWTBotButton button
= shell2
.bot().button("Overwrite All");
180 fBot
.waitUntil(Conditions
.shellCloses(shell
));
181 SWTBotUtils
.waitForJobs();
185 * Checks finish button enablement
188 * state to check against
191 protected void checkFinishButton(boolean isEnabled
) {
192 final SWTBotButton finishButton
= fBot
.button("Finish");
193 assertTrue(finishButton
.isEnabled() == isEnabled
);
196 // ---------------------------------------------
197 // Helpers for testing views
198 // ---------------------------------------------
201 * Verifies the properties view for a given view part
206 protected void testPropertyView(IViewPart vp
) {
207 PropertySheet pv
= (PropertySheet
) vp
;
212 * Verifies the Histogram View
219 protected void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
220 final CtfTmfEvent desiredEvent1
= getEvent(100);
221 UIThreadRunnable
.syncExec(new VoidResult() {
225 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
229 SWTBotUtils
.waitForJobs();
230 SWTBotUtils
.delay(1000);
232 final CtfTmfEvent desiredEvent2
= getEvent(10000);
233 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
234 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
235 for (SWTBotToolbarButton hvTool
: hvTools
) {
236 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
240 HistogramView hv
= (HistogramView
) vp
;
241 final TmfSelectionRangeUpdatedSignal signal
= new TmfSelectionRangeUpdatedSignal(hv
, desiredEvent1
.getTimestamp());
242 final TmfSelectionRangeUpdatedSignal signal2
= new TmfSelectionRangeUpdatedSignal(hv
, desiredEvent2
.getTimestamp());
243 hv
.updateTimeRange(100000);
244 SWTBotUtils
.waitForJobs();
245 hv
.selectionRangeUpdated(signal
);
246 hv
.broadcast(signal
);
247 SWTBotUtils
.waitForJobs();
248 SWTBotUtils
.delay(1000);
250 hv
.updateTimeRange(1000000000);
251 SWTBotUtils
.waitForJobs();
252 hv
.selectionRangeUpdated(signal2
);
253 hv
.broadcast(signal2
);
254 SWTBotUtils
.waitForJobs();
255 SWTBotUtils
.delay(1000);
260 * Verifies the statistics view
265 protected void testStatisticsView(IViewPart vp
) {
266 TmfStatisticsViewImpl sv
= (TmfStatisticsViewImpl
) vp
;
270 // ---------------------------------------------
272 // ---------------------------------------------
275 * Gets an event at a given rank
279 * @return the event at given rank
281 protected CtfTmfEvent
getEvent(int rank
) {
282 CtfTmfTrace trace
= CtfTmfTestTraceUtils
.getTrace(fTrace
);
283 ITmfContext ctx
= trace
.seekEvent(rank
);
284 CtfTmfEvent ret
= trace
.getNext(ctx
);
290 * Gets a view part based on view title
294 * @return the view part
296 protected IViewPart
getViewPart(final String viewTile
) {
297 final IViewPart
[] vps
= new IViewPart
[1];
298 UIThreadRunnable
.syncExec(new VoidResult() {
301 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
302 for (IViewReference viewRef
: viewRefs
) {
303 IViewPart vp
= viewRef
.getView(true);
304 if (vp
.getTitle().equals(viewTile
)) {