tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / AbstractImportAndReadSmokeTest.java
CommitLineData
2f7b3dd7 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 Ericsson
2f7b3dd7
BH
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 * (Extracted from ImportAndReadSmokeTest.java)
12 *******************************************************************************/
13
2bdf0193 14package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
2f7b3dd7
BH
15
16import static org.junit.Assert.assertNotNull;
40ba27e1 17import static org.junit.Assert.assertTrue;
2f7b3dd7
BH
18
19import java.util.List;
20
21import org.apache.log4j.Logger;
22import org.apache.log4j.varia.NullAppender;
c4d57ac1 23import org.eclipse.jdt.annotation.NonNull;
2f7b3dd7
BH
24import org.eclipse.jface.viewers.SelectionChangedEvent;
25import org.eclipse.jface.viewers.StructuredSelection;
26import org.eclipse.jface.wizard.Wizard;
2f7b3dd7
BH
27import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
28import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
29import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
30import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
31import org.eclipse.swtbot.swt.finder.results.VoidResult;
32import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
33import org.eclipse.swtbot.swt.finder.waits.Conditions;
34import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
2f7b3dd7
BH
35import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
36import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
37import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
38import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
39import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
c47c8803 40import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation;
1743f395 41import org.eclipse.tracecompass.internal.tmf.ui.views.statistics.TmfStatisticsViewImpl;
c4d57ac1 42import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
97c71024 43import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
2bdf0193 44import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
9722e5d7 45import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
c4d57ac1 46import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
9722e5d7 47import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
2bdf0193 48import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
fa24d78b
AM
49import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
50import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
f0beeb4a 51import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
2bdf0193 52import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
2f7b3dd7
BH
53import org.eclipse.ui.IViewPart;
54import org.eclipse.ui.IViewReference;
55import org.eclipse.ui.PlatformUI;
56import org.eclipse.ui.views.properties.PropertySheet;
f10c30a0 57import org.junit.AfterClass;
2f7b3dd7
BH
58import org.junit.BeforeClass;
59import org.junit.runner.RunWith;
60
61/**
62 * Abstract SWTBot Smoke test class.
63 *
64 * @author Matthew Khouzam
65 * @author Bernd Hufmann
66 */
67@RunWith(SWTBotJunit4ClassRunner.class)
68public abstract class AbstractImportAndReadSmokeTest {
69
70 /** Trace name */
93c91230
MAL
71 protected static final String TRACE_NAME = "scp_dest";
72 /** Trace folder */
73 protected static final String TRACE_FOLDER = "synctraces";
2f7b3dd7
BH
74 /** Trace type name for generic CTF traces */
75 protected static final String TRACE_TYPE_NAME = "Generic CTF Trace";
dea9c934 76 /** A Generic CTF Trace */
c4d57ac1 77 protected static final @NonNull CtfTestTrace fTrace = CtfTestTrace.SYNC_DEST;
2f7b3dd7
BH
78 /** SWT BOT workbench reference */
79 protected static SWTWorkbenchBot fBot;
80 /** Wizard to use */
81 protected static Wizard fWizard;
82
83 /** The Log4j logger instance. */
84 protected static final Logger fLogger = Logger.getRootLogger();
85
86 /** Test Class setup */
87 @BeforeClass
88 public static void init() {
5785ab49 89 SWTBotUtils.initialize();
2f7b3dd7
BH
90
91 /* set up for swtbot */
92 SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
f10c30a0 93 fLogger.removeAllAppenders();
2f7b3dd7
BH
94 fLogger.addAppender(new NullAppender());
95 fBot = new SWTWorkbenchBot();
96
fa24d78b 97 SWTBotUtils.closeView("welcome", fBot);
2f7b3dd7 98
fa24d78b 99 SWTBotUtils.switchToTracingPerspective();
2f7b3dd7 100 /* finish waiting for eclipse to load */
f0beeb4a 101 WaitUtils.waitForJobs();
2f7b3dd7
BH
102 }
103
f10c30a0
MK
104 /**
105 * Test Class teardown
106 */
107 @AfterClass
108 public static void terminate() {
109 fLogger.removeAllAppenders();
110 }
111
2f7b3dd7
BH
112 /**
113 * Creates a tracing projects
29fe7911
MAL
114 *
115 * @param traceProjectName
116 * the name of the test project
2f7b3dd7 117 */
29fe7911 118 protected static void createProject(String traceProjectName) {
fa24d78b 119 SWTBotUtils.focusMainWindow(fBot.shells());
2f7b3dd7
BH
120 fBot.menu("File").menu("New").menu("Project...").click();
121
8af624a8 122 fBot.shell("New Project").setFocus();
2f7b3dd7
BH
123 SWTBotTree tree = fBot.tree();
124 assertNotNull(tree);
125 final String tracingKey = "Tracing";
126 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(tracingKey, tree));
127 final SWTBotTreeItem tracingNode = tree.expandNode(tracingKey);
128
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);
134
135 tracingProject.select();
136 tracingProject.click();
137
138 SWTBotButton nextButton = fBot.button("Next >");
139 fBot.waitUntil(Conditions.widgetIsEnabled(nextButton));
140 nextButton.click();
8af624a8 141 fBot.shell("Tracing Project").setFocus();
2f7b3dd7
BH
142
143 final SWTBotText text = fBot.text();
29fe7911 144 text.setText(traceProjectName);
2f7b3dd7
BH
145
146 fBot.button("Finish").click();
f0beeb4a 147 WaitUtils.waitForJobs();
2f7b3dd7
BH
148 }
149
2f7b3dd7
BH
150 /**
151 * Finishes the wizard
152 */
153 protected void importFinish() {
c47c8803
BH
154 importFinish(ImportConfirmation.CONTINUE);
155 }
156
157 /**
158 * Finishes the wizard
159 *
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
165 */
166 protected void importFinish(ImportConfirmation confirmationMode) {
2f7b3dd7
BH
167 SWTBotShell shell = fBot.activeShell();
168 final SWTBotButton finishButton = fBot.button("Finish");
169 finishButton.click();
c47c8803
BH
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");
174 button.click();
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");
179 button.click();
180 }
2f7b3dd7 181 fBot.waitUntil(Conditions.shellCloses(shell));
f0beeb4a 182 WaitUtils.waitForJobs();
2f7b3dd7
BH
183 }
184
40ba27e1
BH
185 /**
186 * Checks finish button enablement
187 *
188 * @param isEnabled
189 * state to check against
190 *
191 */
192 protected void checkFinishButton(boolean isEnabled) {
193 final SWTBotButton finishButton = fBot.button("Finish");
194 assertTrue(finishButton.isEnabled() == isEnabled);
195 }
196
2f7b3dd7
BH
197 // ---------------------------------------------
198 // Helpers for testing views
199 // ---------------------------------------------
200
201 /**
202 * Verifies the properties view for a given view part
203 *
204 * @param vp
205 * a view part
206 */
207 protected void testPropertyView(IViewPart vp) {
208 PropertySheet pv = (PropertySheet) vp;
209 assertNotNull(pv);
210 }
211
212 /**
213 * Verifies the Histogram View
dea9c934 214 *
2f7b3dd7
BH
215 * @param vp
216 * the view part
217 * @param tmfEd
218 * the events editor
219 */
220 protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) {
221 final CtfTmfEvent desiredEvent1 = getEvent(100);
222 UIThreadRunnable.syncExec(new VoidResult() {
223 @Override
224 public void run() {
225 tmfEd.setFocus();
226 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1)));
227 }
228 });
229
f0beeb4a 230 WaitUtils.waitForJobs();
fa24d78b 231 SWTBotUtils.delay(1000);
2f7b3dd7
BH
232
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")) {
238 hvTool.click();
239 }
240 }
241 HistogramView hv = (HistogramView) vp;
97c71024
AM
242 final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent1.getTimestamp());
243 final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent2.getTimestamp());
2f7b3dd7 244 hv.updateTimeRange(100000);
f0beeb4a 245 WaitUtils.waitForJobs();
97c71024 246 hv.selectionRangeUpdated(signal);
2f7b3dd7 247 hv.broadcast(signal);
f0beeb4a 248 WaitUtils.waitForJobs();
fa24d78b 249 SWTBotUtils.delay(1000);
2f7b3dd7
BH
250
251 hv.updateTimeRange(1000000000);
f0beeb4a 252 WaitUtils.waitForJobs();
97c71024 253 hv.selectionRangeUpdated(signal2);
2f7b3dd7 254 hv.broadcast(signal2);
f0beeb4a 255 WaitUtils.waitForJobs();
fa24d78b 256 SWTBotUtils.delay(1000);
2f7b3dd7
BH
257 assertNotNull(hv);
258 }
259
260 /**
261 * Verifies the statistics view
dea9c934 262 *
2f7b3dd7
BH
263 * @param vp
264 * the view part
265 */
266 protected void testStatisticsView(IViewPart vp) {
1743f395 267 TmfStatisticsViewImpl sv = (TmfStatisticsViewImpl) vp;
2f7b3dd7
BH
268 assertNotNull(sv);
269 }
270
271 // ---------------------------------------------
272 // Trace helpers
273 // ---------------------------------------------
274
275 /**
276 * Gets an event at a given rank
0ff9e595 277 *
2f7b3dd7
BH
278 * @param rank
279 * a rank
280 * @return the event at given rank
281 */
282 protected CtfTmfEvent getEvent(int rank) {
c4d57ac1 283 CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(fTrace);
dea9c934 284 ITmfContext ctx = trace.seekEvent(rank);
0ff9e595 285 CtfTmfEvent ret = trace.getNext(ctx);
dea9c934 286 ctx.dispose();
0ff9e595 287 return ret;
2f7b3dd7
BH
288 }
289
290 /**
291 * Gets a view part based on view title
dea9c934 292 *
2f7b3dd7 293 * @param viewTile
dea9c934 294 * a view title
2f7b3dd7
BH
295 * @return the view part
296 */
297 protected IViewPart getViewPart(final String viewTile) {
298 final IViewPart[] vps = new IViewPart[1];
299 UIThreadRunnable.syncExec(new VoidResult() {
300 @Override
301 public void run() {
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)) {
306 vps[0] = vp;
307 return;
308 }
309 }
310 }
311 });
312
313 return vps[0];
314 }
315}
This page took 0.081113 seconds and 5 git commands to generate.