1 /**********************************************************************
2 * Copyright (c) 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
.lttng2
.ui
.tests
.control
.model
.component
;
17 import static org
.junit
.Assert
.assertEquals
;
18 import static org
.junit
.Assert
.assertNotNull
;
19 import static org
.junit
.Assert
.assertTrue
;
21 import org
.eclipse
.core
.runtime
.FileLocator
;
22 import org
.eclipse
.core
.runtime
.Path
;
23 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TargetNodeState
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.core
.control
.model
.TraceSessionState
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.CreateSessionDialogStub
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.dialogs
.DestroyConfirmDialogStub
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.stubs
.service
.TestRemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.dialogs
.TraceControlDialogFactory
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.ITraceControlComponent
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TargetNodeComponent
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.ui
.views
.control
.model
.impl
.TraceSessionComponent
;
32 import org
.eclipse
.rse
.core
.RSECorePlugin
;
33 import org
.eclipse
.rse
.core
.model
.IHost
;
34 import org
.eclipse
.rse
.core
.model
.ISystemProfile
;
35 import org
.eclipse
.rse
.core
.model
.ISystemRegistry
;
36 import org
.junit
.After
;
37 import org
.junit
.Before
;
38 import org
.junit
.Test
;
39 import org
.osgi
.framework
.FrameworkUtil
;
42 * The class <code>TraceControlKernelSessionTests</code> contains Kernel session/channel/event
43 * handling test cases.
46 @SuppressWarnings({"nls", "javadoc"})
47 public class TraceControlCreateSessionTests
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
52 private static final String TEST_STREAM
= "CreateSessionTest.cfg";
53 private static final String SCEN_SCENARIO_NO_CONSUMER_TEST
= "CreateSessionNoConsumer";
54 private static final String SCEN_SCENARIO_DISABLE_CONSUMER_TEST
= "CreateSessionDisableConsumer";
55 private static final String SCEN_SCENARIO_FILE_PROTO_TEST
= "CreateSessionFileProto";
56 private static final String SCEN_SCENARIO_CONTROL_DATA_TEST
= "CreateSessionControlData";
57 private static final String SCEN_SCENARIO_NETWORK_TEST
= "CreateSessionNetwork";
59 // ------------------------------------------------------------------------
61 // ------------------------------------------------------------------------
62 private TraceControlTestFacility fFacility
;
63 private TestRemoteSystemProxy fProxy
;
64 private String fTestFile
;
66 // ------------------------------------------------------------------------
68 // ------------------------------------------------------------------------
71 * Perform pre-test initialization.
74 * if the initialization fails for some reason
78 public void setUp() throws Exception
{
79 fFacility
= TraceControlTestFacility
.getInstance();
80 fProxy
= new TestRemoteSystemProxy();
81 URL location
= FileLocator
.find(FrameworkUtil
.getBundle(this.getClass()), new Path(TraceControlTestFacility
.DIRECTORY
+ File
.separator
+ TEST_STREAM
), null);
82 File testfile
= new File(FileLocator
.toFileURL(location
).toURI());
83 fTestFile
= testfile
.getAbsolutePath();
87 * Perform post-test clean-up.
90 * if the clean-up fails for some reason
94 public void tearDown() {
95 fFacility
.waitForJobs();
99 * Run the TraceControlComponent.
102 public void testTraceSessionTree() throws Exception
{
104 fProxy
.setTestFile(fTestFile
);
105 fProxy
.setScenario(TraceControlTestFacility
.SCEN_INIT_TEST
);
107 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
109 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
110 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
111 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
113 TargetNodeComponent node
= new TargetNodeComponent("myNode", root
, host
, fProxy
);
116 fFacility
.waitForJobs();
118 fFacility
.executeCommand(node
, "connect");
120 while ((i
< 10) && (node
.getTargetNodeState() != TargetNodeState
.CONNECTED
)) {
122 fFacility
.delay(TraceControlTestFacility
.GUI_REFESH_DELAY
);
125 // Verify that node is connected
126 assertEquals(TargetNodeState
.CONNECTED
, node
.getTargetNodeState());
128 // Get provider groups
129 ITraceControlComponent
[] groups
= node
.getChildren();
130 assertNotNull(groups
);
131 assertEquals(2, groups
.length
);
133 // Initialize dialog implementations for command execution
134 CreateSessionDialogStub sessionDialogStub
= new CreateSessionDialogStub();
135 TraceControlDialogFactory
.getInstance().setCreateSessionDialog(sessionDialogStub
);
136 TraceControlDialogFactory
.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
138 // Initialize session handling scenario
139 fProxy
.setScenario(SCEN_SCENARIO_NO_CONSUMER_TEST
);
141 // ------------------------------------------------------------------------
142 // Create session (--no-consumer) and destroy
143 // ------------------------------------------------------------------------
144 // Initialize session handling scenario
145 fProxy
.setScenario(SCEN_SCENARIO_NO_CONSUMER_TEST
);
146 sessionDialogStub
.setNoConsumer(true);
147 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
149 // Verify that session was created
150 assertNotNull(session
);
151 assertEquals("mysession", session
.getName());
152 assertEquals("", session
.getSessionPath());
153 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
154 sessionDialogStub
.setNoConsumer(false);
156 fFacility
.destroySession(session
);
158 // Verify that no more session components exist
159 assertEquals(0, groups
[1].getChildren().length
);
161 // ------------------------------------------------------------------------
162 // Create session (--disable-consumer) and destroy
163 // ------------------------------------------------------------------------
164 // Initialize session handling scenario
165 fProxy
.setScenario(SCEN_SCENARIO_DISABLE_CONSUMER_TEST
);
167 sessionDialogStub
.setDisableConsumer(true);
168 session
= fFacility
.createSession(groups
[1]);
170 // Verify that session was created
171 assertNotNull(session
);
172 assertEquals("mysession", session
.getName());
173 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
174 sessionDialogStub
.setDisableConsumer(false);
176 fFacility
.destroySession(session
);
178 // Verify that no more session components exist
179 assertEquals(0, groups
[1].getChildren().length
);
181 // ------------------------------------------------------------------------
182 // Create session (--U file://...) and destroy
183 // ------------------------------------------------------------------------
184 // Initialize session handling scenario
185 fProxy
.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST
);
187 sessionDialogStub
.setNetworkUrl("file:///tmp");
188 sessionDialogStub
.setStreamedTrace(true);
189 session
= fFacility
.createSession(groups
[1]);
191 // Verify that session was created
192 assertNotNull(session
);
193 assertEquals("mysession", session
.getName());
194 assertEquals("file:///tmp", session
.getSessionPath());
195 assertTrue(session
.isStreamedTrace());
196 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
197 sessionDialogStub
.setNetworkUrl(null);
198 sessionDialogStub
.setStreamedTrace(false);
200 fFacility
.destroySession(session
);
202 // Verify that no more session components exist
203 assertEquals(0, groups
[1].getChildren().length
);
205 // ------------------------------------------------------------------------
206 // Create session (--U file://,,, and destroy
207 // ------------------------------------------------------------------------
208 // Initialize session handling scenario
209 fProxy
.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST
);
211 sessionDialogStub
.setControlUrl("tcp://172.0.0.1");
212 sessionDialogStub
.setDataUrl("tcp://172.0.0.1:5343");
213 sessionDialogStub
.setStreamedTrace(true);
215 session
= fFacility
.createSession(groups
[1]);
217 // Verify that session was created
218 assertNotNull(session
);
219 assertEquals("mysession", session
.getName());
220 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session
.getSessionPath());
221 assertTrue(session
.isStreamedTrace());
222 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
223 sessionDialogStub
.setControlUrl(null);
224 sessionDialogStub
.setDataUrl(null);
225 sessionDialogStub
.setStreamedTrace(false);
227 fFacility
.destroySession(session
);
229 // Verify that no more session components exist
230 assertEquals(0, groups
[1].getChildren().length
);
232 // ------------------------------------------------------------------------
233 // Create session (--U file://,,, and destroy
234 // ------------------------------------------------------------------------
235 // Initialize session handling scenario
236 fProxy
.setScenario(SCEN_SCENARIO_NETWORK_TEST
);
238 sessionDialogStub
.setNetworkUrl("net://172.0.0.1:1234:2345");
239 sessionDialogStub
.setStreamedTrace(true);
241 session
= fFacility
.createSession(groups
[1]);
243 // Verify that session was created
244 assertNotNull(session
);
245 assertEquals("mysession", session
.getName());
246 assertEquals("net://172.0.0.1:1234 [data: 2345]", session
.getSessionPath());
247 assertTrue(session
.isStreamedTrace());
248 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
249 sessionDialogStub
.setNetworkUrl(null);
251 fFacility
.destroySession(session
);
253 // Verify that no more session components exist
254 assertEquals(0, groups
[1].getChildren().length
);
256 //-------------------------------------------------------------------------
258 //-------------------------------------------------------------------------
259 fFacility
.executeCommand(node
, "disconnect");
260 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
262 //-------------------------------------------------------------------------
264 //-------------------------------------------------------------------------
266 fFacility
.executeCommand(node
, "delete");
267 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);