tmf: Remove equals()/hashCode() from TmfEventRequest
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / AbstractImportAndReadSmokeTest.java
CommitLineData
2f7b3dd7
BH
1/*******************************************************************************
2 * Copyright (c) 2014 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
2bdf0193 14package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
2f7b3dd7
BH
15
16import static org.junit.Assert.assertNotNull;
57adf00d 17import static org.junit.Assume.assumeTrue;
2f7b3dd7
BH
18
19import java.util.List;
20
21import org.apache.log4j.Logger;
22import org.apache.log4j.varia.NullAppender;
2f7b3dd7
BH
23import org.eclipse.jface.viewers.SelectionChangedEvent;
24import org.eclipse.jface.viewers.StructuredSelection;
25import org.eclipse.jface.wizard.Wizard;
2f7b3dd7
BH
26import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
27import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
28import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
29import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
30import org.eclipse.swtbot.swt.finder.results.VoidResult;
31import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
32import org.eclipse.swtbot.swt.finder.waits.Conditions;
33import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
2f7b3dd7
BH
34import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
35import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
36import org.eclipse.swtbot.swt.finder.widgets.SWTBotToolbarButton;
37import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
38import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
2bdf0193
AM
39import org.eclipse.tracecompass.tmf.core.signal.TmfTimeSynchSignal;
40import org.eclipse.tracecompass.tmf.core.trace.ITmfContext;
9722e5d7 41import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent;
2bdf0193 42import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
9722e5d7 43import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace;
2bdf0193 44import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
2bdf0193
AM
45import org.eclipse.tracecompass.tmf.ui.swtbot.tests.SWTBotUtil;
46import org.eclipse.tracecompass.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
47import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView;
48import org.eclipse.tracecompass.tmf.ui.views.statistics.TmfStatisticsView;
2f7b3dd7
BH
49import org.eclipse.ui.IViewPart;
50import org.eclipse.ui.IViewReference;
51import org.eclipse.ui.PlatformUI;
52import org.eclipse.ui.views.properties.PropertySheet;
53import org.junit.BeforeClass;
54import org.junit.runner.RunWith;
55
56/**
57 * Abstract SWTBot Smoke test class.
58 *
59 * @author Matthew Khouzam
60 * @author Bernd Hufmann
61 */
62@RunWith(SWTBotJunit4ClassRunner.class)
63public abstract class AbstractImportAndReadSmokeTest {
64
65 /** Trace name */
93c91230
MAL
66 protected static final String TRACE_NAME = "scp_dest";
67 /** Trace folder */
68 protected static final String TRACE_FOLDER = "synctraces";
2f7b3dd7
BH
69 /** Trace type name for generic CTF traces */
70 protected static final String TRACE_TYPE_NAME = "Generic CTF Trace";
71 /** A Generic CTF Trace*/
93c91230 72 protected static final CtfTmfTestTrace fTrace = CtfTmfTestTrace.SYNC_DEST;
2f7b3dd7
BH
73 /** SWT BOT workbench reference */
74 protected static SWTWorkbenchBot fBot;
75 /** Wizard to use */
76 protected static Wizard fWizard;
77
78 /** The Log4j logger instance. */
79 protected static final Logger fLogger = Logger.getRootLogger();
80
81 /** Test Class setup */
82 @BeforeClass
83 public static void init() {
57adf00d 84 assumeTrue(fTrace.exists());
2f7b3dd7
BH
85 SWTBotUtil.failIfUIThread();
86
87 /* set up for swtbot */
88 SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */
89 fLogger.addAppender(new NullAppender());
90 fBot = new SWTWorkbenchBot();
91
92 SWTBotUtil.closeView("welcome", fBot);
93
94 SWTBotUtil.switchToTracingPerspective();
95 /* finish waiting for eclipse to load */
96 SWTBotUtil.waitForJobs();
97 }
98
99 /**
100 * Creates a tracing projects
101 */
102 protected void createProject() {
103 SWTBotUtil.focusMainWindow(fBot.shells());
104 fBot.menu("File").menu("New").menu("Project...").click();
105
8af624a8 106 fBot.shell("New Project").setFocus();
2f7b3dd7
BH
107 SWTBotTree tree = fBot.tree();
108 assertNotNull(tree);
109 final String tracingKey = "Tracing";
110 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(tracingKey, tree));
111 final SWTBotTreeItem tracingNode = tree.expandNode(tracingKey);
112
113 tracingNode.select();
114 final String projectKey = "Tracing Project";
115 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(projectKey, tracingNode));
116 final SWTBotTreeItem tracingProject = tracingNode.getNode(projectKey);
117 assertNotNull(tracingProject);
118
119 tracingProject.select();
120 tracingProject.click();
121
122 SWTBotButton nextButton = fBot.button("Next >");
123 fBot.waitUntil(Conditions.widgetIsEnabled(nextButton));
124 nextButton.click();
8af624a8 125 fBot.shell("Tracing Project").setFocus();
2f7b3dd7
BH
126
127 final SWTBotText text = fBot.text();
128 text.setText(getProjectName());
129
130 fBot.button("Finish").click();
131 SWTBotUtil.waitForJobs();
132 }
133
2f7b3dd7
BH
134 /**
135 * Finishes the wizard
136 */
137 protected void importFinish() {
138 SWTBotShell shell = fBot.activeShell();
139 final SWTBotButton finishButton = fBot.button("Finish");
140 finishButton.click();
141 fBot.waitUntil(Conditions.shellCloses(shell));
142 SWTBotUtil.waitForJobs();
143 }
144
145 /**
146 * Gets the project Name
147 * @return the project name
148 */
149 protected abstract String getProjectName();
150
151 // ---------------------------------------------
152 // Helpers for testing views
153 // ---------------------------------------------
154
155 /**
156 * Verifies the properties view for a given view part
157 *
158 * @param vp
159 * a view part
160 */
161 protected void testPropertyView(IViewPart vp) {
162 PropertySheet pv = (PropertySheet) vp;
163 assertNotNull(pv);
164 }
165
166 /**
167 * Verifies the Histogram View
168 * @param vp
169 * the view part
170 * @param tmfEd
171 * the events editor
172 */
173 protected void testHistogramView(IViewPart vp, final TmfEventsEditor tmfEd) {
174 final CtfTmfEvent desiredEvent1 = getEvent(100);
175 UIThreadRunnable.syncExec(new VoidResult() {
176 @Override
177 public void run() {
178 tmfEd.setFocus();
179 tmfEd.selectionChanged(new SelectionChangedEvent(tmfEd, new StructuredSelection(desiredEvent1)));
180 }
181 });
182
183 SWTBotUtil.waitForJobs();
184 SWTBotUtil.delay(1000);
185
186 final CtfTmfEvent desiredEvent2 = getEvent(10000);
187 SWTBotView hvBot = fBot.viewById(HistogramView.ID);
188 List<SWTBotToolbarButton> hvTools = hvBot.getToolbarButtons();
189 for (SWTBotToolbarButton hvTool : hvTools) {
190 if (hvTool.getToolTipText().toLowerCase().contains("lost")) {
191 hvTool.click();
192 }
193 }
194 HistogramView hv = (HistogramView) vp;
195 final TmfTimeSynchSignal signal = new TmfTimeSynchSignal(hv, desiredEvent1.getTimestamp());
196 final TmfTimeSynchSignal signal2 = new TmfTimeSynchSignal(hv, desiredEvent2.getTimestamp());
197 hv.updateTimeRange(100000);
198 SWTBotUtil.waitForJobs();
199 hv.currentTimeUpdated(signal);
200 hv.broadcast(signal);
201 SWTBotUtil.waitForJobs();
202 SWTBotUtil.delay(1000);
203
204 hv.updateTimeRange(1000000000);
205 SWTBotUtil.waitForJobs();
206 hv.currentTimeUpdated(signal2);
207 hv.broadcast(signal2);
208 SWTBotUtil.waitForJobs();
209 SWTBotUtil.delay(1000);
210 assertNotNull(hv);
211 }
212
213 /**
214 * Verifies the statistics view
215 * @param vp
216 * the view part
217 */
218 protected void testStatisticsView(IViewPart vp) {
219 TmfStatisticsView sv = (TmfStatisticsView) vp;
220 assertNotNull(sv);
221 }
222
223 // ---------------------------------------------
224 // Trace helpers
225 // ---------------------------------------------
226
227 /**
228 * Gets an event at a given rank
229 * @param rank
230 * a rank
231 * @return the event at given rank
232 */
233 protected CtfTmfEvent getEvent(int rank) {
7b3eb8c0
AM
234 try (CtfTmfTrace trace = fTrace.getTrace()) {
235 ITmfContext ctx = trace.seekEvent(0);
236 for (int i = 0; i < rank; i++) {
237 trace.getNext(ctx);
238 }
239 return trace.getNext(ctx);
2f7b3dd7 240 }
2f7b3dd7
BH
241 }
242
243 /**
244 * Gets a view part based on view title
245 * @param viewTile
246 * a view title
247 * @return the view part
248 */
249 protected IViewPart getViewPart(final String viewTile) {
250 final IViewPart[] vps = new IViewPart[1];
251 UIThreadRunnable.syncExec(new VoidResult() {
252 @Override
253 public void run() {
254 IViewReference[] viewRefs = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
255 for (IViewReference viewRef : viewRefs) {
256 IViewPart vp = viewRef.getView(true);
257 if (vp.getTitle().equals(viewTile)) {
258 vps[0] = vp;
259 return;
260 }
261 }
262 }
263 });
264
265 return vps[0];
266 }
267}
This page took 0.051259 seconds and 5 git commands to generate.