pcap: Rename packages to org.eclipse.tracecompass.*
[deliverable/tracecompass.git] / org.eclipse.tracecompass.lttng2.control.ui.tests / src / org / eclipse / linuxtools / lttng2 / control / ui / tests / model / component / TraceControlTreeModelNoProvidersTest.java
1 /**********************************************************************
2 * Copyright (c) 2012, 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 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
13
14 package org.eclipse.linuxtools.lttng2.control.ui.tests.model.component;
15
16 import static org.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertNotSame;
20 import static org.junit.Assert.assertTrue;
21
22 import java.io.File;
23 import java.net.URL;
24
25 import org.eclipse.core.runtime.FileLocator;
26 import org.eclipse.core.runtime.Path;
27 import org.eclipse.linuxtools.internal.lttng2.control.stubs.service.TestRemoteSystemProxy;
28 import org.eclipse.linuxtools.internal.lttng2.control.core.model.TargetNodeState;
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.TraceProviderGroup;
32 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.TraceSessionGroup;
33 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.model.impl.UstProviderComponent;
34 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.ILttngControlService;
35 import org.eclipse.linuxtools.internal.lttng2.control.ui.views.service.LTTngControlService;
36 import org.eclipse.rse.core.RSECorePlugin;
37 import org.eclipse.rse.core.model.IHost;
38 import org.eclipse.rse.core.model.ISystemProfile;
39 import org.eclipse.rse.core.model.ISystemRegistry;
40 import org.eclipse.swt.graphics.Image;
41 import org.junit.After;
42 import org.junit.Before;
43 import org.junit.Test;
44 import org.osgi.framework.FrameworkUtil;
45
46 /**
47 * The class <code>TraceControlTreeModelNoProvidersTest</code> verifies that the
48 * Tracer Control can handle the case where no kernel provider and only UST
49 * provider are available.
50 */
51 public class TraceControlTreeModelNoProvidersTest {
52
53 // ------------------------------------------------------------------------
54 // Constants
55 // ------------------------------------------------------------------------
56
57 private static final String TEST_STREAM = "ListInfoTest.cfg";
58 private static final String SCEN_LIST_INFO_TEST = "ListInfoTestNoKernel";
59 private static final String TARGET_NODE_NAME = "myNode";
60
61 // ------------------------------------------------------------------------
62 // Test data
63 // ------------------------------------------------------------------------
64
65 private TestRemoteSystemProxy fProxy;
66 private String fTestFile;
67
68 // ------------------------------------------------------------------------
69 // Housekeeping
70 // ------------------------------------------------------------------------
71
72 /**
73 * Perform pre-test initialization.
74 *
75 * @throws Exception
76 * if the initialization fails for some reason
77 */
78 @Before
79 public void setUp() throws Exception {
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 @After
90 public void tearDown() {
91 TraceControlTestFacility.getInstance().waitForJobs();
92 }
93
94 /**
95 * Run the TraceControlComponent.
96 *
97 * @throws Exception
98 * This will fail the test
99 */
100 @Test
101 public void testTraceControlComponents() throws Exception {
102
103 fProxy.setTestFile(fTestFile);
104 fProxy.setScenario(SCEN_LIST_INFO_TEST);
105
106 ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
107
108 ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
109 ISystemProfile profile = registry.createSystemProfile("myProfile", true);
110 IHost host = registry.createLocalHost(profile, "myProfile", "user");
111
112 TargetNodeComponent node = new TargetNodeComponent(TARGET_NODE_NAME, root, host, fProxy);
113
114 root.addChild(node);
115 node.connect();
116
117 TraceControlTestFacility.getInstance().waitForJobs();
118
119 // ------------------------------------------------------------------------
120 // Verify Parameters of TargetNodeComponent
121 // ------------------------------------------------------------------------
122 assertEquals("LOCALHOST", node.getHostName()); // assigned in createLocalHost() above
123 assertEquals("LOCALHOST", node.getToolTip()); // assigned in createLocalHost() above
124 Image connectedImage = node.getImage();
125 assertNotNull(connectedImage);
126 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
127 assertNotNull(node.getControlService());
128 ILttngControlService service = node.getControlService();
129 assertTrue(service instanceof LTTngControlService);
130 node.setControlService(service);
131 assertTrue(node.getControlService() instanceof LTTngControlService);
132
133 assertTrue(node.isPassiveCommunicationsListener());
134
135 // ------------------------------------------------------------------------
136 // Verify Children of TargetNodeComponent
137 // ------------------------------------------------------------------------
138 ITraceControlComponent[] groups = node.getChildren();
139 assertNotNull(groups);
140 assertEquals(2, groups.length);
141
142 assertTrue(groups[0] instanceof TraceProviderGroup);
143 assertTrue(groups[1] instanceof TraceSessionGroup);
144
145 // Check for kernel provider
146 TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
147 assertFalse(providerGroup.hasKernelProvider());
148
149 assertEquals("Provider", providerGroup.getName());
150 assertEquals("Sessions", groups[1].getName());
151
152 // ------------------------------------------------------------------------
153 // Verify TraceProviderGroup
154 // ------------------------------------------------------------------------
155 ITraceControlComponent[] providers = groups[0].getChildren();
156
157 assertNotNull(providers);
158 assertEquals(1, providers.length);
159 assertTrue(providers[0] instanceof UstProviderComponent);
160
161 // disconnect
162 node.disconnect();
163 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
164 assertNotNull(node.getImage());
165 assertNotSame(connectedImage, node.getImage());
166
167 node.getParent().removeChild(node);
168 }
169 }
This page took 0.033459 seconds and 5 git commands to generate.