1 /*******************************************************************************
2 * Copyright (c) 2011 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
.impl
;
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
.experiment
.TmfExperiment
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
29 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
30 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.trace
.TmfUml2SDTestTrace
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.Criteria
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.FilterCriteria
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.FilterListDialog
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.impl
.TmfUml2SDSyncLoader
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
38 import org
.eclipse
.swt
.widgets
.Display
;
39 import org
.eclipse
.ui
.IViewPart
;
40 import org
.eclipse
.ui
.PartInitException
;
41 import org
.eclipse
.ui
.PlatformUI
;
42 import org
.osgi
.framework
.FrameworkUtil
;
45 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
46 * utility methods for interacting with the loader/view.
48 public class Uml2SDTestFacility
{
50 // ------------------------------------------------------------------------
52 // ------------------------------------------------------------------------
53 private static Uml2SDTestFacility fInstance
= null;
55 private TmfUml2SDSyncLoader fLoader
;
56 private SDView fSdView
;
57 private TmfTraceStub fTrace
= null;
58 private TmfUml2SDTestTrace fParser
= null;
59 private TmfExperiment
<TmfEvent
> fExperiment
= null;
61 private boolean fIsInitialized
= false;
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
66 private Uml2SDTestFacility() {
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
72 public synchronized static Uml2SDTestFacility
getInstance() {
73 if (fInstance
== null) {
74 fInstance
= new Uml2SDTestFacility();
81 * Initial the test facility.
85 if (!fIsInitialized
) {
87 fParser
= new TmfUml2SDTestTrace();
88 fTrace
= setupTrace(fParser
);
89 fParser
.setTrace(fTrace
);
93 // Remove welcome view to avoid interference during test execution
94 view
= PlatformUI
.getWorkbench()
95 .getActiveWorkbenchWindow()
97 .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
100 PlatformUI
.getWorkbench()
101 .getActiveWorkbenchWindow()
102 .getActivePage().hideView(view
);
105 view
= PlatformUI
.getWorkbench()
106 .getActiveWorkbenchWindow()
108 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
110 } catch (final PartInitException e
) {
111 throw new RuntimeException(e
);
114 fSdView
= (SDView
) view
;
115 fLoader
= (TmfUml2SDSyncLoader
)LoadersManager
.getInstance().createLoader(
116 "org.eclipse.linuxtools.tmf.ui.views.uml2sd.impl.TmfUml2SDSyncLoader", fSdView
); //$NON-NLS-1$
119 fIsInitialized
= true;
124 private TmfTraceStub
setupTrace(final ITmfEventParser
<TmfEvent
> parser
) {
127 // Create test trace object
128 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
129 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
130 return new TmfTraceStub(test
.getPath(), 500, true, parser
, null);
131 } catch (final TmfTraceException e
) {
133 throw new RuntimeException(e
);
134 } catch (final URISyntaxException e
) {
136 throw new RuntimeException(e
);
137 } catch (final IOException e
) {
139 throw new RuntimeException(e
);
144 * Dispose the resource
146 public void dispose() {
147 if (fIsInitialized
) {
148 fExperiment
.dispose();
150 // Wait for all Eclipse jobs to finish
153 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView
);
154 fIsInitialized
= false;
159 * Sleeps current thread or GUI thread for a given time.
160 * @param waitTimeMillis
162 public void delay(final long waitTimeMillis
) {
163 final Display display
= Display
.getCurrent();
164 if (display
!= null) {
165 final long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
166 while(System
.currentTimeMillis() < endTimeMillis
) {
167 if (!display
.readAndDispatch()) {
174 Thread
.sleep(waitTimeMillis
);
175 } catch (final InterruptedException e
) {
182 * Waits for all Eclipse jobs to finish
184 public void waitForJobs() {
185 while (!Job
.getJobManager().isIdle()) {
186 delay(IUml2SDTestConstants
.WAIT_FOR_JOBS_DELAY
);
191 * @return current UML2SD loader
193 public TmfUml2SDSyncLoader
getLoader() {
198 * @return current SD view
200 public SDView
getSdView() {
205 * @return current trace
207 public TmfTraceStub
getTrace() {
212 * @return Trace parser
214 public TmfUml2SDTestTrace
getParser() {
219 * @return current experiment.
221 public TmfExperiment
<TmfEvent
> getExperiment() {
228 public void nextPage() {
230 fLoader
.waitForCompletion();
231 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
235 * Go to previous page.
237 public void prevPage() {
239 fLoader
.waitForCompletion();
240 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
246 public void lastPage() {
248 fLoader
.waitForCompletion();
249 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
255 public void firstPage() {
257 fLoader
.waitForCompletion();
258 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
262 * @param page number to set
264 public void setPage(final int page
) {
265 fLoader
.pageNumberChanged(page
);;
266 fLoader
.waitForCompletion();
267 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
271 * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean)
273 public void selectExperiment() {
274 this.selectExperiment(true);
278 * Selects the experiment.
279 * @param wait true to wait for indexing to finish else false
281 @SuppressWarnings({ "rawtypes", "unchecked" })
282 public void selectExperiment(final boolean wait
) {
283 fParser
= new TmfUml2SDTestTrace();
284 fTrace
= setupTrace(fParser
);
285 fParser
.setTrace(fTrace
);
287 // fTrace = setupTrace(fParser);
289 final ITmfTrace traces
[] = new ITmfTrace
[1];
291 fExperiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, "TestExperiment", traces
); //$NON-NLS-1$
292 fTrace
.broadcast(new TmfExperimentSelectedSignal
<TmfEvent
>(this, fExperiment
));
294 while (fExperiment
.getNbEvents() == 0) {
295 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
298 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
303 * Disposes the experiment.
305 public void disposeExperiment() {
306 fExperiment
.dispose();
307 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
311 * Creates some global filter criteria and saves them to disk.
313 public void createFilterCriteria() {
314 // Create Filter Criteria and save tme
315 final List
<FilterCriteria
> filterToSave
= new ArrayList
<FilterCriteria
>();
316 Criteria criteria
= new Criteria();
317 criteria
.setLifeLineSelected(true);
318 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
319 filterToSave
.add(new FilterCriteria(criteria
, true, false));
321 criteria
= new Criteria();
322 criteria
.setSyncMessageSelected(true);
323 criteria
.setExpression("BALL_.*"); //$NON-NLS-1$
324 filterToSave
.add(new FilterCriteria(criteria
, true, false));
325 FilterListDialog
.saveFiltersCriteria(filterToSave
);