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
.event
.TmfEvent
;
25 import org
.eclipse
.linuxtools
.tmf
.experiment
.TmfExperiment
;
26 import org
.eclipse
.linuxtools
.tmf
.parser
.ITmfEventParser
;
27 import org
.eclipse
.linuxtools
.tmf
.signal
.TmfExperimentSelectedSignal
;
28 import org
.eclipse
.linuxtools
.tmf
.trace
.ITmfTrace
;
29 import org
.eclipse
.linuxtools
.tmf
.trace
.TmfTraceStub
;
30 import org
.eclipse
.linuxtools
.tmf
.ui
.tests
.TmfUITestPlugin
;
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
;
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;
61 private boolean fIsGlobalTest
= false;
63 // ------------------------------------------------------------------------
65 // ------------------------------------------------------------------------
66 private Uml2SDTestFacility() {
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
72 public static Uml2SDTestFacility
getInstance() {
73 if (fInstance
== null) {
74 fInstance
= new Uml2SDTestFacility();
80 * Initial the test facility.
81 * @param isGlobal true if multiple test cases are run in sequence (AllTests) or false for a single test case
83 public void init(boolean isGlobal
) {
85 if (!fIsInitialized
) {
86 fIsGlobalTest
= isGlobal
;
88 fParser
= new TmfUml2SDTestTrace();
89 fTrace
= setupTrace(fParser
);
93 view
= PlatformUI
.getWorkbench()
94 .getActiveWorkbenchWindow()
96 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
98 } catch (PartInitException e
) {
99 throw new RuntimeException(e
);
102 fSdView
= (SDView
) view
;
103 fLoader
= (TmfUml2SDSyncLoader
)LoadersManager
.getInstance().createLoader(
104 "org.eclipse.linuxtools.tmf.ui.views.uml2sd.impl.TmfUml2SDSyncLoader", fSdView
); //$NON-NLS-1$
107 fIsInitialized
= true;
112 private TmfTraceStub
setupTrace(ITmfEventParser parser
) {
115 // Create test trace object
116 URL location
= FileLocator
.find(TmfUITestPlugin
.getDefault().getBundle(), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
117 File test
= new File(FileLocator
.toFileURL(location
).toURI());
118 return new TmfTraceStub(test
.getPath(), 500, true, parser
);
119 } catch (URISyntaxException e
) {
121 throw new RuntimeException(e
);
122 } catch (IOException e
) {
124 throw new RuntimeException(e
);
129 * Dispose the resource
131 public void dispose() {
132 if (fIsInitialized
&& !fIsGlobalTest
) {
133 fExperiment
.dispose();
135 // Wait for all Eclipse jobs to finish
138 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView
);
139 fIsInitialized
= false;
144 * Sleeps current thread or GUI thread for a given time.
145 * @param waitTimeMillis
147 public void delay(long waitTimeMillis
) {
148 Display display
= Display
.getCurrent();
149 if (display
!= null) {
150 long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
151 while(System
.currentTimeMillis() < endTimeMillis
) {
152 if (!display
.readAndDispatch()) {
159 Thread
.sleep(waitTimeMillis
);
160 } catch (InterruptedException e
) {
167 * Waits for all Eclipse jobs to finish
169 public void waitForJobs() {
170 while (!Job
.getJobManager().isIdle()) {
171 delay(IUml2SDTestConstants
.WAIT_FOR_JOBS_DELAY
);
176 * @return current UML2SD loader
178 public TmfUml2SDSyncLoader
getLoader() {
183 * @return current SD view
185 public SDView
getSdView() {
190 * @return current trace
192 public TmfTraceStub
getTrace() {
197 * @return Trace parser
199 public TmfUml2SDTestTrace
getParser() {
204 * @return current experiment.
206 public TmfExperiment
<TmfEvent
> getExperiment() {
213 public void nextPage() {
215 fLoader
.waitForCompletion();
216 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
220 * Go to previous page.
222 public void prevPage() {
224 fLoader
.waitForCompletion();
225 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
231 public void lastPage() {
233 fLoader
.waitForCompletion();
234 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
240 public void firstPage() {
242 fLoader
.waitForCompletion();
243 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
247 * @param page number to set
249 public void setPage(int page
) {
250 fLoader
.pageNumberChanged(page
);;
251 fLoader
.waitForCompletion();
252 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
256 * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.impl.selectExperiment(boolean)
258 public void selectExperiment() {
259 this.selectExperiment(true);
263 * Selects the experiment.
264 * @param wait true to wait for indexing to finish else false
266 public void selectExperiment(boolean wait
) {
267 fTrace
= setupTrace(fParser
);
269 ITmfTrace traces
[] = new ITmfTrace
[1];
271 fExperiment
= new TmfExperiment
<TmfEvent
>(TmfEvent
.class, "TestExperiment", traces
); //$NON-NLS-1$
272 fTrace
.broadcast(new TmfExperimentSelectedSignal
<TmfEvent
>(this, fExperiment
));
275 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
280 * Disposes the experiment.
282 public void disposeExperiment() {
283 fExperiment
.dispose();
284 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
288 * Creates some global filter criteria and saves them to disk.
290 public void createFilterCriteria() {
291 // Create Filter Criteria and save tme
292 List
<FilterCriteria
> filterToSave
= new ArrayList
<FilterCriteria
>();
293 Criteria criteria
= new Criteria();
294 criteria
.setLifeLineSelected(true);
295 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
296 filterToSave
.add(new FilterCriteria(criteria
, true, false));
298 criteria
= new Criteria();
299 criteria
.setSyncMessageSelected(true);
300 criteria
.setExpression("BALL_.*"); //$NON-NLS-1$
301 filterToSave
.add(new FilterCriteria(criteria
, true, false));
302 FilterListDialog
.saveFiltersCriteria(filterToSave
);