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
.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
.core
.trace
.TmfExperiment
;
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
.dialogs
.Criteria
;
34 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterCriteria
;
35 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.dialogs
.FilterListDialog
;
36 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.load
.LoadersManager
;
37 import org
.eclipse
.linuxtools
.tmf
.ui
.views
.uml2sd
.loader
.TmfUml2SDSyncLoader
;
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 * @author Bernd Hufmann
50 public class Uml2SDTestFacility
{
52 // ------------------------------------------------------------------------
54 // ------------------------------------------------------------------------
55 private static Uml2SDTestFacility fInstance
= null;
57 private TmfUml2SDSyncLoader fLoader
;
58 private SDView fSdView
;
59 private TmfTraceStub fTrace
= null;
60 private TmfUml2SDTestTrace fParser
= null;
61 private TmfExperiment fExperiment
= null;
63 private boolean fIsInitialized
= false;
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
68 private Uml2SDTestFacility() {
71 // ------------------------------------------------------------------------
73 // ------------------------------------------------------------------------
75 * @return the singleton instance.
77 public synchronized static Uml2SDTestFacility
getInstance() {
78 if (fInstance
== null) {
79 fInstance
= new Uml2SDTestFacility();
86 * Initial the test facility.
90 if (!fIsInitialized
) {
92 fParser
= new TmfUml2SDTestTrace();
93 fTrace
= setupTrace(fParser
);
94 fParser
.setTrace(fTrace
);
98 // Remove welcome view to avoid interference during test execution
99 view
= PlatformUI
.getWorkbench()
100 .getActiveWorkbenchWindow()
102 .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
105 PlatformUI
.getWorkbench()
106 .getActiveWorkbenchWindow()
107 .getActivePage().hideView(view
);
110 view
= PlatformUI
.getWorkbench()
111 .getActiveWorkbenchWindow()
113 .showView("org.eclipse.linuxtools.tmf.ui.tmfUml2SDSyncView"); //$NON-NLS-1$
115 } catch (final PartInitException e
) {
116 throw new RuntimeException(e
);
119 fSdView
= (SDView
) view
;
120 fLoader
= (TmfUml2SDSyncLoader
)LoadersManager
.getInstance().createLoader(
121 "org.eclipse.linuxtools.tmf.ui.views.uml2sd.loader.TmfUml2SDSyncLoader", fSdView
); //$NON-NLS-1$
124 fIsInitialized
= true;
129 private TmfTraceStub
setupTrace(final ITmfEventParser parser
) {
132 // Create test trace object
133 final URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path("tracesets/sdEvents"), null); //$NON-NLS-1$
134 final File test
= new File(FileLocator
.toFileURL(location
).toURI());
135 return new TmfTraceStub(test
.getPath(), 500, true, parser
, null);
136 } catch (final TmfTraceException e
) {
138 throw new RuntimeException(e
);
139 } catch (final URISyntaxException e
) {
141 throw new RuntimeException(e
);
142 } catch (final IOException e
) {
144 throw new RuntimeException(e
);
149 * Dispose the resource
151 public void dispose() {
152 if (fIsInitialized
) {
153 fExperiment
.dispose();
155 // Wait for all Eclipse jobs to finish
158 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fSdView
);
159 fIsInitialized
= false;
164 * Sleeps current thread or GUI thread for a given time.
165 * @param waitTimeMillis time in milliseconds to wait
167 public void delay(final long waitTimeMillis
) {
168 final Display display
= Display
.getCurrent();
169 if (display
!= null) {
170 final long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
171 while(System
.currentTimeMillis() < endTimeMillis
) {
172 if (!display
.readAndDispatch()) {
179 Thread
.sleep(waitTimeMillis
);
180 } catch (final InterruptedException e
) {
187 * Waits for all Eclipse jobs to finish
189 public void waitForJobs() {
190 while (!Job
.getJobManager().isIdle()) {
191 delay(IUml2SDTestConstants
.WAIT_FOR_JOBS_DELAY
);
196 * @return current UML2SD loader
198 public TmfUml2SDSyncLoader
getLoader() {
203 * @return current SD view
205 public SDView
getSdView() {
210 * @return current trace
212 public TmfTraceStub
getTrace() {
217 * @return Trace parser
219 public TmfUml2SDTestTrace
getParser() {
224 * @return current experiment.
226 public TmfExperiment
getExperiment() {
233 public void nextPage() {
235 fLoader
.waitForCompletion();
236 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
240 * Go to previous page.
242 public void prevPage() {
244 fLoader
.waitForCompletion();
245 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
251 public void lastPage() {
253 fLoader
.waitForCompletion();
254 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
260 public void firstPage() {
262 fLoader
.waitForCompletion();
263 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
267 * @param page number to set
269 public void setPage(final int page
) {
270 fLoader
.pageNumberChanged(page
);
271 fLoader
.waitForCompletion();
272 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
276 * @see org.eclipse.linuxtools.tmf.ui.tests.views.uml2sd.loader.Uml2SDTestFacility#selectExperiment(boolean)
278 public void selectExperiment() {
279 this.selectExperiment(true);
283 * Selects the experiment.
284 * @param wait true to wait for indexing to finish else false
286 public void selectExperiment(final boolean wait
) {
287 fParser
= new TmfUml2SDTestTrace();
288 fTrace
= setupTrace(fParser
);
289 fParser
.setTrace(fTrace
);
291 // fTrace = setupTrace(fParser);
293 final ITmfTrace traces
[] = new ITmfTrace
[1];
295 fExperiment
= new TmfExperiment(TmfEvent
.class, "TestExperiment", traces
); //$NON-NLS-1$
296 fTrace
.broadcast(new TmfExperimentSelectedSignal(this, fExperiment
));
298 while (fExperiment
.getNbEvents() == 0) {
299 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
302 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
307 * Disposes the experiment.
309 public void disposeExperiment() {
310 fExperiment
.dispose();
311 delay(IUml2SDTestConstants
.GUI_REFESH_DELAY
);
315 * Creates some global filter criteria and saves them to disk.
317 public void createFilterCriteria() {
318 // Create Filter Criteria and save tme
319 final List
<FilterCriteria
> filterToSave
= new ArrayList
<FilterCriteria
>();
320 Criteria criteria
= new Criteria();
321 criteria
.setLifeLineSelected(true);
322 criteria
.setExpression(IUml2SDTestConstants
.FIRST_PLAYER_NAME
);
323 filterToSave
.add(new FilterCriteria(criteria
, true, false));
325 criteria
= new Criteria();
326 criteria
.setSyncMessageSelected(true);
327 criteria
.setExpression("BALL_.*"); //$NON-NLS-1$
328 filterToSave
.add(new FilterCriteria(criteria
, true, false));
329 FilterListDialog
.saveFiltersCriteria(filterToSave
);