204fef13e81d7dab7484dad7443b88341114f49d
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / AbstractImportAndReadSmokeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
14 package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
15
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertTrue;
18
19 import java.util.List;
20
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;
59
60 /**
61 * Abstract SWTBot Smoke test class.
62 *
63 * @author Matthew Khouzam
64 * @author Bernd Hufmann
65 */
66 @RunWith(SWTBotJunit4ClassRunner.class)
67 public abstract class AbstractImportAndReadSmokeTest {
68
69 /** Trace name */
70 protected static final String TRACE_NAME = "scp_dest";
71 /** Trace folder */
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;
79 /** Wizard to use */
80 protected static Wizard fWizard;
81
82 /** The Log4j logger instance. */
83 protected static final Logger fLogger = Logger.getRootLogger();
84
85 /** Test Class setup */
86 @BeforeClass
87 public static void init() {
88 SWTBotUtils.initialize();
89
90 /* set up for swtbot */
91 SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
92 fLogger.removeAllAppenders();
93 fLogger.addAppender(new NullAppender());
94 fBot = new SWTWorkbenchBot();
95
96 SWTBotUtils.closeView("welcome", fBot);
97
98 SWTBotUtils.switchToTracingPerspective();
99 /* finish waiting for eclipse to load */
100 SWTBotUtils.waitForJobs();
101 }
102
103 /**
104 * Test Class teardown
105 */
106 @AfterClass
107 public static void terminate() {
108 fLogger.removeAllAppenders();
109 }
110
111 /**
112 * Creates a tracing projects
113 *
114 * @param traceProjectName
115 * the name of the test project
116 */
117 protected static void createProject(String traceProjectName) {
118 SWTBotUtils.focusMainWindow(fBot.shells());
119 fBot.menu("File").menu("New").menu("Project...").click();
120
121 fBot.shell("New Project").setFocus();
122 SWTBotTree tree = fBot.tree();
123 assertNotNull(tree);
124 final String tracingKey = "Tracing";
125 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(tracingKey, tree));
126 final SWTBotTreeItem tracingNode = tree.expandNode(tracingKey);
127
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);
133
134 tracingProject.select();
135 tracingProject.click();
136
137 SWTBotButton nextButton = fBot.button("Next >");
138 fBot.waitUntil(Conditions.widgetIsEnabled(nextButton));
139 nextButton.click();
140 fBot.shell("Tracing Project").setFocus();
141
142 final SWTBotText text = fBot.text();
143 text.setText(traceProjectName);
144
145 fBot.button("Finish").click();
146 SWTBotUtils.waitForJobs();
147 }
148
149 /**
150 * Finishes the wizard
151 */
152 protected void importFinish() {
153 importFinish(ImportConfirmation.CONTINUE);
154 }
155
156 /**
157 * Finishes the wizard
158 *
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
164 */
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");
173 button.click();
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");
178 button.click();
179 }
180 fBot.waitUntil(Conditions.shellCloses(shell));
181 SWTBotUtils.waitForJobs();
182 }
183
184 /**
185 * Checks finish button enablement
186 *
187 * @param isEnabled
188 * state to check against
189 *
190 */
191 protected void checkFinishButton(boolean isEnabled) {
192 final SWTBotButton finishButton = fBot.button("Finish");
193 assertTrue(finishButton.isEnabled() == isEnabled);
194 }
195
196 // ---------------------------------------------
197 // Helpers for testing views
198 // ---------------------------------------------
199
200 /**
201 * Verifies the properties view for a given view part
202 *
203 * @param vp
204 * a view part
205 */
206 protected void testPropertyView(IViewPart vp) {
207 PropertySheet pv = (PropertySheet) vp;
208 assertNotNull(pv);
209 }
210
211 /**
212 * Verifies the Histogram View
213 *
214 * @param vp
215 * the view part
216 * @param tmfEd
217 * the events editor
218 */
219 protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) {
220 final CtfTmfEvent desiredEvent1 = getEvent(100);
221 UIThreadRunnable.syncExec(new VoidResult() {
222 @Override
223 public void run() {
224 tmfEd.setFocus();
225 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1)));
226 }
227 });
228
229 SWTBotUtils.waitForJobs();
230 SWTBotUtils.delay(1000);
231
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")) {
237 hvTool.click();
238 }
239 }
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);
249
250 hv.updateTimeRange(1000000000);
251 SWTBotUtils.waitForJobs();
252 hv.selectionRangeUpdated(signal2);
253 hv.broadcast(signal2);
254 SWTBotUtils.waitForJobs();
255 SWTBotUtils.delay(1000);
256 assertNotNull(hv);
257 }
258
259 /**
260 * Verifies the statistics view
261 *
262 * @param vp
263 * the view part
264 */
265 protected void testStatisticsView(IViewPart vp) {
266 TmfStatisticsViewImpl sv = (TmfStatisticsViewImpl) vp;
267 assertNotNull(sv);
268 }
269
270 // ---------------------------------------------
271 // Trace helpers
272 // ---------------------------------------------
273
274 /**
275 * Gets an event at a given rank
276 *
277 * @param rank
278 * a rank
279 * @return the event at given rank
280 */
281 protected CtfTmfEvent getEvent(int rank) {
282 CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(fTrace);
283 ITmfContext ctx = trace.seekEvent(rank);
284 CtfTmfEvent ret = trace.getNext(ctx);
285 ctx.dispose();
286 return ret;
287 }
288
289 /**
290 * Gets a view part based on view title
291 *
292 * @param viewTile
293 * a view title
294 * @return the view part
295 */
296 protected IViewPart getViewPart(final String viewTile) {
297 final IViewPart[] vps = new IViewPart[1];
298 UIThreadRunnable.syncExec(new VoidResult() {
299 @Override
300 public void run() {
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)) {
305 vps[0] = vp;
306 return;
307 }
308 }
309 }
310 });
311
312 return vps[0];
313 }
314 }
This page took 0.040171 seconds and 4 git commands to generate.