tmf: lttngControl: basic mi test suite
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / 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 **********************************************************************/
8e8c0226 12package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component;
f3b33d40
BH
13
14import static org.junit.Assert.assertEquals;
15import static org.junit.Assert.assertNotNull;
16import static org.junit.Assert.assertTrue;
17
8e8c0226
AM
18import java.io.File;
19import java.net.URL;
20
f3b33d40
BH
21import org.eclipse.core.runtime.FileLocator;
22import org.eclipse.core.runtime.Path;
8e8c0226
AM
23import org.eclipse.linuxtools.internal.lttng2.control.core.model.TargetNodeState;
24import org.eclipse.linuxtools.internal.lttng2.control.core.model.TraceSessionState;
25import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
26import org.eclipse.linuxtools.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
27import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
28import org.eclipse.linuxtools.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
29import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.ITraceControlComponent;
30import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
31import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
f3b33d40
BH
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
4e0b52e0 46@SuppressWarnings("javadoc")
f3b33d40
BH
47public class TraceControlCreateSessionTests {
48
49 // ------------------------------------------------------------------------
50 // Constants
51 // ------------------------------------------------------------------------
52 private static final String TEST_STREAM = "CreateSessionTest.cfg";
f3b33d40
BH
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";
a30e79fe 56 private static final String SCEN_SCENARIO_NETWORK2_TEST = "CreateSessionNetwork2";
f3b33d40
BH
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();
a30e79fe 79 fFacility.init();
f3b33d40
BH
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
f3b33d40 138 // ------------------------------------------------------------------------
a30e79fe 139 // Create session (--U file://...) and destroy
f3b33d40
BH
140 // ------------------------------------------------------------------------
141 // Initialize session handling scenario
a30e79fe 142 fProxy.setScenario(SCEN_SCENARIO_FILE_PROTO_TEST);
f3b33d40 143
a30e79fe
BH
144 sessionDialogStub.setNetworkUrl("file:///tmp");
145 sessionDialogStub.setStreamedTrace(true);
146 TraceSessionComponent session = fFacility.createSession(groups[1]);
f3b33d40
BH
147
148 // Verify that session was created
149 assertNotNull(session);
150 assertEquals("mysession", session.getName());
a30e79fe
BH
151 assertEquals("file:///tmp", session.getSessionPath());
152 assertTrue(!session.isStreamedTrace());
f3b33d40 153 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
154 sessionDialogStub.setNetworkUrl(null);
155 sessionDialogStub.setStreamedTrace(false);
f3b33d40
BH
156
157 fFacility.destroySession(session);
158
159 // Verify that no more session components exist
160 assertEquals(0, groups[1].getChildren().length);
161
162 // ------------------------------------------------------------------------
a30e79fe 163 // Create session (--U file://,,, and destroy
f3b33d40
BH
164 // ------------------------------------------------------------------------
165 // Initialize session handling scenario
a30e79fe 166 fProxy.setScenario(SCEN_SCENARIO_CONTROL_DATA_TEST);
f3b33d40 167
a30e79fe
BH
168 sessionDialogStub.setControlUrl("tcp://172.0.0.1");
169 sessionDialogStub.setDataUrl("tcp://172.0.0.1:5343");
f3b33d40 170 sessionDialogStub.setStreamedTrace(true);
a30e79fe 171
f3b33d40
BH
172 session = fFacility.createSession(groups[1]);
173
174 // Verify that session was created
175 assertNotNull(session);
176 assertEquals("mysession", session.getName());
a30e79fe 177 assertEquals("tcp://172.0.0.1:5342 [data: 5343]", session.getSessionPath());
f3b33d40
BH
178 assertTrue(session.isStreamedTrace());
179 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe
BH
180 sessionDialogStub.setControlUrl(null);
181 sessionDialogStub.setDataUrl(null);
f3b33d40
BH
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 // ------------------------------------------------------------------------
a30e79fe 190 // Create session (--U file://... and destroy
f3b33d40
BH
191 // ------------------------------------------------------------------------
192 // Initialize session handling scenario
a30e79fe 193 fProxy.setScenario(SCEN_SCENARIO_NETWORK_TEST);
f3b33d40 194
a30e79fe 195 sessionDialogStub.setNetworkUrl("net://172.0.0.1:1234:2345");
f3b33d40
BH
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());
a30e79fe 203 assertEquals("net://172.0.0.1:1234 [data: 2345]", session.getSessionPath());
f3b33d40
BH
204 assertTrue(session.isStreamedTrace());
205 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
a30e79fe 206 sessionDialogStub.setNetworkUrl(null);
f3b33d40
BH
207
208 fFacility.destroySession(session);
209
210 // Verify that no more session components exist
211 assertEquals(0, groups[1].getChildren().length);
212
213 // ------------------------------------------------------------------------
a30e79fe 214 // Create session (--U net6://[...] and destroy
f3b33d40
BH
215 // ------------------------------------------------------------------------
216 // Initialize session handling scenario
a30e79fe 217 fProxy.setScenario(SCEN_SCENARIO_NETWORK2_TEST);
f3b33d40 218
a30e79fe 219 sessionDialogStub.setNetworkUrl("net6://[ffff::eeee:dddd:cccc:0]");
f3b33d40
BH
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());
a30e79fe 227 assertEquals("net://[ffff::eeee:dddd:cccc:0]:5342/mysession-20130221-144451 [data: 5343]", session.getSessionPath());
f3b33d40
BH
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
a30e79fe 237
f3b33d40
BH
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
a30e79fe 252}
This page took 0.056046 seconds and 5 git commands to generate.