Commit | Line | Data |
---|---|---|
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 | 14 | package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests; |
2f7b3dd7 BH |
15 | |
16 | import static org.junit.Assert.assertNotNull; | |
40ba27e1 | 17 | import static org.junit.Assert.assertTrue; |
2f7b3dd7 BH |
18 | |
19 | import java.util.List; | |
20 | ||
21 | import org.apache.log4j.Logger; | |
22 | import org.apache.log4j.varia.NullAppender; | |
c4d57ac1 | 23 | import org.eclipse.jdt.annotation.NonNull; |
2f7b3dd7 BH |
24 | import org.eclipse.jface.viewers.SelectionChangedEvent; |
25 | import org.eclipse.jface.viewers.StructuredSelection; | |
26 | import org.eclipse.jface.wizard.Wizard; | |
2f7b3dd7 BH |
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; | |
2f7b3dd7 BH |
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; | |
c47c8803 | 40 | import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation; |
1743f395 | 41 | import org.eclipse.tracecompass.internal.tmf.ui.views.statistics.TmfStatisticsViewImpl; |
c4d57ac1 | 42 | import org.eclipse.tracecompass.testtraces.ctf.CtfTestTrace; |
97c71024 | 43 | import org.eclipse.tracecompass.tmf.core.signal.TmfSelectionRangeUpdatedSignal; |
2bdf0193 | 44 | import org.eclipse.tracecompass.tmf.core.trace.ITmfContext; |
9722e5d7 | 45 | import org.eclipse.tracecompass.tmf.ctf.core.event.CtfTmfEvent; |
c4d57ac1 | 46 | import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTraceUtils; |
9722e5d7 | 47 | import org.eclipse.tracecompass.tmf.ctf.core.trace.CtfTmfTrace; |
2bdf0193 | 48 | import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
fa24d78b AM |
49 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
50 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
2bdf0193 | 51 | import org.eclipse.tracecompass.tmf.ui.views.histogram.HistogramView; |
2f7b3dd7 BH |
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; | |
f10c30a0 | 56 | import org.junit.AfterClass; |
2f7b3dd7 BH |
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 */ | |
93c91230 MAL |
70 | protected static final String TRACE_NAME = "scp_dest"; |
71 | /** Trace folder */ | |
72 | protected static final String TRACE_FOLDER = "synctraces"; | |
2f7b3dd7 BH |
73 | /** Trace type name for generic CTF traces */ |
74 | protected static final String TRACE_TYPE_NAME = "Generic CTF Trace"; | |
dea9c934 | 75 | /** A Generic CTF Trace */ |
c4d57ac1 | 76 | protected static final @NonNull CtfTestTrace fTrace = CtfTestTrace.SYNC_DEST; |
2f7b3dd7 BH |
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() { | |
5785ab49 | 88 | SWTBotUtils.initialize(); |
2f7b3dd7 BH |
89 | |
90 | /* set up for swtbot */ | |
91 | SWTBotPreferences.TIMEOUT = 50000; /* 50 second timeout */ | |
f10c30a0 | 92 | fLogger.removeAllAppenders(); |
2f7b3dd7 BH |
93 | fLogger.addAppender(new NullAppender()); |
94 | fBot = new SWTWorkbenchBot(); | |
95 | ||
fa24d78b | 96 | SWTBotUtils.closeView("welcome", fBot); |
2f7b3dd7 | 97 | |
fa24d78b | 98 | SWTBotUtils.switchToTracingPerspective(); |
2f7b3dd7 | 99 | /* finish waiting for eclipse to load */ |
fa24d78b | 100 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
101 | } |
102 | ||
f10c30a0 MK |
103 | /** |
104 | * Test Class teardown | |
105 | */ | |
106 | @AfterClass | |
107 | public static void terminate() { | |
108 | fLogger.removeAllAppenders(); | |
109 | } | |
110 | ||
2f7b3dd7 BH |
111 | /** |
112 | * Creates a tracing projects | |
29fe7911 MAL |
113 | * |
114 | * @param traceProjectName | |
115 | * the name of the test project | |
2f7b3dd7 | 116 | */ |
29fe7911 | 117 | protected static void createProject(String traceProjectName) { |
fa24d78b | 118 | SWTBotUtils.focusMainWindow(fBot.shells()); |
2f7b3dd7 BH |
119 | fBot.menu("File").menu("New").menu("Project...").click(); |
120 | ||
8af624a8 | 121 | fBot.shell("New Project").setFocus(); |
2f7b3dd7 BH |
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(); | |
8af624a8 | 140 | fBot.shell("Tracing Project").setFocus(); |
2f7b3dd7 BH |
141 | |
142 | final SWTBotText text = fBot.text(); | |
29fe7911 | 143 | text.setText(traceProjectName); |
2f7b3dd7 BH |
144 | |
145 | fBot.button("Finish").click(); | |
fa24d78b | 146 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
147 | } |
148 | ||
2f7b3dd7 BH |
149 | /** |
150 | * Finishes the wizard | |
151 | */ | |
152 | protected void importFinish() { | |
c47c8803 BH |
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) { | |
2f7b3dd7 BH |
166 | SWTBotShell shell = fBot.activeShell(); |
167 | final SWTBotButton finishButton = fBot.button("Finish"); | |
168 | finishButton.click(); | |
c47c8803 BH |
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 | } | |
2f7b3dd7 | 180 | fBot.waitUntil(Conditions.shellCloses(shell)); |
fa24d78b | 181 | SWTBotUtils.waitForJobs(); |
2f7b3dd7 BH |
182 | } |
183 | ||
40ba27e1 BH |
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 | ||
2f7b3dd7 BH |
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 | |
dea9c934 | 213 | * |
2f7b3dd7 BH |
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 | ||
fa24d78b AM |
229 | SWTBotUtils.waitForJobs(); |
230 | SWTBotUtils.delay(1000); | |
2f7b3dd7 BH |
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; | |
97c71024 AM |
241 | final TmfSelectionRangeUpdatedSignal signal = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent1.getTimestamp()); |
242 | final TmfSelectionRangeUpdatedSignal signal2 = new TmfSelectionRangeUpdatedSignal(hv, desiredEvent2.getTimestamp()); | |
2f7b3dd7 | 243 | hv.updateTimeRange(100000); |
fa24d78b | 244 | SWTBotUtils.waitForJobs(); |
97c71024 | 245 | hv.selectionRangeUpdated(signal); |
2f7b3dd7 | 246 | hv.broadcast(signal); |
fa24d78b AM |
247 | SWTBotUtils.waitForJobs(); |
248 | SWTBotUtils.delay(1000); | |
2f7b3dd7 BH |
249 | |
250 | hv.updateTimeRange(1000000000); | |
fa24d78b | 251 | SWTBotUtils.waitForJobs(); |
97c71024 | 252 | hv.selectionRangeUpdated(signal2); |
2f7b3dd7 | 253 | hv.broadcast(signal2); |
fa24d78b AM |
254 | SWTBotUtils.waitForJobs(); |
255 | SWTBotUtils.delay(1000); | |
2f7b3dd7 BH |
256 | assertNotNull(hv); |
257 | } | |
258 | ||
259 | /** | |
260 | * Verifies the statistics view | |
dea9c934 | 261 | * |
2f7b3dd7 BH |
262 | * @param vp |
263 | * the view part | |
264 | */ | |
265 | protected void testStatisticsView(IViewPart vp) { | |
1743f395 | 266 | TmfStatisticsViewImpl sv = (TmfStatisticsViewImpl) vp; |
2f7b3dd7 BH |
267 | assertNotNull(sv); |
268 | } | |
269 | ||
270 | // --------------------------------------------- | |
271 | // Trace helpers | |
272 | // --------------------------------------------- | |
273 | ||
274 | /** | |
275 | * Gets an event at a given rank | |
0ff9e595 | 276 | * |
2f7b3dd7 BH |
277 | * @param rank |
278 | * a rank | |
279 | * @return the event at given rank | |
280 | */ | |
281 | protected CtfTmfEvent getEvent(int rank) { | |
c4d57ac1 | 282 | CtfTmfTrace trace = CtfTmfTestTraceUtils.getTrace(fTrace); |
dea9c934 | 283 | ITmfContext ctx = trace.seekEvent(rank); |
0ff9e595 | 284 | CtfTmfEvent ret = trace.getNext(ctx); |
dea9c934 | 285 | ctx.dispose(); |
0ff9e595 | 286 | return ret; |
2f7b3dd7 BH |
287 | } |
288 | ||
289 | /** | |
290 | * Gets a view part based on view title | |
dea9c934 | 291 | * |
2f7b3dd7 | 292 | * @param viewTile |
dea9c934 | 293 | * a view title |
2f7b3dd7 BH |
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 | } |