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