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
.tests
.shared
.WaitUtils
;
52 import org
.eclipse
.tracecompass
.tmf
.ui
.views
.histogram
.HistogramView
;
53 import org
.eclipse
.ui
.IViewPart
;
54 import org
.eclipse
.ui
.IViewReference
;
55 import org
.eclipse
.ui
.PlatformUI
;
56 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
57 import org
.junit
.AfterClass
;
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 @NonNull CtfTestTrace fTrace
= CtfTestTrace
.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 SWTBotUtils
.initialize();
91 /* set up for swtbot */
92 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
93 fLogger
.removeAllAppenders();
94 fLogger
.addAppender(new NullAppender());
95 fBot
= new SWTWorkbenchBot();
97 SWTBotUtils
.closeView("welcome", fBot
);
99 SWTBotUtils
.switchToTracingPerspective();
100 /* finish waiting for eclipse to load */
101 WaitUtils
.waitForJobs();
105 * Test Class teardown
108 public static void terminate() {
109 fLogger
.removeAllAppenders();
113 * Creates a tracing projects
115 * @param traceProjectName
116 * the name of the test project
118 protected static void createProject(String traceProjectName
) {
119 SWTBotUtils
.focusMainWindow(fBot
.shells());
120 fBot
.menu("File").menu("New").menu("Project...").click();
122 fBot
.shell("New Project").setFocus();
123 SWTBotTree tree
= fBot
.tree();
125 final String tracingKey
= "Tracing";
126 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
127 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
129 tracingNode
.select();
130 final String projectKey
= "Tracing Project";
131 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(projectKey
, tracingNode
));
132 final SWTBotTreeItem tracingProject
= tracingNode
.getNode(projectKey
);
133 assertNotNull(tracingProject
);
135 tracingProject
.select();
136 tracingProject
.click();
138 SWTBotButton nextButton
= fBot
.button("Next >");
139 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
141 fBot
.shell("Tracing Project").setFocus();
143 final SWTBotText text
= fBot
.text();
144 text
.setText(traceProjectName
);
146 fBot
.button("Finish").click();
147 WaitUtils
.waitForJobs();
151 * Finishes the wizard
153 protected void importFinish() {
154 importFinish(ImportConfirmation
.CONTINUE
);
158 * Finishes the wizard
160 * @param confirmationMode
161 * a confirmation value
162 * Note: Only {@link ImportConfirmation#RENAME_ALL},
163 * {@link ImportConfirmation#OVERWRITE_ALL},
164 * {@link ImportConfirmation#CONTINUE} are supported
166 protected void importFinish(ImportConfirmation confirmationMode
) {
167 SWTBotShell shell
= fBot
.activeShell();
168 final SWTBotButton finishButton
= fBot
.button("Finish");
169 finishButton
.click();
170 if (confirmationMode
== ImportConfirmation
.RENAME_ALL
) {
171 fBot
.waitUntil(Conditions
.shellIsActive("Confirmation"));
172 SWTBotShell shell2
= fBot
.activeShell();
173 SWTBotButton button
= shell2
.bot().button("Rename All");
175 } else if (confirmationMode
== ImportConfirmation
.OVERWRITE_ALL
) {
176 fBot
.waitUntil(Conditions
.shellIsActive("Confirmation"));
177 SWTBotShell shell2
= fBot
.activeShell();
178 SWTBotButton button
= shell2
.bot().button("Overwrite All");
181 fBot
.waitUntil(Conditions
.shellCloses(shell
));
182 WaitUtils
.waitForJobs();
186 * Checks finish button enablement
189 * state to check against
192 protected void checkFinishButton(boolean isEnabled
) {
193 final SWTBotButton finishButton
= fBot
.button("Finish");
194 assertTrue(finishButton
.isEnabled() == isEnabled
);
197 // ---------------------------------------------
198 // Helpers for testing views
199 // ---------------------------------------------
202 * Verifies the properties view for a given view part
207 protected void testPropertyView(IViewPart vp
) {
208 PropertySheet pv
= (PropertySheet
) vp
;
213 * Verifies the Histogram View
220 protected void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
221 final CtfTmfEvent desiredEvent1
= getEvent(100);
222 UIThreadRunnable
.syncExec(new VoidResult() {
226 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
230 WaitUtils
.waitForJobs();
231 SWTBotUtils
.delay(1000);
233 final CtfTmfEvent desiredEvent2
= getEvent(10000);
234 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
235 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
236 for (SWTBotToolbarButton hvTool
: hvTools
) {
237 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
241 HistogramView hv
= (HistogramView
) vp
;
242 final TmfSelectionRangeUpdatedSignal signal
= new TmfSelectionRangeUpdatedSignal(hv
, desiredEvent1
.getTimestamp());
243 final TmfSelectionRangeUpdatedSignal signal2
= new TmfSelectionRangeUpdatedSignal(hv
, desiredEvent2
.getTimestamp());
244 hv
.updateTimeRange(100000);
245 WaitUtils
.waitForJobs();
246 hv
.selectionRangeUpdated(signal
);
247 hv
.broadcast(signal
);
248 WaitUtils
.waitForJobs();
249 SWTBotUtils
.delay(1000);
251 hv
.updateTimeRange(1000000000);
252 WaitUtils
.waitForJobs();
253 hv
.selectionRangeUpdated(signal2
);
254 hv
.broadcast(signal2
);
255 WaitUtils
.waitForJobs();
256 SWTBotUtils
.delay(1000);
261 * Verifies the statistics view
266 protected void testStatisticsView(IViewPart vp
) {
267 TmfStatisticsViewImpl sv
= (TmfStatisticsViewImpl
) vp
;
271 // ---------------------------------------------
273 // ---------------------------------------------
276 * Gets an event at a given rank
280 * @return the event at given rank
282 protected CtfTmfEvent
getEvent(int rank
) {
283 CtfTmfTrace trace
= CtfTmfTestTraceUtils
.getTrace(fTrace
);
284 ITmfContext ctx
= trace
.seekEvent(rank
);
285 CtfTmfEvent ret
= trace
.getNext(ctx
);
291 * Gets a view part based on view title
295 * @return the view part
297 protected IViewPart
getViewPart(final String viewTile
) {
298 final IViewPart
[] vps
= new IViewPart
[1];
299 UIThreadRunnable
.syncExec(new VoidResult() {
302 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
303 for (IViewReference viewRef
: viewRefs
) {
304 IViewPart vp
= viewRef
.getView(true);
305 if (vp
.getTitle().equals(viewTile
)) {