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
.lttng2
.ui
.tests
.control
.model
.component
;
14 import org
.eclipse
.core
.commands
.ExecutionException
;
15 import org
.eclipse
.core
.commands
.NotEnabledException
;
16 import org
.eclipse
.core
.commands
.NotHandledException
;
17 import org
.eclipse
.core
.commands
.common
.NotDefinedException
;
18 import org
.eclipse
.core
.runtime
.jobs
.Job
;
19 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.ControlView
;
20 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
21 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
22 import org
.eclipse
.swt
.widgets
.Display
;
23 import org
.eclipse
.ui
.IViewPart
;
24 import org
.eclipse
.ui
.PartInitException
;
25 import org
.eclipse
.ui
.PlatformUI
;
26 import org
.eclipse
.ui
.handlers
.IHandlerService
;
29 * Singleton class to facilitate the test cases. Creates UML2SD view and loader objects as well as provides
30 * utility methods for interacting with the loader/view.
32 public class TraceControlTestFacility
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
37 public final static int WAIT_FOR_JOBS_DELAY
= 1000;
38 public final static int GUI_REFESH_DELAY
= 500;
40 public final static String DIRECTORY
= "testfiles"; //$NON-NLS-1$
41 public final static String COMMAND_CATEGORY_PREFIX
= "org.eclipse.linuxtools.internal.lttng2.ui.commands.control."; //$NON-NLS-1$
42 public final static String SCEN_INIT_TEST
= "Initialize"; //$NON-NLS-1$
43 public final static String SCEN_SCENARIO_SESSION_HANDLING
= "SessionHandling"; //$NON-NLS-1$
44 public final static String SCEN_SCENARIO_SESSION_HANDLING_WITH_PATH
= "SessionHandlingWithPath"; //$NON-NLS-1$
46 // ------------------------------------------------------------------------
48 // ------------------------------------------------------------------------
49 private static TraceControlTestFacility fInstance
= null;
50 private ControlView fControlView
= null;
51 private boolean fIsInitialized
= false;
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
56 private TraceControlTestFacility() {
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
62 public static TraceControlTestFacility
getInstance() {
63 if (fInstance
== null) {
64 fInstance
= new TraceControlTestFacility();
70 * Initial the test facility.
74 if (!fIsInitialized
) {
79 view
= PlatformUI
.getWorkbench()
80 .getActiveWorkbenchWindow()
82 .findView("org.eclipse.ui.internal.introview"); //$NON-NLS-1$
85 PlatformUI
.getWorkbench()
86 .getActiveWorkbenchWindow()
87 .getActivePage().hideView(view
);
90 view
= PlatformUI
.getWorkbench()
91 .getActiveWorkbenchWindow()
93 .showView(ControlView
.ID
);
95 } catch (PartInitException e
) {
96 throw new RuntimeException(e
);
99 fControlView
= (ControlView
) view
;
102 fIsInitialized
= true;
108 * Disposes the facility (and GUI)
110 public void dispose() {
111 if (fIsInitialized
) {
114 PlatformUI
.getWorkbench().getActiveWorkbenchWindow().getActivePage().hideView(fControlView
);
115 fIsInitialized
= false;
120 * Creates a delay for given time.
121 * @param waitTimeMillis - time in milli seconds
123 public void delay(long waitTimeMillis
) {
124 Display display
= Display
.getCurrent();
125 if (display
!= null) {
126 long endTimeMillis
= System
.currentTimeMillis() + waitTimeMillis
;
127 while(System
.currentTimeMillis() < endTimeMillis
) {
128 if (!display
.readAndDispatch()) {
135 Thread
.sleep(waitTimeMillis
);
136 } catch (InterruptedException e
) {
143 * Waits for all Eclipse jobs to finish
145 public void waitForJobs() {
146 while (!Job
.getJobManager().isIdle()) {
147 delay(WAIT_FOR_JOBS_DELAY
);
152 * @return current control view
154 public ControlView
getControlView() {
159 * Executes an Eclipse command with command ID after selecting passed component
160 * @param component - component to select in the tree
161 * @param commandId - command ID
162 * @throws ExecutionException
163 * @throws NotDefinedException
164 * @throws NotEnabledException
165 * @throws NotHandledException
167 public void executeCommand(ITraceControlComponent component
, String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
168 setSelection(component
);
169 executeCommand(commandId
);
173 * Executes an Eclipse command with command ID after selecting passed components
174 * @param components - array of components to select in the tree
175 * @param commandId - command ID
176 * @throws ExecutionException
177 * @throws NotDefinedException
178 * @throws NotEnabledException
179 * @throws NotHandledException
181 public void executeCommand(ITraceControlComponent
[] components
, String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
182 setSelection(components
);
183 executeCommand(commandId
);
187 * Executes an Eclipse command with command ID
189 * @throws ExecutionException
190 * @throws NotDefinedException
191 * @throws NotEnabledException
192 * @throws NotHandledException
194 public void executeCommand(String commandId
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
195 IHandlerService handlerService
= (IHandlerService
) fControlView
.getSite().getService(IHandlerService
.class);
196 handlerService
.executeCommand(COMMAND_CATEGORY_PREFIX
+ commandId
, null);
201 * Selects passed component
202 * @param component - component to select in the tree
203 * @param commandId - command ID
205 public void setSelection(ITraceControlComponent component
) {
206 fControlView
.setSelection(component
);
207 // Selection is done in own job
213 * Selects passed components
214 * @param components - array of component to select in the tree
215 * @param commandId - command ID
217 public void setSelection(ITraceControlComponent
[] components
) {
218 fControlView
.setSelection(components
);
220 // Selection is done in own job
225 * Creates session on passed session group.
226 * @param group - session group
227 * @return - trace session group if it's successful else null
228 * @throws ExecutionException
229 * @throws NotDefinedException
230 * @throws NotEnabledException
231 * @throws NotHandledException
233 @SuppressWarnings("nls")
234 public TraceSessionComponent
createSession(ITraceControlComponent group
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
235 executeCommand(group
, "createSession");
237 ITraceControlComponent
[] sessions
= group
.getChildren();
238 if ((sessions
== null) || (sessions
.length
== 0)) {
241 return (TraceSessionComponent
)sessions
[0];
245 * Destroys a given session.
246 * @param session - session to destroy
247 * @throws ExecutionException
248 * @throws NotDefinedException
249 * @throws NotEnabledException
250 * @throws NotHandledException
252 @SuppressWarnings("nls")
253 public void destroySession(TraceSessionComponent session
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
254 executeCommand(session
, "destroySession");
258 * Starts a given session
259 * @param session - session to start
260 * @throws ExecutionException
261 * @throws NotDefinedException
262 * @throws NotEnabledException
263 * @throws NotHandledException
265 @SuppressWarnings("nls")
266 public void startSession(TraceSessionComponent session
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
267 executeCommand(session
, "start");
271 * Stops a given session
272 * @param session - session to stop
273 * @throws ExecutionException
274 * @throws NotDefinedException
275 * @throws NotEnabledException
276 * @throws NotHandledException
278 @SuppressWarnings("nls")
279 public void stopSession(TraceSessionComponent session
) throws ExecutionException
, NotDefinedException
, NotEnabledException
, NotHandledException
{
280 executeCommand(session
, "stop");