1 /**********************************************************************
2 * Copyright (c) 2012, 2013 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Alexandre Montplaisir - Port to JUnit4
12 **********************************************************************/
14 package org
.eclipse
.linuxtools
.lttng2
.ui
.tests
.control
.model
.component
;
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
;
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
;
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.
51 @SuppressWarnings("nls")
52 public class TraceControlTreeModelNoProvidersTest
{
54 // ------------------------------------------------------------------------
56 // ------------------------------------------------------------------------
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";
62 // ------------------------------------------------------------------------
64 // ------------------------------------------------------------------------
66 private TestRemoteSystemProxy fProxy
;
67 private String fTestFile
;
69 // ------------------------------------------------------------------------
71 // ------------------------------------------------------------------------
74 * Perform pre-test initialization.
77 * if the initialization fails for some reason
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();
88 * Perform post-test clean-up.
91 public void tearDown() {
92 TraceControlTestFacility
.getInstance().waitForJobs();
96 * Run the TraceControlComponent.
99 * This will fail the test
102 public void testTraceControlComponents() throws Exception
{
104 fProxy
.setTestFile(fTestFile
);
105 fProxy
.setScenario(SCEN_LIST_INFO_TEST
);
107 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
109 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
110 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
111 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
113 TargetNodeComponent node
= new TargetNodeComponent(TARGET_NODE_NAME
, root
, host
, fProxy
);
118 TraceControlTestFacility
.getInstance().waitForJobs();
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
);
134 assertTrue(node
.isPassiveCommunicationsListener());
136 // ------------------------------------------------------------------------
137 // Verify Children of TargetNodeComponent
138 // ------------------------------------------------------------------------
139 ITraceControlComponent
[] groups
= node
.getChildren();
140 assertNotNull(groups
);
141 assertEquals(2, groups
.length
);
143 assertTrue(groups
[0] instanceof TraceProviderGroup
);
144 assertTrue(groups
[1] instanceof TraceSessionGroup
);
146 // Check for kernel provider
147 TraceProviderGroup providerGroup
= (TraceProviderGroup
) groups
[0];
148 assertFalse(providerGroup
.hasKernelProvider());
150 assertEquals("Provider", providerGroup
.getName());
151 assertEquals("Sessions", groups
[1].getName());
153 // ------------------------------------------------------------------------
154 // Verify TraceProviderGroup
155 // ------------------------------------------------------------------------
156 ITraceControlComponent
[] providers
= groups
[0].getChildren();
158 assertNotNull(providers
);
159 assertEquals(1, providers
.length
);
160 assertTrue(providers
[0] instanceof UstProviderComponent
);
164 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
165 assertNotNull(node
.getImage());
166 assertNotSame(connectedImage
, node
.getImage());
168 node
.getParent().removeChild(node
);