1 /**********************************************************************
2 * Copyright (c) 2013 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
.control
.ui
.tests
.model
.component
;
14 import static org
.junit
.Assert
.assertEquals
;
15 import static org
.junit
.Assert
.assertNotNull
;
16 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
.control
.core
.model
.TargetNodeState
;
24 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.core
.model
.TraceSessionState
;
25 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.CreateSessionDialogStub
;
26 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.dialogs
.DestroyConfirmDialogStub
;
27 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.stubs
.service
.TestRemoteSystemProxy
;
28 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.dialogs
.TraceControlDialogFactory
;
29 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.ITraceControlComponent
;
30 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.model
.impl
.TargetNodeComponent
;
31 import org
.eclipse
.linuxtools
.internal
.lttng2
.control
.ui
.views
.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("javadoc")
47 public class TraceControlCreateSessionTests
{
49 // ------------------------------------------------------------------------
51 // ------------------------------------------------------------------------
52 private static final String TEST_STREAM
= "CreateSessionTest.cfg";
53 private static final String SCEN_SCENARIO_FILE_PROTO_TEST
= "CreateSessionFileProto";
54 private static final String SCEN_SCENARIO_CONTROL_DATA_TEST
= "CreateSessionControlData";
55 private static final String SCEN_SCENARIO_NETWORK_TEST
= "CreateSessionNetwork";
56 private static final String SCEN_SCENARIO_NETWORK2_TEST
= "CreateSessionNetwork2";
58 // ------------------------------------------------------------------------
60 // ------------------------------------------------------------------------
61 private TraceControlTestFacility fFacility
;
62 private TestRemoteSystemProxy fProxy
;
63 private String fTestFile
;
65 // ------------------------------------------------------------------------
67 // ------------------------------------------------------------------------
70 * Perform pre-test initialization.
73 * if the initialization fails for some reason
77 public void setUp() throws Exception
{
78 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 // ------------------------------------------------------------------------
139 // Create session (--U file://...) and destroy
140 // ------------------------------------------------------------------------
141 // Initialize session handling scenario
142 fProxy
.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST
);
144 sessionDialogStub
.setNetworkUrl("file:///tmp");
145 sessionDialogStub
.setStreamedTrace(true);
146 TraceSessionComponent session
= fFacility
.createSession(groups
[1]);
148 // Verify that session was created
149 assertNotNull(session
);
150 assertEquals("mysession", session
.getName());
151 assertEquals("file:///tmp", session
.getSessionPath());
152 assertTrue(!session
.isStreamedTrace());
153 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
154 sessionDialogStub
.setNetworkUrl(null);
155 sessionDialogStub
.setStreamedTrace(false);
157 fFacility
.destroySession(session
);
159 // Verify that no more session components exist
160 assertEquals(0, groups
[1].getChildren().length
);
162 // ------------------------------------------------------------------------
163 // Create session (--U file://,,, and destroy
164 // ------------------------------------------------------------------------
165 // Initialize session handling scenario
166 fProxy
.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST
);
168 sessionDialogStub
.setControlUrl("tcp://172.0.0.1");
169 sessionDialogStub
.setDataUrl("tcp://172.0.0.1:5343");
170 sessionDialogStub
.setStreamedTrace(true);
172 session
= fFacility
.createSession(groups
[1]);
174 // Verify that session was created
175 assertNotNull(session
);
176 assertEquals("mysession", session
.getName());
177 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session
.getSessionPath());
178 assertTrue(session
.isStreamedTrace());
179 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
180 sessionDialogStub
.setControlUrl(null);
181 sessionDialogStub
.setDataUrl(null);
182 sessionDialogStub
.setStreamedTrace(false);
184 fFacility
.destroySession(session
);
186 // Verify that no more session components exist
187 assertEquals(0, groups
[1].getChildren().length
);
189 // ------------------------------------------------------------------------
190 // Create session (--U file://... and destroy
191 // ------------------------------------------------------------------------
192 // Initialize session handling scenario
193 fProxy
.setScenario(SCEN_SCENARIO_NETWORK_TEST
);
195 sessionDialogStub
.setNetworkUrl("net://172.0.0.1:1234:2345");
196 sessionDialogStub
.setStreamedTrace(true);
198 session
= fFacility
.createSession(groups
[1]);
200 // Verify that session was created
201 assertNotNull(session
);
202 assertEquals("mysession", session
.getName());
203 assertEquals("net://172.0.0.1:1234 [data: 2345]", session
.getSessionPath());
204 assertTrue(session
.isStreamedTrace());
205 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
206 sessionDialogStub
.setNetworkUrl(null);
208 fFacility
.destroySession(session
);
210 // Verify that no more session components exist
211 assertEquals(0, groups
[1].getChildren().length
);
213 // ------------------------------------------------------------------------
214 // Create session (--U net6://[...] and destroy
215 // ------------------------------------------------------------------------
216 // Initialize session handling scenario
217 fProxy
.setScenario(SCEN_SCENARIO_NETWORK2_TEST
);
219 sessionDialogStub
.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
220 sessionDialogStub
.setStreamedTrace(true);
222 session
= fFacility
.createSession(groups
[1]);
224 // Verify that session was created
225 assertNotNull(session
);
226 assertEquals("mysession", session
.getName());
227 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session
.getSessionPath());
228 assertTrue(session
.isStreamedTrace());
229 assertEquals(TraceSessionState
.INACTIVE
, session
.getSessionState());
230 sessionDialogStub
.setNetworkUrl(null);
232 fFacility
.destroySession(session
);
234 // Verify that no more session components exist
235 assertEquals(0, groups
[1].getChildren().length
);
238 //-------------------------------------------------------------------------
240 //-------------------------------------------------------------------------
241 fFacility
.executeCommand(node
, "disconnect");
242 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
244 //-------------------------------------------------------------------------
246 //-------------------------------------------------------------------------
248 fFacility
.executeCommand(node
, "delete");
249 assertEquals(0,fFacility
.getControlView().getTraceControlRoot().getChildren().length
);