1 /*******************************************************************************
2 * Copyright (c) 2013 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
12 *******************************************************************************/
14 package org
.eclipse
.linuxtools
.tmf
.ui
.swtbot
.tests
;
16 import static org
.junit
.Assert
.assertNotNull
;
18 import java
.util
.List
;
20 import org
.apache
.log4j
.Logger
;
21 import org
.apache
.log4j
.varia
.NullAppender
;
22 import org
.eclipse
.core
.resources
.IResource
;
23 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
24 import org
.eclipse
.core
.runtime
.CoreException
;
25 import org
.eclipse
.jface
.viewers
.SelectionChangedEvent
;
26 import org
.eclipse
.jface
.viewers
.StructuredSelection
;
27 import org
.eclipse
.jface
.wizard
.IWizardPage
;
28 import org
.eclipse
.jface
.wizard
.Wizard
;
29 import org
.eclipse
.jface
.wizard
.WizardDialog
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfEvent
;
31 import org
.eclipse
.linuxtools
.tmf
.core
.ctfadaptor
.CtfTmfTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTimeSynchSignal
;
33 import org
.eclipse
.linuxtools
.tmf
.core
.tests
.shared
.CtfTmfTestTrace
;
34 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfContext
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.editors
.TmfEventsEditor
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.project
.wizards
.importtrace
.BatchImportTraceWizard
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.swtbot
.tests
.conditions
.ConditionHelpers
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.histogram
.HistogramView
;
39 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.statistics
.TmfStatisticsView
;
40 import org
.eclipse
.swt
.widgets
.Shell
;
41 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
42 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
43 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
44 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
45 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
46 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
47 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotButton
;
48 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotMenu
;
49 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
50 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
51 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotToolbarButton
;
52 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
53 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
54 import org
.eclipse
.ui
.IEditorPart
;
55 import org
.eclipse
.ui
.IEditorReference
;
56 import org
.eclipse
.ui
.IPageLayout
;
57 import org
.eclipse
.ui
.IViewPart
;
58 import org
.eclipse
.ui
.IViewReference
;
59 import org
.eclipse
.ui
.IWorkbench
;
60 import org
.eclipse
.ui
.IWorkbenchWindow
;
61 import org
.eclipse
.ui
.PlatformUI
;
62 import org
.eclipse
.ui
.views
.properties
.PropertySheet
;
63 import org
.junit
.BeforeClass
;
64 import org
.junit
.Test
;
67 * SWTBot Smoke test. base for other tests
69 * @author Matthew Khouzam
71 public class ImportAndReadSmokeTest
{
74 private static final String TRACE_PROJECT_NAME
= "test";
75 private static final String TRACE_NAME
= "synthetic-trace";
76 private static final String TRACE_TYPE_NAME
= "Generic CTF Trace";
77 private static final CtfTmfTestTrace fTrace
= CtfTmfTestTrace
.SYNTHETIC_TRACE
;
79 private static SWTWorkbenchBot fBot
;
80 private static Wizard fWizard
;
82 /** The Log4j logger instance. */
83 private static final Logger fLogger
= Logger
.getRootLogger();
85 /** Test Class setup */
87 public static void init() {
88 SWTBotUtil
.failIfUIThread();
90 /* set up for swtbot */
91 SWTBotPreferences
.TIMEOUT
= 50000; /* 50 second timeout */
92 fLogger
.addAppender(new NullAppender());
93 fBot
= new SWTWorkbenchBot();
95 SWTBotUtil
.closeView("welcome", fBot
);
97 SWTBotUtil
.switchToTracingPerspective();
98 /* finish waiting for eclipse to load */
99 SWTBotUtil
.waitForJobs();
109 batchImportOpenWizard();
110 batchImportSelecTraceType();
111 batchImportAddDirectory();
112 batchImportSelectTrace();
115 TmfEventsEditor tmfEd
= openEditor();
117 testHistogramView(getViewPart("Histogram"), tmfEd
);
118 testPropertyView(getViewPart("Properties"));
119 testStatisticsView(getViewPart("Statistics"));
124 private static void createProject() {
125 SWTBotUtil
.focusMainWindow(fBot
.shells());
126 fBot
.menu("File").menu("New").menu("Project...").click();
128 fBot
.waitUntil(Conditions
.shellIsActive("New Project"));
129 SWTBotTree tree
= fBot
.tree();
131 final String tracingKey
= "Tracing";
132 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(tracingKey
, tree
));
133 final SWTBotTreeItem tracingNode
= tree
.expandNode(tracingKey
);
135 tracingNode
.select();
136 final String projectKey
= "Tracing Project";
137 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(projectKey
, tracingNode
));
138 final SWTBotTreeItem tracingProject
= tracingNode
.getNode(projectKey
);
139 assertNotNull(tracingProject
);
141 tracingProject
.select();
142 tracingProject
.click();
144 SWTBotButton nextButton
= fBot
.button("Next >");
145 fBot
.waitUntil(Conditions
.widgetIsEnabled(nextButton
));
147 fBot
.waitUntil(Conditions
.shellIsActive("Tracing Project"));
149 final SWTBotText text
= fBot
.text();
150 text
.setText(TRACE_PROJECT_NAME
);
152 fBot
.button("Finish").click();
153 SWTBotUtil
.waitForJobs();
156 private static void batchImportOpenWizard() {
157 fWizard
= new BatchImportTraceWizard();
159 UIThreadRunnable
.asyncExec(new VoidResult() {
162 final IWorkbench workbench
= PlatformUI
.getWorkbench();
163 // Fire the Import Trace Wizard
164 if (workbench
!= null) {
165 final IWorkbenchWindow activeWorkbenchWindow
= workbench
.getActiveWorkbenchWindow();
166 Shell shell
= activeWorkbenchWindow
.getShell();
167 assertNotNull(shell
);
168 ((BatchImportTraceWizard
) fWizard
).init(PlatformUI
.getWorkbench(), StructuredSelection
.EMPTY
);
169 WizardDialog dialog
= new WizardDialog(shell
, fWizard
);
175 fBot
.waitUntil(ConditionHelpers
.isWizardReady(fWizard
));
178 private static void batchImportSelecTraceType() {
179 final SWTBotTree tree
= fBot
.tree();
180 final String ctfId
= "Common Trace Format";
181 fBot
.waitUntil(ConditionHelpers
.IsTreeNodeAvailable(ctfId
, tree
));
182 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(TRACE_TYPE_NAME
, tree
.getTreeItem(ctfId
)));
183 tree
.getTreeItem(ctfId
).getNode(TRACE_TYPE_NAME
).check();
184 batchImportClickNext();
187 private static void batchImportAddDirectory() {
188 UIThreadRunnable
.syncExec(new VoidResult() {
191 ((BatchImportTraceWizard
) fWizard
).addFileToScan(fTrace
.getPath());
194 final SWTBotButton removeButton
= fBot
.button("Remove");
195 fBot
.waitUntil(Conditions
.widgetIsEnabled(removeButton
));
196 removeButton
.click();
197 fBot
.waitUntil(Conditions
.tableHasRows(fBot
.table(), 1));
199 batchImportClickNext();
202 private static void batchImportSelectTrace() {
203 SWTBotTree tree
= fBot
.tree();
204 fBot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
205 final SWTBotTreeItem genericCtfTreeItem
= tree
.getTreeItem(TRACE_TYPE_NAME
);
206 fBot
.waitUntil(Conditions
.widgetIsEnabled(genericCtfTreeItem
));
207 genericCtfTreeItem
.expand();
208 genericCtfTreeItem
.check();
209 batchImportClickNext();
212 private static void batchImportClickNext() {
213 IWizardPage currentPage
= fWizard
.getContainer().getCurrentPage();
214 IWizardPage desiredPage
= fWizard
.getNextPage(currentPage
);
215 SWTBotButton nextButton
= fBot
.button("Next >");
217 fBot
.waitUntil(ConditionHelpers
.isWizardOnPage(fWizard
, desiredPage
));
220 private static void batchImportFinish() {
221 SWTBotShell shell
= fBot
.activeShell();
222 final SWTBotButton finishButton
= fBot
.button("Finish");
223 finishButton
.click();
224 fBot
.waitUntil(Conditions
.shellCloses(shell
));
225 SWTBotUtil
.waitForJobs();
228 private static TmfEventsEditor
openEditor() {
229 final SWTBotView projectExplorerBot
= fBot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
230 projectExplorerBot
.setFocus();
232 final SWTBotTree tree
= fBot
.tree();
233 final SWTBotTreeItem treeItem
= tree
.getTreeItem(TRACE_PROJECT_NAME
);
236 List
<String
> nodes
= treeItem
.getNodes();
237 String nodeName
= "";
238 for (String node
: nodes
) {
239 if (node
.startsWith("Traces")) {
243 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(nodeName
, treeItem
));
244 treeItem
.getNode(nodeName
).expand();
245 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(TRACE_NAME
, treeItem
.getNode(nodeName
)));
246 treeItem
.getNode(nodeName
).getNode(TRACE_NAME
).select();
247 treeItem
.getNode(nodeName
).getNode(TRACE_NAME
).doubleClick();
248 SWTBotUtil
.delay(1000);
249 SWTBotUtil
.waitForJobs();
251 final IEditorPart iep
[] = new IEditorPart
[1];
252 UIThreadRunnable
.syncExec(new VoidResult() {
255 IEditorReference
[] ieds
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
258 for (IEditorReference ied
: ieds
) {
259 if (ied
.getTitle().equals(TRACE_NAME
)) {
260 iep
[0] = ied
.getEditor(true);
266 assertNotNull(iep
[0]);
267 return (TmfEventsEditor
) iep
[0];
270 private static void deleteProject() {
272 ResourcesPlugin
.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME
).refreshLocal(IResource
.DEPTH_INFINITE
, null);
273 } catch (CoreException e
) {
276 SWTBotUtil
.waitForJobs();
278 final SWTBotView projectViewBot
= fBot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
279 projectViewBot
.setFocus();
281 SWTBotTree treeBot
= fBot
.tree();
282 SWTBotTreeItem treeItem
= treeBot
.getTreeItem(TRACE_PROJECT_NAME
);
283 SWTBotMenu contextMenu
= treeItem
.contextMenu("Delete");
286 String shellText
= "Delete Resources";
287 fBot
.waitUntil(Conditions
.shellIsActive(shellText
));
288 final SWTBotButton okButton
= fBot
.button("OK");
289 fBot
.waitUntil(Conditions
.widgetIsEnabled(okButton
));
292 SWTBotUtil
.waitForJobs();
295 // ---------------------------------------------
296 // Helpers for testing views
297 // ---------------------------------------------
299 private static void testPropertyView(IViewPart vp
) {
300 PropertySheet pv
= (PropertySheet
) vp
;
304 private static void testHistogramView(IViewPart vp
, final TmfEventsEditor tmfEd
) {
305 final CtfTmfEvent desiredEvent1
= getEvent(100);
306 UIThreadRunnable
.syncExec(new VoidResult() {
310 tmfEd
.selectionChanged(new SelectionChangedEvent(tmfEd
, new StructuredSelection(desiredEvent1
)));
314 SWTBotUtil
.waitForJobs();
315 SWTBotUtil
.delay(1000);
317 final CtfTmfEvent desiredEvent2
= getEvent(10000);
318 SWTBotView hvBot
= fBot
.viewById(HistogramView
.ID
);
319 List
<SWTBotToolbarButton
> hvTools
= hvBot
.getToolbarButtons();
320 for (SWTBotToolbarButton hvTool
: hvTools
) {
321 if (hvTool
.getToolTipText().toLowerCase().contains("lost")) {
325 HistogramView hv
= (HistogramView
) vp
;
326 final TmfTimeSynchSignal signal
= new TmfTimeSynchSignal(hv
, desiredEvent1
.getTimestamp());
327 final TmfTimeSynchSignal signal2
= new TmfTimeSynchSignal(hv
, desiredEvent2
.getTimestamp());
328 hv
.updateTimeRange(100000);
329 SWTBotUtil
.waitForJobs();
330 hv
.currentTimeUpdated(signal
);
331 hv
.broadcast(signal
);
332 SWTBotUtil
.waitForJobs();
333 SWTBotUtil
.delay(1000);
335 hv
.updateTimeRange(1000000000);
336 SWTBotUtil
.waitForJobs();
337 hv
.currentTimeUpdated(signal2
);
338 hv
.broadcast(signal2
);
339 SWTBotUtil
.waitForJobs();
340 SWTBotUtil
.delay(1000);
344 private static void testStatisticsView(IViewPart vp
) {
345 TmfStatisticsView sv
= (TmfStatisticsView
) vp
;
349 // ---------------------------------------------
351 // ---------------------------------------------
353 private static CtfTmfEvent
getEvent(int rank
) {
354 CtfTmfTrace trace
= fTrace
.getTrace();
358 ITmfContext ctx
= trace
.seekEvent(0);
359 for (int i
= 0; i
< rank
; i
++) {
362 final CtfTmfEvent retVal
= trace
.getNext(ctx
);
367 private static IViewPart
getViewPart(final String viewTile
) {
368 final IViewPart
[] vps
= new IViewPart
[1];
369 UIThreadRunnable
.syncExec(new VoidResult() {
372 IViewReference
[] viewRefs
= PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().getViewReferences();
373 for (IViewReference viewRef
: viewRefs
) {
374 IViewPart vp
= viewRef
.getView(true);
375 if (vp
.getTitle().equals(viewTile
)) {