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 *******************************************************************************/
13 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.model
.component
;
15 import org
.eclipse
.core
.commands
.ExecutionException
;
16 import org
.eclipse
.core
.commands
.NotEnabledException
;
17 import org
.eclipse
.core
.commands
.NotHandledException
;
18 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
19 import org
.eclipse
.core
.runtime
.jobs
.Job
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
22 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
23 import org
.eclipse
.swt
.widgets
.Display
;
24 import org
.eclipse
.ui
.IViewPart
;
25 import org
.eclipse
.ui
.PartInitException
;
26 import org
.eclipse
.ui
.PlatformUI
;
27 import org
.eclipse
.ui
.handlers
.IHandlerService
;
30 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
31 * utility methods for interacting with the loader/view.
33 @SuppressWarnings("javadoc")
34 public class TraceControlTestFacility
{
36 // ------------------------------------------------------------------------
38 // ------------------------------------------------------------------------
39 public final static int WAIT_FOR_JOBS_DELAY
= 1000;
40 public final static int GUI_REFESH_DELAY
= 500;
42 public final static String DIRECTORY
= "testfiles"; //$NON-NLS-1$
43 public final static String COMMAND_CATEGORY_PREFIX
= "org.eclipse.linuxtools.internal.lttng2.ui.commands.control."; //$NON-NLS-1$
44 public final static String SCEN_INIT_TEST
= "Initialize"; //$NON-NLS-1$
45 public final static String SCEN_SCENARIO_SESSION_HANDLING
= "SessionHandling"; //$NON-NLS-1$
46 public final static String SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
= "SessionHandlingWithPath"; //$NON-NLS-1$
48 // ------------------------------------------------------------------------
50 // ------------------------------------------------------------------------
51 private static TraceControlTestFacility fInstance
= null;
52 private ControlView fControlView
= null;
53 private boolean fIsInitialized
= false;
55 // ------------------------------------------------------------------------
57 // ------------------------------------------------------------------------
58 private TraceControlTestFacility() {
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
64 public static TraceControlTestFacility
getInstance() {
65 if (fInstance
== null) {
66 fInstance
= new TraceControlTestFacility();
72 * Initial the test facility.
76 if (!fIsInitialized
) {
81 view
= PlatformUI
.getWorkbench()
82 .getActiveWorkbenchWindow()
84 .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
87 PlatformUI
.getWorkbench()
88 .getActiveWorkbenchWindow()
89 .getActivePage().hideView(view
);
92 view
= PlatformUI
.getWorkbench()
93 .getActiveWorkbenchWindow()
95 .showView(ControlView
.ID
);
97 } catch (PartInitException e
) {
98 throw new RuntimeException(e
);
101 fControlView
= (ControlView
) view
;
104 fIsInitialized
= true;
110 * Disposes the facility (and GUI)
112 public void dispose() {
113 if (fIsInitialized
) {
116 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView
);
117 fIsInitialized
= false;
122 * Creates a delay for given time.
123 * @param waitTimeMillis - time in milli seconds
125 public void delay(long waitTimeMillis
) {
126 Display display
= Display
.getCurrent();
127 if (display
!= null) {
128 long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
129 while(System
.currentTimeMillis() < endTimeMillis
) {
130 if (!display
.readAndDispatch()) {
137 Thread
.sleep(waitTimeMillis
);
138 } catch (InterruptedException e
) {
145 * Waits for all Eclipse jobs to finish
147 public void waitForJobs() {
148 while (!Job
.getJobManager().isIdle()) {
149 delay(WAIT_FOR_JOBS_DELAY
);
154 * @return current control view
156 public ControlView
getControlView() {
161 * Executes an Eclipse command with command ID after selecting passed component
162 * @param component - component to select in the tree
163 * @param commandId - command ID
164 * @throws ExecutionException
165 * @throws NotDefinedException
166 * @throws NotEnabledException
167 * @throws NotHandledException
169 public void executeCommand(ITraceControlComponent component
, String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
170 setSelection(component
);
171 executeCommand(commandId
);
175 * Executes an Eclipse command with command ID after selecting passed components
176 * @param components - array of components to select in the tree
177 * @param commandId - command ID
178 * @throws ExecutionException
179 * @throws NotDefinedException
180 * @throws NotEnabledException
181 * @throws NotHandledException
183 public void executeCommand(ITraceControlComponent
[] components
, String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
184 setSelection(components
);
185 executeCommand(commandId
);
189 * Executes an Eclipse command with command ID
191 * @throws ExecutionException
192 * @throws NotDefinedException
193 * @throws NotEnabledException
194 * @throws NotHandledException
196 public void executeCommand(String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
197 IHandlerService handlerService
= (IHandlerService
) fControlView
.getSite().getService(IHandlerService
.class);
198 handlerService
.executeCommand(COMMAND_CATEGORY_PREFIX
+ commandId
, null);
203 * Selects passed component
204 * @param component - component to select in the tree
205 * @param commandId - command ID
207 public void setSelection(ITraceControlComponent component
) {
208 fControlView
.setSelection(component
);
209 // Selection is done in own job
215 * Selects passed components
216 * @param components - array of component to select in the tree
217 * @param commandId - command ID
219 public void setSelection(ITraceControlComponent
[] components
) {
220 fControlView
.setSelection(components
);
222 // Selection is done in own job
227 * Creates session on passed session group.
228 * @param group - session group
229 * @return - trace session group if it's successful else null
230 * @throws ExecutionException
231 * @throws NotDefinedException
232 * @throws NotEnabledException
233 * @throws NotHandledException
235 @SuppressWarnings("nls")
236 public TraceSessionComponent
createSession(ITraceControlComponent group
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
237 executeCommand(group
, "createSession");
239 ITraceControlComponent
[] sessions
= group
.getChildren();
240 if ((sessions
== null) || (sessions
.length
== 0)) {
243 return (TraceSessionComponent
)sessions
[0];
247 * Destroys a given session.
248 * @param session - session to destroy
249 * @throws ExecutionException
250 * @throws NotDefinedException
251 * @throws NotEnabledException
252 * @throws NotHandledException
254 @SuppressWarnings("nls")
255 public void destroySession(TraceSessionComponent session
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
256 executeCommand(session
, "destroySession");
260 * Starts a given session
261 * @param session - session to start
262 * @throws ExecutionException
263 * @throws NotDefinedException
264 * @throws NotEnabledException
265 * @throws NotHandledException
267 @SuppressWarnings("nls")
268 public void startSession(TraceSessionComponent session
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
269 executeCommand(session
, "start");
273 * Stops a given session
274 * @param session - session to stop
275 * @throws ExecutionException
276 * @throws NotDefinedException
277 * @throws NotEnabledException
278 * @throws NotHandledException
280 @SuppressWarnings("nls")
281 public void stopSession(TraceSessionComponent session
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
282 executeCommand(session
, "stop");