1 /*******************************************************************************
2 * Copyright (c) 2011, 2012 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12 package org
.eclipse
.linuxtools
.tmf
.ui
.tests
.views
.uml2sd
.loader
;
15 import java
.io
.IOException
;
16 import java
.net
.URISyntaxException
;
18 import java
.util
.ArrayList
;
19 import java
.util
.List
;
21 import org
.eclipse
.core
.runtime
.FileLocator
;
22 import org
.eclipse
.core
.runtime
.Path
;
23 import org
.eclipse
.core
.runtime
.jobs
.Job
;
24 import org
.eclipse
.linuxtools
.tmf
.core
.event
.TmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.core
.exceptions
.TmfTraceException
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceClosedSignal
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfTraceSelectedSignal
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.TmfExperiment
;
31 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.trace
.TmfUml2SDTestTrace
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.Criteria
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
38 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
.TmfUml2SDSyncLoader
;
39 import org
.eclipse
.swt
.widgets
.Display
;
40 import org
.eclipse
.ui
.IViewPart
;
41 import org
.eclipse
.ui
.PartInitException
;
42 import org
.eclipse
.ui
.PlatformUI
;
43 import org
.osgi
.framework
.FrameworkUtil
;
46 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
47 * utility methods for interacting with the loader/view.
49 * @author Bernd Hufmann
51 public class Uml2SDTestFacility
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
56 private static Uml2SDTestFacility fInstance
= null;
58 private TmfUml2SDSyncLoader fLoader
;
59 private SDView fSdView
;
60 private TmfTraceStub fTrace
= null;
61 private TmfUml2SDTestTrace fParser
= null;
62 private TmfExperiment fExperiment
= null;
64 private boolean fIsInitialized
= false;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
69 private Uml2SDTestFacility() {
72 // ------------------------------------------------------------------------
74 // ------------------------------------------------------------------------
76 * @return the singleton instance.
78 public synchronized static Uml2SDTestFacility
getInstance() {
79 if (fInstance
== null) {
80 fInstance
= new Uml2SDTestFacility();
87 * Initial the test facility.
91 if (!fIsInitialized
) {
93 fParser
= new TmfUml2SDTestTrace();
94 fTrace
= setupTrace(fParser
);
95 fParser
.setTrace(fTrace
);
99 // Remove welcome view to avoid interference during test execution
100 view
= PlatformUI
.getWorkbench()
101 .getActiveWorkbenchWindow()
103 .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
106 PlatformUI
.getWorkbench()
107 .getActiveWorkbenchWindow()
108 .getActivePage().hideView(view
);
111 view
= PlatformUI
.getWorkbench()
112 .getActiveWorkbenchWindow()
114 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
116 } catch (final PartInitException e
) {
117 throw new RuntimeException(e
);
120 fSdView
= (SDView
) view
;
121 fLoader
= (TmfUml2SDSyncLoader
)LoadersManager
.getInstance().createLoader(
122 "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView
); //$NON-NLS-1$
125 fIsInitialized
= true;
130 private TmfTraceStub
setupTrace(final ITmfEventParser parser
) {
133 // Create test trace object
134 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
135 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
136 return new TmfTraceStub(test
.getPath(), 500, true, parser
, null);
137 } catch (final TmfTraceException e
) {
139 throw new RuntimeException(e
);
140 } catch (final URISyntaxException e
) {
142 throw new RuntimeException(e
);
143 } catch (final IOException e
) {
145 throw new RuntimeException(e
);
150 * Dispose the resource
152 public void dispose() {
153 if (fIsInitialized
) {
154 fTrace
.broadcast(new TmfTraceClosedSignal(this, fExperiment
));
155 fExperiment
.dispose();
157 // Wait for all Eclipse jobs to finish
160 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView
);
161 fIsInitialized
= false;
166 * Sleeps current thread or GUI thread for a given time.
167 * @param waitTimeMillis time in milliseconds to wait
169 public void delay(final long waitTimeMillis
) {
170 final Display display
= Display
.getCurrent();
171 if (display
!= null) {
172 final long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
173 while(System
.currentTimeMillis() < endTimeMillis
) {
174 if (!display
.readAndDispatch()) {
181 Thread
.sleep(waitTimeMillis
);
182 } catch (final InterruptedException e
) {
189 * Waits for all Eclipse jobs to finish
191 public void waitForJobs() {
192 while (!Job
.getJobManager().isIdle()) {
193 delay(IUml2SDTestConstants
.WAIT_FOR_JOBS_DELAY
);
198 * @return current UML2SD loader
200 public TmfUml2SDSyncLoader
getLoader() {
205 * @return current SD view
207 public SDView
getSdView() {
212 * @return current trace
214 public TmfTraceStub
getTrace() {
219 * @return Trace parser
221 public TmfUml2SDTestTrace
getParser() {
226 * @return current experiment.
228 public TmfExperiment
getExperiment() {
235 public void nextPage() {
237 fLoader
.waitForCompletion();
238 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
242 * Go to previous page.
244 public void prevPage() {
246 fLoader
.waitForCompletion();
247 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
253 public void lastPage() {
255 fLoader
.waitForCompletion();
256 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
262 public void firstPage() {
264 fLoader
.waitForCompletion();
265 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
269 * @param page number to set
271 public void setPage(final int page
) {
272 fLoader
.pageNumberChanged(page
);
273 fLoader
.waitForCompletion();
274 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
278 * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader.Uml2SDTestFacility#selectExperiment(boolean)
280 public void selectExperiment() {
281 this.selectExperiment(true);
285 * Selects the experiment.
286 * @param wait true to wait for indexing to finish else false
288 public void selectExperiment(final boolean wait
) {
289 fParser
= new TmfUml2SDTestTrace();
290 fTrace
= setupTrace(fParser
);
291 fParser
.setTrace(fTrace
);
293 // fTrace = setupTrace(fParser);
295 final ITmfTrace traces
[] = new ITmfTrace
[1];
297 fExperiment
= new TmfExperiment(TmfEvent
.class, "TestExperiment", traces
); //$NON-NLS-1$
298 fTrace
.broadcast(new TmfTraceSelectedSignal(this, fExperiment
));
300 while (fExperiment
.getNbEvents() == 0) {
301 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
304 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
309 * Disposes the experiment.
311 public void disposeExperiment() {
312 fTrace
.broadcast(new TmfTraceClosedSignal(this, fExperiment
));
313 fExperiment
.dispose();
314 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
318 * Creates some global filter criteria and saves them to disk.
320 public void createFilterCriteria() {
321 // Create Filter Criteria and save tme
322 final List
<FilterCriteria
> filterToSave
= new ArrayList
<FilterCriteria
>();
323 Criteria criteria
= new Criteria();
324 criteria
.setLifeLineSelected(true);
325 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
326 filterToSave
.add(new FilterCriteria(criteria
, true, false));
328 criteria
= new Criteria();
329 criteria
.setSyncMessageSelected(true);
330 criteria
.setExpression("BALL_.*"); //$NON-NLS-1$
331 filterToSave
.add(new FilterCriteria(criteria
, true, false));
332 FilterListDialog
.saveFiltersCriteria(filterToSave
);