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
.experiment
.TmfExperiment
;
26 import org
.eclipse
.linuxtools
.tmf
.core
.signal
.TmfExperimentSelectedSignal
;
27 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfEventParser
;
28 import org
.eclipse
.linuxtools
.tmf
.core
.trace
.ITmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.tests
.stubs
.trace
.TmfTraceStub
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.uml2sd
.trace
.TmfUml2SDTestTrace
;
31 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.SDView
;
32 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.Criteria
;
33 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.FilterCriteria
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.handlers
.widgets
.FilterListDialog
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.impl
.TmfUml2SDSyncLoader
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
37 import org
.eclipse
.swt
.widgets
.Display
;
38 import org
.eclipse
.ui
.IViewPart
;
39 import org
.eclipse
.ui
.PartInitException
;
40 import org
.eclipse
.ui
.PlatformUI
;
41 import org
.osgi
.framework
.FrameworkUtil
;
44 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
45 * utility methods for interacting with the loader/view.
47 public class Uml2SDTestFacility
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
52 private static Uml2SDTestFacility fInstance
= null;
54 private TmfUml2SDSyncLoader fLoader
;
55 private SDView fSdView
;
56 private TmfTraceStub fTrace
= null;
57 private TmfUml2SDTestTrace fParser
= null;
58 private TmfExperiment
<TmfEvent
> fExperiment
= null;
60 private boolean fIsInitialized
= false;
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
65 private Uml2SDTestFacility() {
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
71 public synchronized static Uml2SDTestFacility
getInstance() {
72 if (fInstance
== null) {
73 fInstance
= new Uml2SDTestFacility();
80 * Initial the test facility.
84 if (!fIsInitialized
) {
86 fParser
= new TmfUml2SDTestTrace();
87 fTrace
= setupTrace(fParser
);
88 fParser
.setTrace(fTrace
);
92 // Remove welcome view to avoid interference during test execution
93 view
= PlatformUI
.getWorkbench()
94 .getActiveWorkbenchWindow()
96 .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
99 PlatformUI
.getWorkbench()
100 .getActiveWorkbenchWindow()
101 .getActivePage().hideView(view
);
104 view
= PlatformUI
.getWorkbench()
105 .getActiveWorkbenchWindow()
107 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
109 } catch (final PartInitException e
) {
110 throw new RuntimeException(e
);
113 fSdView
= (SDView
) view
;
114 fLoader
= (TmfUml2SDSyncLoader
)LoadersManager
.getInstance().createLoader(
115 "org.eclipse.linuxtools.tmf.ui.views.uml2sd.impl.TmfUml2SDSyncLoader", fSdView
); //$NON-NLS-1$
118 fIsInitialized
= true;
123 private TmfTraceStub
setupTrace(final ITmfEventParser
<TmfEvent
> parser
) {
126 // Create test trace object
127 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
128 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
129 return new TmfTraceStub(test
.getPath(), 500, true, parser
, null);
130 } catch (final URISyntaxException e
) {
132 throw new RuntimeException(e
);
133 } catch (final IOException e
) {
135 throw new RuntimeException(e
);
140 * Dispose the resource
142 public void dispose() {
143 if (fIsInitialized
) {
144 fExperiment
.dispose();
146 // Wait for all Eclipse jobs to finish
149 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView
);
150 fIsInitialized
= false;
155 * Sleeps current thread or GUI thread for a given time.
156 * @param waitTimeMillis
158 public void delay(final long waitTimeMillis
) {
159 final Display display
= Display
.getCurrent();
160 if (display
!= null) {
161 final long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
162 while(System
.currentTimeMillis() < endTimeMillis
) {
163 if (!display
.readAndDispatch()) {
170 Thread
.sleep(waitTimeMillis
);
171 } catch (final InterruptedException e
) {
178 * Waits for all Eclipse jobs to finish
180 public void waitForJobs() {
181 while (!Job
.getJobManager().isIdle()) {
182 delay(IUml2SDTestConstants
.WAIT_FOR_JOBS_DELAY
);
187 * @return current UML2SD loader
189 public TmfUml2SDSyncLoader
getLoader() {
194 * @return current SD view
196 public SDView
getSdView() {
201 * @return current trace
203 public TmfTraceStub
getTrace() {
208 * @return Trace parser
210 public TmfUml2SDTestTrace
getParser() {
215 * @return current experiment.
217 public TmfExperiment
<TmfEvent
> getExperiment() {
224 public void nextPage() {
226 fLoader
.waitForCompletion();
227 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
231 * Go to previous page.
233 public void prevPage() {
235 fLoader
.waitForCompletion();
236 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
242 public void lastPage() {
244 fLoader
.waitForCompletion();
245 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
251 public void firstPage() {
253 fLoader
.waitForCompletion();
254 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
258 * @param page number to set
260 public void setPage(final int page
) {
261 fLoader
.pageNumberChanged(page
);;
262 fLoader
.waitForCompletion();
263 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
267 * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean)
269 public void selectExperiment() {
270 this.selectExperiment(true);
274 * Selects the experiment.
275 * @param wait true to wait for indexing to finish else false
277 @SuppressWarnings({ "rawtypes", "unchecked" })
278 public void selectExperiment(final boolean wait
) {
279 fParser
= new TmfUml2SDTestTrace();
280 fTrace
= setupTrace(fParser
);
281 fParser
.setTrace(fTrace
);
283 // fTrace = setupTrace(fParser);
285 final ITmfTrace traces
[] = new ITmfTrace
[1];
287 fExperiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, "TestExperiment", traces
); //$NON-NLS-1$
288 fTrace
.broadcast(new TmfExperimentSelectedSignal
<TmfEvent
>(this, fExperiment
));
290 while (fExperiment
.getNbEvents() == 0) {
291 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
294 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
299 * Disposes the experiment.
301 public void disposeExperiment() {
302 fExperiment
.dispose();
303 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
307 * Creates some global filter criteria and saves them to disk.
309 public void createFilterCriteria() {
310 // Create Filter Criteria and save tme
311 final List
<FilterCriteria
> filterToSave
= new ArrayList
<FilterCriteria
>();
312 Criteria criteria
= new Criteria();
313 criteria
.setLifeLineSelected(true);
314 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
315 filterToSave
.add(new FilterCriteria(criteria
, true, false));
317 criteria
= new Criteria();
318 criteria
.setSyncMessageSelected(true);
319 criteria
.setExpression("BALL_.*"); //$NON-NLS-1$
320 filterToSave
.add(new FilterCriteria(criteria
, true, false));
321 FilterListDialog
.saveFiltersCriteria(filterToSave
);