4ff93b0ad8dd8efb9238019da16d57297edae521
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / model / component / TraceControlCreateSessionTests.java
1 /**********************************************************************
2 * Copyright (c) 2013 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 **********************************************************************/
12 package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertNotNull;
16 import static org.junit.Assert.assertTrue;
17
18 import java.io.File;
19 import java.net.URL;
20
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;
40
41 /**
42 * The class <code>TraceControlKernelSessionTests</code> contains Kernel session/channel/event
43 * handling test cases.
44 */
45
46 @SuppressWarnings("javadoc")
47 public class TraceControlCreateSessionTests {
48
49 // ------------------------------------------------------------------------
50 // Constants
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";
57
58 // ------------------------------------------------------------------------
59 // Test data
60 // ------------------------------------------------------------------------
61 private TraceControlTestFacility fFacility;
62 private TestRemoteSystemProxy fProxy;
63 private String fTestFile;
64
65 // ------------------------------------------------------------------------
66 // Housekeeping
67 // ------------------------------------------------------------------------
68
69 /**
70 * Perform pre-test initialization.
71 *
72 * @throws Exception
73 * if the initialization fails for some reason
74 *
75 */
76 @Before
77 public void setUp() throws Exception {
78 fFacility = TraceControlTestFacility.getInstance();
79 fFacility.init();
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();
84 }
85
86 /**
87 * Perform post-test clean-up.
88 *
89 * @throws Exception
90 * if the clean-up fails for some reason
91 *
92 */
93 @After
94 public void tearDown() {
95 fFacility.waitForJobs();
96 }
97
98 /**
99 * Run the TraceControlComponent.
100 */
101 @Test
102 public void testTraceSessionTree() throws Exception {
103
104 fProxy.setTestFile(fTestFile);
105 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
106
107 ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
108
109 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
110 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
111 IHost host = registry.createLocalHost(profile, "myProfile", "user");
112
113 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
114
115 root.addChild(node);
116 fFacility.waitForJobs();
117
118 fFacility.executeCommand(node, "connect");
119 int i = 0;
120 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
121 i++;
122 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
123 }
124
125 // Verify that node is connected
126 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
127
128 // Get provider groups
129 ITraceControlComponent[] groups = node.getChildren();
130 assertNotNull(groups);
131 assertEquals(2, groups.length);
132
133 // Initialize dialog implementations for command execution
134 CreateSessionDialogStub sessionDialogStub = new CreateSessionDialogStub();
135 TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialogStub);
136 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
137
138 // ------------------------------------------------------------------------
139 // Create session (--U file://...) and destroy
140 // ------------------------------------------------------------------------
141 // Initialize session handling scenario
142 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
143
144 sessionDialogStub.setNetworkUrl("file:///tmp");
145 sessionDialogStub.setStreamedTrace(true);
146 TraceSessionComponent session = fFacility.createSession(groups[1]);
147
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);
156
157 fFacility.destroySession(session);
158
159 // Verify that no more session components exist
160 assertEquals(0, groups[1].getChildren().length);
161
162 // ------------------------------------------------------------------------
163 // Create session (--U file://,,, and destroy
164 // ------------------------------------------------------------------------
165 // Initialize session handling scenario
166 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
167
168 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
169 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
170 sessionDialogStub.setStreamedTrace(true);
171
172 session = fFacility.createSession(groups[1]);
173
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);
183
184 fFacility.destroySession(session);
185
186 // Verify that no more session components exist
187 assertEquals(0, groups[1].getChildren().length);
188
189 // ------------------------------------------------------------------------
190 // Create session (--U file://... and destroy
191 // ------------------------------------------------------------------------
192 // Initialize session handling scenario
193 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
194
195 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
196 sessionDialogStub.setStreamedTrace(true);
197
198 session = fFacility.createSession(groups[1]);
199
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);
207
208 fFacility.destroySession(session);
209
210 // Verify that no more session components exist
211 assertEquals(0, groups[1].getChildren().length);
212
213 // ------------------------------------------------------------------------
214 // Create session (--U net6://[...] and destroy
215 // ------------------------------------------------------------------------
216 // Initialize session handling scenario
217 fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST);
218
219 sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
220 sessionDialogStub.setStreamedTrace(true);
221
222 session = fFacility.createSession(groups[1]);
223
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);
231
232 fFacility.destroySession(session);
233
234 // Verify that no more session components exist
235 assertEquals(0, groups[1].getChildren().length);
236
237
238 //-------------------------------------------------------------------------
239 // Disconnect node
240 //-------------------------------------------------------------------------
241 fFacility.executeCommand(node, "disconnect");
242 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
243
244 //-------------------------------------------------------------------------
245 // Delete node
246 //-------------------------------------------------------------------------
247
248 fFacility.executeCommand(node, "delete");
249 assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
250 }
251
252 }
This page took 0.037513 seconds and 5 git commands to generate.