lttng: Port unit tests to JUnit4
[deliverable/tracecompass.git] / org.eclipse.linuxtools.lttng2.ui.tests / src / org / eclipse / linuxtools / lttng2 / ui / tests / control / 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.ui.tests.control.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.core.control.model.TargetNodeState;
28 import org.eclipse.linuxtools.internal.lttng2.stubs.service.TestRemoteSystemProxy;
29 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.ITraceControlComponent;
30 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
31 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup;
32 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionGroup;
33 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.UstProviderComponent;
34 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.service.ILttngControlService;
35 import org.eclipse.linuxtools.internal.lttng2.ui.views.control.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 @SuppressWarnings("nls")
52 public class TraceControlTreeModelNoProvidersTest {
53
54 // ------------------------------------------------------------------------
55 // Constants
56 // ------------------------------------------------------------------------
57
58 private static final String TEST_STREAM = "ListInfoTest.cfg";
59 private static final String SCEN_LIST_INFO_TEST = "ListInfoTestNoKernel";
60 private static final String TARGET_NODE_NAME = "myNode";
61
62 // ------------------------------------------------------------------------
63 // Test data
64 // ------------------------------------------------------------------------
65
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 fProxy = new TestRemoteSystemProxy();
82 URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
83 File testfile = new File(FileLocator.toFileURL(location).toURI());
84 fTestFile = testfile.getAbsolutePath();
85 }
86
87 /**
88 * Perform post-test clean-up.
89 */
90 @After
91 public void tearDown() {
92 TraceControlTestFacility.getInstance().waitForJobs();
93 }
94
95 /**
96 * Run the TraceControlComponent.
97 *
98 * @throws Exception
99 * This will fail the test
100 */
101 @Test
102 public void testTraceControlComponents() throws Exception {
103
104 fProxy.setTestFile(fTestFile);
105 fProxy.setScenario(SCEN_LIST_INFO_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(TARGET_NODE_NAME, root, host, fProxy);
114
115 root.addChild(node);
116 node.connect();
117
118 TraceControlTestFacility.getInstance().waitForJobs();
119
120 // ------------------------------------------------------------------------
121 // Verify Parameters of TargetNodeComponent
122 // ------------------------------------------------------------------------
123 assertEquals("LOCALHOST", node.getHostName()); // assigned in createLocalHost() above
124 assertEquals("LOCALHOST", node.getToolTip()); // assigned in createLocalHost() above
125 Image connectedImage = node.getImage();
126 assertNotNull(connectedImage);
127 assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
128 assertNotNull(node.getControlService());
129 ILttngControlService service = node.getControlService();
130 assertTrue(service instanceof LTTngControlService);
131 node.setControlService(service);
132 assertTrue(node.getControlService() instanceof LTTngControlService);
133
134 assertTrue(node.isPassiveCommunicationsListener());
135
136 // ------------------------------------------------------------------------
137 // Verify Children of TargetNodeComponent
138 // ------------------------------------------------------------------------
139 ITraceControlComponent[] groups = node.getChildren();
140 assertNotNull(groups);
141 assertEquals(2, groups.length);
142
143 assertTrue(groups[0] instanceof TraceProviderGroup);
144 assertTrue(groups[1] instanceof TraceSessionGroup);
145
146 // Check for kernel provider
147 TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
148 assertFalse(providerGroup.hasKernelProvider());
149
150 assertEquals("Provider", providerGroup.getName());
151 assertEquals("Sessions", groups[1].getName());
152
153 // ------------------------------------------------------------------------
154 // Verify TraceProviderGroup
155 // ------------------------------------------------------------------------
156 ITraceControlComponent[] providers = groups[0].getChildren();
157
158 assertNotNull(providers);
159 assertEquals(1, providers.length);
160 assertTrue(providers[0] instanceof UstProviderComponent);
161
162 // disconnect
163 node.disconnect();
164 assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
165 assertNotNull(node.getImage());
166 assertNotSame(connectedImage, node.getImage());
167
168 node.getParent().removeChild(node);
169 }
170 }
This page took 0.046056 seconds and 5 git commands to generate.