Disable "warn for deprecated in deprecated code" warnings in test plugins
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.tests / src / org / eclipse / tracecompass / tmf / ui / tests / views / uml2sd / loader / Uml2SDTestFacility.java
CommitLineData
73005152 1/*******************************************************************************
c8422608 2 * Copyright (c) 2011, 2013 Ericsson
64636df8 3 *
73005152
BH
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
64636df8 8 *
73005152
BH
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
2bdf0193 12package org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader;
73005152
BH
13
14import java.io.File;
15import java.io.IOException;
16import java.net.URISyntaxException;
17import java.net.URL;
18import java.util.ArrayList;
19import java.util.List;
20
21import org.eclipse.core.runtime.FileLocator;
22import org.eclipse.core.runtime.Path;
23import org.eclipse.core.runtime.jobs.Job;
73005152 24import org.eclipse.swt.widgets.Display;
2bdf0193
AM
25import org.eclipse.tracecompass.tmf.core.event.ITmfEvent;
26import org.eclipse.tracecompass.tmf.core.exceptions.TmfTraceException;
27import org.eclipse.tracecompass.tmf.core.signal.TmfTraceClosedSignal;
28import org.eclipse.tracecompass.tmf.core.signal.TmfTraceOpenedSignal;
29import org.eclipse.tracecompass.tmf.core.signal.TmfTraceSelectedSignal;
30import org.eclipse.tracecompass.tmf.core.trace.ITmfEventParser;
31import org.eclipse.tracecompass.tmf.core.trace.ITmfTrace;
32import org.eclipse.tracecompass.tmf.core.trace.TmfExperiment;
33import org.eclipse.tracecompass.tmf.core.trace.indexer.ITmfTraceIndexer;
34import org.eclipse.tracecompass.tmf.core.trace.indexer.checkpoint.TmfCheckpointIndexer;
35import org.eclipse.tracecompass.tmf.tests.stubs.trace.TmfTraceStub;
36import org.eclipse.tracecompass.tmf.ui.tests.uml2sd.trace.TmfUml2SDTestTrace;
37import org.eclipse.tracecompass.tmf.ui.views.uml2sd.SDView;
38import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.Criteria;
39import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.FilterCriteria;
40import org.eclipse.tracecompass.tmf.ui.views.uml2sd.dialogs.FilterListDialog;
41import org.eclipse.tracecompass.tmf.ui.views.uml2sd.load.LoadersManager;
42import org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader;
73005152
BH
43import org.eclipse.ui.IViewPart;
44import org.eclipse.ui.PartInitException;
45import org.eclipse.ui.PlatformUI;
9269df72 46import org.osgi.framework.FrameworkUtil;
73005152
BH
47
48/**
49 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
20658947 50 * utility methods for interacting with the loader/view.
64636df8
BH
51 *
52 * @author Bernd Hufmann
73005152
BH
53 */
54public class Uml2SDTestFacility {
20658947 55
73005152
BH
56 // ------------------------------------------------------------------------
57 // Attributes
58 // ------------------------------------------------------------------------
59 private static Uml2SDTestFacility fInstance = null;
20658947 60
73005152
BH
61 private TmfUml2SDSyncLoader fLoader;
62 private SDView fSdView;
63 private TmfTraceStub fTrace = null;
64 private TmfUml2SDTestTrace fParser = null;
6256d8ad 65 private TmfExperiment fExperiment = null;
20658947 66
62f62b14 67 private volatile boolean fIsInitialized = false;
20658947 68
73005152
BH
69 // ------------------------------------------------------------------------
70 // Constructors
71 // ------------------------------------------------------------------------
72 private Uml2SDTestFacility() {
73 }
74
75 // ------------------------------------------------------------------------
76 // Operations
77 // ------------------------------------------------------------------------
64636df8
BH
78 /**
79 * @return the singleton instance.
80 */
1f2f091b 81 public synchronized static Uml2SDTestFacility getInstance() {
73005152
BH
82 if (fInstance == null) {
83 fInstance = new Uml2SDTestFacility();
3ef62bac 84 fInstance.init();
73005152
BH
85 }
86 return fInstance;
87 }
88
89 /**
90 * Initial the test facility.
73005152 91 */
4f5d9f9b 92 public void init() {
20658947 93
73005152 94 if (!fIsInitialized) {
73005152
BH
95
96 fParser = new TmfUml2SDTestTrace();
97 fTrace = setupTrace(fParser);
7e6347b0 98 fParser.setTrace(fTrace);
20658947 99
73005152
BH
100 IViewPart view;
101 try {
1e412478
BH
102 // Remove welcome view to avoid interference during test execution
103 view = PlatformUI.getWorkbench()
104 .getActiveWorkbenchWindow()
105 .getActivePage()
cad06250 106 .findView("org.eclipse.ui.internal.introview");
20658947 107
1e412478
BH
108 if (view != null) {
109 PlatformUI.getWorkbench()
110 .getActiveWorkbenchWindow()
20658947 111 .getActivePage().hideView(view);
1e412478 112 }
20658947 113
73005152 114 view = PlatformUI.getWorkbench()
20658947
FC
115 .getActiveWorkbenchWindow()
116 .getActivePage()
cad06250 117 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView");
20658947
FC
118
119 } catch (final PartInitException e) {
73005152
BH
120 throw new RuntimeException(e);
121 }
122
123 fSdView = (SDView) view;
e57a3f06
AM
124 fLoader = (TmfUml2SDSyncLoader) LoadersManager.getInstance().createLoader(
125 "org.eclipse.tracecompass.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView);
73005152
BH
126
127 delay(3000);
128 fIsInitialized = true;
129 }
130 }
131
20658947 132
6256d8ad 133 private TmfTraceStub setupTrace(final ITmfEventParser parser) {
20658947
FC
134
135 try {
136 // Create test trace object
cad06250 137 final URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null);
20658947 138 final File test = new File(FileLocator.toFileURL(location).toURI());
ab186fbb 139 return new TmfTraceStub(test.getPath(), 500, true, parser);
b4f71e4a
FC
140 } catch (final TmfTraceException e) {
141 e.printStackTrace();
142 throw new RuntimeException(e);
20658947
FC
143 } catch (final URISyntaxException e) {
144 e.printStackTrace();
145 throw new RuntimeException(e);
146 } catch (final IOException e) {
147 e.printStackTrace();
148 throw new RuntimeException(e);
149 }
73005152 150 }
20658947 151
73005152
BH
152 /**
153 * Dispose the resource
154 */
155 public void dispose() {
4f5d9f9b 156 if (fIsInitialized) {
62f62b14
AM
157 ITmfTrace trace = fTrace;
158 TmfExperiment experiment = fExperiment;
159 if (trace == null || experiment == null) {
160 throw new IllegalStateException();
161 }
162
163 trace.broadcast(new TmfTraceClosedSignal(this, experiment));
164 experiment.dispose();
73005152
BH
165
166 // Wait for all Eclipse jobs to finish
167 waitForJobs();
168
169 PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView);
170 fIsInitialized = false;
171 }
172 }
20658947 173
73005152 174 /**
20658947 175 * Sleeps current thread or GUI thread for a given time.
64636df8 176 * @param waitTimeMillis time in milliseconds to wait
73005152 177 */
20658947
FC
178 public void delay(final long waitTimeMillis) {
179 final Display display = Display.getCurrent();
73005152 180 if (display != null) {
20658947 181 final long endTimeMillis = System.currentTimeMillis() + waitTimeMillis;
73005152
BH
182 while(System.currentTimeMillis() < endTimeMillis) {
183 if (!display.readAndDispatch()) {
99c3a878
MAL
184 // We do not use Display.sleep because it might never wake up
185 // if there is no user interaction
186 try {
187 Thread.sleep(Math.min(waitTimeMillis, 10));
188 } catch (final InterruptedException e) {
189 // Ignored
b07022a9 190 }
73005152
BH
191 }
192 display.update();
193 }
194 } else {
195 try {
196 Thread.sleep(waitTimeMillis);
20658947 197 } catch (final InterruptedException e) {
73005152
BH
198 // Ignored
199 }
200 }
201 }
202
203 /**
204 * Waits for all Eclipse jobs to finish
205 */
206 public void waitForJobs() {
207 while (!Job.getJobManager().isIdle()) {
208 delay(IUml2SDTestConstants.WAIT_FOR_JOBS_DELAY);
209 }
210 }
211
212 /**
213 * @return current UML2SD loader
214 */
215 public TmfUml2SDSyncLoader getLoader() {
216 return fLoader;
217 }
218
219 /**
220 * @return current SD view
221 */
222 public SDView getSdView() {
223 return fSdView;
224 }
225
226 /**
227 * @return current trace
228 */
229 public TmfTraceStub getTrace() {
230 return fTrace;
231 }
232
233 /**
234 * @return Trace parser
235 */
236 public TmfUml2SDTestTrace getParser() {
237 return fParser;
238 }
239
240 /**
241 * @return current experiment.
242 */
6256d8ad 243 public TmfExperiment getExperiment() {
73005152
BH
244 return fExperiment;
245 }
20658947 246
73005152
BH
247 /**
248 * Go to next page;
249 */
250 public void nextPage() {
251 fLoader.nextPage();
252 fLoader.waitForCompletion();
253 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
254 }
255
256 /**
257 * Go to previous page.
258 */
259 public void prevPage() {
260 fLoader.prevPage();
261 fLoader.waitForCompletion();
262 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
263 }
20658947 264
73005152
BH
265 /**
266 * Go to last page.
267 */
268 public void lastPage() {
269 fLoader.lastPage();
270 fLoader.waitForCompletion();
271 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
272 }
273
274 /**
275 * Go to first page.
276 */
277 public void firstPage() {
278 fLoader.firstPage();
279 fLoader.waitForCompletion();
280 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
281 }
20658947 282
73005152
BH
283 /**
284 * @param page number to set
285 */
20658947 286 public void setPage(final int page) {
abbdd66a 287 fLoader.pageNumberChanged(page);
73005152
BH
288 fLoader.waitForCompletion();
289 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
290 }
20658947 291
73005152 292 /**
2bdf0193 293 * @see org.eclipse.tracecompass.tmf.ui.tests.views.uml2sd.loader.Uml2SDTestFacility#selectExperiment(boolean)
73005152
BH
294 */
295 public void selectExperiment() {
296 this.selectExperiment(true);
297 }
20658947 298
73005152 299 /**
20658947 300 * Selects the experiment.
73005152
BH
301 * @param wait true to wait for indexing to finish else false
302 */
20658947 303 public void selectExperiment(final boolean wait) {
7e6347b0 304 fParser = new TmfUml2SDTestTrace();
73005152 305 fTrace = setupTrace(fParser);
7e6347b0
FC
306 fParser.setTrace(fTrace);
307
20658947 308 final ITmfTrace traces[] = new ITmfTrace[1];
73005152 309 traces[0] = fTrace;
8143f5a1
BH
310 fExperiment = new TmfExperiment(ITmfEvent.class, "TestExperiment", traces) {
311 @Override
312 protected ITmfTraceIndexer createIndexer(int interval) {
313 return new TmfCheckpointIndexer(this, interval);
314 }
315 };
3fcf269e 316 fTrace.broadcast(new TmfTraceOpenedSignal(this, fExperiment, null));
faa38350 317 fTrace.broadcast(new TmfTraceSelectedSignal(this, fExperiment));
73005152 318 if (wait) {
2717e7ec
PT
319 while (fExperiment.getNbEvents() == 0) {
320 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
321 }
73005152
BH
322 waitForJobs();
323 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
324 }
325 }
20658947 326
73005152
BH
327 /**
328 * Disposes the experiment.
329 */
330 public void disposeExperiment() {
62f62b14
AM
331 ITmfTrace trace = fTrace;
332 TmfExperiment experiment = fExperiment;
333 if (trace == null || experiment == null) {
334 throw new IllegalStateException();
335 }
336 trace.broadcast(new TmfTraceClosedSignal(this, experiment));
337 experiment.dispose();
73005152
BH
338 delay(IUml2SDTestConstants.GUI_REFESH_DELAY);
339 }
20658947 340
73005152 341 /**
20658947 342 * Creates some global filter criteria and saves them to disk.
73005152
BH
343 */
344 public void createFilterCriteria() {
345 // Create Filter Criteria and save tme
ab410d88 346 final List<FilterCriteria> filterToSave = new ArrayList<>();
73005152
BH
347 Criteria criteria = new Criteria();
348 criteria.setLifeLineSelected(true);
349 criteria.setExpression(IUml2SDTestConstants.FIRST_PLAYER_NAME);
350 filterToSave.add(new FilterCriteria(criteria, true, false));
20658947 351
73005152
BH
352 criteria = new Criteria();
353 criteria.setSyncMessageSelected(true);
cad06250 354 criteria.setExpression("BALL_.*");
73005152
BH
355 filterToSave.add(new FilterCriteria(criteria, true, false));
356 FilterListDialog.saveFiltersCriteria(filterToSave);
357 }
358
359
360}
This page took 0.084772 seconds and 5 git commands to generate.