4a6a63e3901154ff5c990deff812d2ad91545a17
[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.views.statistics.TmfStatisticsViewImpl;
41 import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace;
42 import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal;
43 import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
44 import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
45 import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils;
46 import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
47 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
48 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
49 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
50 import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
51 import org.eclipse.ui.IViewPart;
52 import org.eclipse.ui.IViewReference;
53 import org.eclipse.ui.PlatformUI;
54 import org.eclipse.ui.views.properties.PropertySheet;
55 import org.junit.AfterClass;
56 import org.junit.BeforeClass;
57 import org.junit.runner.RunWith;
58
59 /**
60 * Abstract SWTBot Smoke test class.
61 *
62 * @author Matthew Khouzam
63 * @author Bernd Hufmann
64 */
65 @RunWith(SWTBotJunit4ClassRunner.class)
66 public abstract class AbstractImportAndReadSmokeTest {
67
68 /** Trace name */
69 protected static final String TRACE_NAME = "scp_dest";
70 /** Trace folder */
71 protected static final String TRACE_FOLDER = "synctraces";
72 /** Trace type name for generic CTF traces */
73 protected static final String TRACE_TYPE_NAME = "Generic CTF Trace";
74 /** A Generic CTF Trace */
75 protected static final @NonNull CtfTestTrace fTrace = CtfTestTrace.SYNC_DEST;
76 /** SWT BOT workbench reference */
77 protected static SWTWorkbenchBot fBot;
78 /** Wizard to use */
79 protected static Wizard fWizard;
80
81 /** The Log4j logger instance. */
82 protected static final Logger fLogger = Logger.getRootLogger();
83
84 /** Test Class setup */
85 @BeforeClass
86 public static void init() {
87 SWTBotUtils.initialize();
88
89 /* set up for swtbot */
90 SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
91 fLogger.removeAllAppenders();
92 fLogger.addAppender(new NullAppender());
93 fBot = new SWTWorkbenchBot();
94
95 SWTBotUtils.closeView("welcome", fBot);
96
97 SWTBotUtils.switchToTracingPerspective();
98 /* finish waiting for eclipse to load */
99 SWTBotUtils.waitForJobs();
100 }
101
102 /**
103 * Test Class teardown
104 */
105 @AfterClass
106 public static void terminate() {
107 fLogger.removeAllAppenders();
108 }
109
110 /**
111 * Creates a tracing projects
112 *
113 * @param traceProjectName
114 * the name of the test project
115 */
116 protected static void createProject(String traceProjectName) {
117 SWTBotUtils.focusMainWindow(fBot.shells());
118 fBot.menu("File").menu("New").menu("Project...").click();
119
120 fBot.shell("New Project").setFocus();
121 SWTBotTree tree = fBot.tree();
122 assertNotNull(tree);
123 final String tracingKey = "Tracing";
124 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(tracingKey, tree));
125 final SWTBotTreeItem tracingNode = tree.expandNode(tracingKey);
126
127 tracingNode.select();
128 final String projectKey = "Tracing Project";
129 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(projectKey, tracingNode));
130 final SWTBotTreeItem tracingProject = tracingNode.getNode(projectKey);
131 assertNotNull(tracingProject);
132
133 tracingProject.select();
134 tracingProject.click();
135
136 SWTBotButton nextButton = fBot.button("Next >");
137 fBot.waitUntil(Conditions.widgetIsEnabled(nextButton));
138 nextButton.click();
139 fBot.shell("Tracing Project").setFocus();
140
141 final SWTBotText text = fBot.text();
142 text.setText(traceProjectName);
143
144 fBot.button("Finish").click();
145 SWTBotUtils.waitForJobs();
146 }
147
148 /**
149 * Finishes the wizard
150 */
151 protected void importFinish() {
152 SWTBotShell shell = fBot.activeShell();
153 final SWTBotButton finishButton = fBot.button("Finish");
154 finishButton.click();
155 fBot.waitUntil(Conditions.shellCloses(shell));
156 SWTBotUtils.waitForJobs();
157 }
158
159 /**
160 * Checks finish button enablement
161 *
162 * @param isEnabled
163 * state to check against
164 *
165 */
166 protected void checkFinishButton(boolean isEnabled) {
167 final SWTBotButton finishButton = fBot.button("Finish");
168 assertTrue(finishButton.isEnabled() == isEnabled);
169 }
170
171 // ---------------------------------------------
172 // Helpers for testing views
173 // ---------------------------------------------
174
175 /**
176 * Verifies the properties view for a given view part
177 *
178 * @param vp
179 * a view part
180 */
181 protected void testPropertyView(IViewPart vp) {
182 PropertySheet pv = (PropertySheet) vp;
183 assertNotNull(pv);
184 }
185
186 /**
187 * Verifies the Histogram View
188 *
189 * @param vp
190 * the view part
191 * @param tmfEd
192 * the events editor
193 */
194 protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) {
195 final CtfTmfEvent desiredEvent1 = getEvent(100);
196 UIThreadRunnable.syncExec(new VoidResult() {
197 @Override
198 public void run() {
199 tmfEd.setFocus();
200 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1)));
201 }
202 });
203
204 SWTBotUtils.waitForJobs();
205 SWTBotUtils.delay(1000);
206
207 final CtfTmfEvent desiredEvent2 = getEvent(10000);
208 SWTBotView hvBot = fBot.viewById(HistogramView.ID);
209 List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons();
210 for (SWTBotToolbarButton hvTool : hvTools) {
211 if (hvTool.getToolTipText().toLowerCase().contains("lost")) {
212 hvTool.click();
213 }
214 }
215 HistogramView hv = (HistogramView) vp;
216 final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent1.getTimestamp());
217 final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent2.getTimestamp());
218 hv.updateTimeRange(100000);
219 SWTBotUtils.waitForJobs();
220 hv.selectionRangeUpdated(signal);
221 hv.broadcast(signal);
222 SWTBotUtils.waitForJobs();
223 SWTBotUtils.delay(1000);
224
225 hv.updateTimeRange(1000000000);
226 SWTBotUtils.waitForJobs();
227 hv.selectionRangeUpdated(signal2);
228 hv.broadcast(signal2);
229 SWTBotUtils.waitForJobs();
230 SWTBotUtils.delay(1000);
231 assertNotNull(hv);
232 }
233
234 /**
235 * Verifies the statistics view
236 *
237 * @param vp
238 * the view part
239 */
240 protected void testStatisticsView(IViewPart vp) {
241 TmfStatisticsViewImpl sv = (TmfStatisticsViewImpl) vp;
242 assertNotNull(sv);
243 }
244
245 // ---------------------------------------------
246 // Trace helpers
247 // ---------------------------------------------
248
249 /**
250 * Gets an event at a given rank
251 *
252 * @param rank
253 * a rank
254 * @return the event at given rank
255 */
256 protected CtfTmfEvent getEvent(int rank) {
257 CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(fTrace);
258 ITmfContext ctx = trace.seekEvent(rank);
259 CtfTmfEvent ret = trace.getNext(ctx);
260 ctx.dispose();
261 return ret;
262 }
263
264 /**
265 * Gets a view part based on view title
266 *
267 * @param viewTile
268 * a view title
269 * @return the view part
270 */
271 protected IViewPart getViewPart(final String viewTile) {
272 final IViewPart[] vps = new IViewPart[1];
273 UIThreadRunnable.syncExec(new VoidResult() {
274 @Override
275 public void run() {
276 IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
277 for (IViewReference viewRef : viewRefs) {
278 IViewPart vp = viewRef.getView(true);
279 if (vp.getTitle().equals(viewTile)) {
280 vps[0] = vp;
281 return;
282 }
283 }
284 }
285 });
286
287 return vps[0];
288 }
289 }
This page took 0.044933 seconds and 4 git commands to generate.