Update file headers in LTTng Control feature
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / model / component / TraceControlCreateSessionTests.java
CommitLineData
f3b33d40 1/**********************************************************************
ba3a9bd2 2 * Copyright (c) 2013 Ericsson
f3b33d40
BH
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 **********************************************************************/
12package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
13
14import java.io.File;
15import java.net.URL;
16
17import static org.junit.Assert.assertEquals;
18import static org.junit.Assert.assertNotNull;
19import static org.junit.Assert.assertTrue;
20
21import org.eclipse.core.runtime.FileLocator;
22import org.eclipse.core.runtime.Path;
23import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
24import org.eclipse.linuxtools.internal.lttng2.core.control.model.TraceSessionState;
25import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.CreateSessionDialogStub;
26import org.eclipse.linuxtools.internal.lttng2.stubs.dialogs.DestroyConfirmDialogStub;
27import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
28import org.eclipse.linuxtools.internal.lttng2.ui.views.control.dialogs.TraceControlDialogFactory;
29import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
30import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
31import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
32import org.eclipse.rse.core.RSECorePlugin;
33import org.eclipse.rse.core.model.IHost;
34import org.eclipse.rse.core.model.ISystemProfile;
35import org.eclipse.rse.core.model.ISystemRegistry;
36import org.junit.After;
37import org.junit.Before;
38import org.junit.Test;
39import 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({"nls", "javadoc"})
47public class TraceControlCreateSessionTests {
48
49 // ------------------------------------------------------------------------
50 // Constants
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";
58
59 // ------------------------------------------------------------------------
60 // Test data
61 // ------------------------------------------------------------------------
62 private TraceControlTestFacility fFacility;
63 private TestRemoteSystemProxy fProxy;
64 private String fTestFile;
65
66 // ------------------------------------------------------------------------
67 // Housekeeping
68 // ------------------------------------------------------------------------
69
70 /**
71 * Perform pre-test initialization.
72 *
73 * @throws Exception
74 * if the initialization fails for some reason
75 *
76 */
77 @Before
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();
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 // Initialize session handling scenario
139 fProxy.setScenario(SCEN_SCENARIO_NO_CONSUMER_TEST);
140
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]);
148
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);
155
156 fFacility.destroySession(session);
157
158 // Verify that no more session components exist
159 assertEquals(0, groups[1].getChildren().length);
160
161 // ------------------------------------------------------------------------
162 // Create session (--disable-consumer) and destroy
163 // ------------------------------------------------------------------------
164 // Initialize session handling scenario
165 fProxy.setScenario(SCEN_SCENARIO_DISABLE_CONSUMER_TEST);
166
167 sessionDialogStub.setDisableConsumer(true);
168 session = fFacility.createSession(groups[1]);
169
170 // Verify that session was created
171 assertNotNull(session);
172 assertEquals("mysession", session.getName());
173 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
174 sessionDialogStub.setDisableConsumer(false);
175
176 fFacility.destroySession(session);
177
178 // Verify that no more session components exist
179 assertEquals(0, groups[1].getChildren().length);
180
181 // ------------------------------------------------------------------------
182 // Create session (--U file://...) and destroy
183 // ------------------------------------------------------------------------
184 // Initialize session handling scenario
185 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
186
187 sessionDialogStub.setNetworkUrl("file:///tmp");
188 sessionDialogStub.setStreamedTrace(true);
189 session = fFacility.createSession(groups[1]);
190
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);
199
200 fFacility.destroySession(session);
201
202 // Verify that no more session components exist
203 assertEquals(0, groups[1].getChildren().length);
204
205 // ------------------------------------------------------------------------
206 // Create session (--U file://,,, and destroy
207 // ------------------------------------------------------------------------
208 // Initialize session handling scenario
209 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
210
211 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
212 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
213 sessionDialogStub.setStreamedTrace(true);
214
215 session = fFacility.createSession(groups[1]);
216
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);
226
227 fFacility.destroySession(session);
228
229 // Verify that no more session components exist
230 assertEquals(0, groups[1].getChildren().length);
231
232 // ------------------------------------------------------------------------
233 // Create session (--U file://,,, and destroy
234 // ------------------------------------------------------------------------
235 // Initialize session handling scenario
236 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
237
238 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
239 sessionDialogStub.setStreamedTrace(true);
240
241 session = fFacility.createSession(groups[1]);
242
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);
250
251 fFacility.destroySession(session);
252
253 // Verify that no more session components exist
254 assertEquals(0, groups[1].getChildren().length);
255
256 //-------------------------------------------------------------------------
257 // Disconnect node
258 //-------------------------------------------------------------------------
259 fFacility.executeCommand(node, "disconnect");
260 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
261
262 //-------------------------------------------------------------------------
263 // Delete node
264 //-------------------------------------------------------------------------
265
266 fFacility.executeCommand(node, "delete");
267 assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
268 }
269
270}
This page took 0.047992 seconds and 5 git commands to generate.