Bug 448058: Replace RSE by org.eclipse.remote
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / tests / model / component / TraceControlSnapshotSessionTests.java
CommitLineData
589d0d33 1/**********************************************************************
60ae41e1 2 * Copyright (c) 2013, 2014 Ericsson
589d0d33
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
b732adaa 11 * Markus Schorn - Bug 448058: Use org.eclipse.remote in favor of RSE
589d0d33
BH
12 **********************************************************************/
13
9bc60be7 14package org.eclipse.tracecompass.lttng2.control.ui.tests.model.component;
589d0d33
BH
15
16import static org.junit.Assert.assertEquals;
17import static org.junit.Assert.assertNotNull;
18import static org.junit.Assert.assertTrue;
19
20import java.io.File;
21import java.net.URL;
22import java.util.HashMap;
23import java.util.Map;
24
25import org.eclipse.core.runtime.FileLocator;
26import org.eclipse.core.runtime.Path;
b732adaa
MS
27import org.eclipse.remote.core.IRemoteConnection;
28import org.eclipse.remote.core.IRemoteConnectionManager;
29import org.eclipse.remote.core.RemoteServices;
9bc60be7
AM
30import org.eclipse.tracecompass.internal.lttng2.control.core.model.TargetNodeState;
31import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
32import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.CreateSessionDialogStub;
33import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.DestroyConfirmDialogStub;
34import org.eclipse.tracecompass.internal.lttng2.control.stubs.dialogs.GetEventInfoDialogStub;
35import org.eclipse.tracecompass.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
36import org.eclipse.tracecompass.internal.lttng2.control.ui.views.dialogs.TraceControlDialogFactory;
37import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
38import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TargetNodeComponent;
39import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceSessionComponent;
40import org.eclipse.tracecompass.internal.lttng2.control.ui.views.property.TraceSessionPropertySource;
589d0d33
BH
41import org.eclipse.ui.views.properties.IPropertyDescriptor;
42import org.eclipse.ui.views.properties.IPropertySource;
43import org.junit.After;
44import org.junit.Before;
45import org.junit.Test;
46import org.osgi.framework.FrameworkUtil;
47
48/**
49 * The class <code>TraceControlSnapshotSessionTests</code> contains Snapshot
50 * session test cases for support of LTTng Tools 2.3.
51 */
52public class TraceControlSnapshotSessionTests {
53
54 // ------------------------------------------------------------------------
55 // Constants
56 // ------------------------------------------------------------------------
57
58 private static final String TEST_STREAM = "CreateSessionTest2.cfg";
59 private static final String SCEN_CREATE_SESSION = "ScenCreateSession";
60
61 // ------------------------------------------------------------------------
62 // Test data
63 // ------------------------------------------------------------------------
64
65 private TraceControlTestFacility fFacility;
66 private TestRemoteSystemProxy fProxy;
67 private String fTestFile;
68
69 // ------------------------------------------------------------------------
70 // Housekeeping
71 // ------------------------------------------------------------------------
72
73 /**
74 * Perform pre-test initialization.
75 *
76 * @throws Exception
77 * if the initialization fails for some reason
78 */
79 @Before
80 public void setUp() throws Exception {
81 fFacility = TraceControlTestFacility.getInstance();
82 fFacility.init();
83 fProxy = new TestRemoteSystemProxy();
84 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
85 File testfile = new File(FileLocator.toFileURL(location).toURI());
86 fTestFile = testfile.getAbsolutePath();
87 }
88
89 /**
90 * Perform post-test clean-up.
91 */
92 @After
93 public void tearDown() {
94 fFacility.waitForJobs();
95 fFacility.dispose();
96 }
97
98 /**
99 * Run the TraceControlComponent.
100 *
101 * @throws Exception
102 * This will fail the test
103 */
104 @Test
105 public void testTraceSessionTree() throws Exception {
106
107 fProxy.setTestFile(fTestFile);
108 fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
109
110 ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
111
b732adaa
MS
112 IRemoteConnectionManager cm = RemoteServices.getLocalServices().getConnectionManager();
113 IRemoteConnection host = cm.getConnection(IRemoteConnectionManager.LOCAL_CONNECTION_NAME);
589d0d33
BH
114
115 TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
116
117 root.addChild(node);
118 fFacility.waitForJobs();
119
120 fFacility.executeCommand(node, "connect");
121 int i = 0;
122 while ((i < 10) && (node.getTargetNodeState() != TargetNodeState.CONNECTED)) {
123 i++;
124 fFacility.delay(TraceControlTestFacility.GUI_REFESH_DELAY);
125 }
126
127 // Get provider groups
128 ITraceControlComponent[] groups = node.getChildren();
129 assertNotNull(groups);
130 assertEquals(2, groups.length);
131
132 // Initialize dialog implementations for command execution
133 // --- snapshot session ---
134 CreateSessionDialogStub sessionDialog = new CreateSessionDialogStub();
135 sessionDialog.setSnapshot(true);
136
137 TraceControlDialogFactory.getInstance().setCreateSessionDialog(sessionDialog);
138 TraceControlDialogFactory.getInstance().setGetEventInfoDialog(new GetEventInfoDialogStub());
139 TraceControlDialogFactory.getInstance().setConfirmDialog(new DestroyConfirmDialogStub());
140
141 // Initialize scenario
142 fProxy.setScenario(SCEN_CREATE_SESSION);
143
144 // ------------------------------------------------------------------------
145 // Create session
146 // ------------------------------------------------------------------------
147 TraceSessionComponent session = fFacility.createSession(groups[1]);
148
149 // Verify that session was created
150 assertNotNull(session);
151 assertEquals("mysession", session.getName());
152 assertTrue(session.isSnapshotSession());
153 assertNotNull(session.getSnapshotInfo());
154 assertEquals("snapshot-1", session.getSnapshotInfo().getName());
155 assertEquals("/home/user/lttng-traces/mysession-20130913-141651", session.getSnapshotInfo().getSnapshotPath());
156 assertEquals(1, session.getSnapshotInfo().getId());
157
158 // ------------------------------------------------------------------------
159 // Start session
160 // ------------------------------------------------------------------------
161 fFacility.startSession(session);
162 assertEquals(TraceSessionState.ACTIVE, session.getSessionState());
163
164 // verify properties
165 Object adapter = session.getAdapter(IPropertySource.class);
166 assertNotNull(adapter);
167 assertTrue(adapter instanceof TraceSessionPropertySource);
168
169 TraceSessionPropertySource sessionSource = (TraceSessionPropertySource)adapter;
170 IPropertyDescriptor[] descriptors = sessionSource.getPropertyDescriptors();
171 assertNotNull(descriptors);
172
e0838ca1 173 Map<String,String> map = new HashMap<>();
589d0d33
BH
174 map.put(TraceSessionPropertySource.TRACE_SESSION_NAME_PROPERTY_ID, "mysession");
175 map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_NAME_PROPERTY_ID, "snapshot-1");
176 map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_PATH_PROPERTY_ID, "/home/user/lttng-traces/mysession-20130913-141651");
177 map.put(TraceSessionPropertySource.TRACE_SNAPSHOT_ID_PROPERTY_ID, "1");
178 map.put(TraceSessionPropertySource.TRACE_SESSION_STATE_PROPERTY_ID, TraceSessionState.ACTIVE.name());
179
180 for (int j = 0; j < descriptors.length; j++) {
181 String expected = map.get(descriptors[j].getId());
182 assertNotNull(expected);
183 assertEquals(expected, sessionSource.getPropertyValue(descriptors[j].getId()).toString());
184 }
185
186 // ------------------------------------------------------------------------
187 // Record snapshot
188 // ------------------------------------------------------------------------
189 fFacility.executeCommand(session, "snapshot");
190
191 // ------------------------------------------------------------------------
192 // Stop snapshot
193 // ------------------------------------------------------------------------
194 fFacility.stopSession(session);
195 assertEquals(TraceSessionState.INACTIVE, session.getSessionState());
196
197 // ------------------------------------------------------------------------
198 // Destroy session
199 // ------------------------------------------------------------------------
200 fFacility.destroySession(session);
201
202 // Verify that no more session components exist
203 assertEquals(0, groups[1].getChildren().length);
204
205 //-------------------------------------------------------------------------
206 // Disconnect node
207 //-------------------------------------------------------------------------
208 fFacility.executeCommand(node, "disconnect");
209 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
210
211 //-------------------------------------------------------------------------
212 // Delete node
213 //-------------------------------------------------------------------------
214
215 fFacility.executeCommand(node, "delete");
216
217 assertEquals(0,fFacility.getControlView().getTraceControlRoot().getChildren().length);
218 }
219}
This page took 0.049193 seconds and 5 git commands to generate.