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
.control
.ui
.tests
.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
.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
;
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 public class TraceControlTreeModelNoProvidersTest
{
53 // ------------------------------------------------------------------------
55 // ------------------------------------------------------------------------
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";
61 // ------------------------------------------------------------------------
63 // ------------------------------------------------------------------------
65 private TestRemoteSystemProxy fProxy
;
66 private String fTestFile
;
68 // ------------------------------------------------------------------------
70 // ------------------------------------------------------------------------
73 * Perform pre-test initialization.
76 * if the initialization fails for some reason
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();
87 * Perform post-test clean-up.
90 public void tearDown() {
91 TraceControlTestFacility
.getInstance().waitForJobs();
95 * Run the TraceControlComponent.
98 * This will fail the test
101 public void testTraceControlComponents() throws Exception
{
103 fProxy
.setTestFile(fTestFile
);
104 fProxy
.setScenario(SCEN_LIST_INFO_TEST
);
106 ITraceControlComponent root
= TraceControlTestFacility
.getInstance().getControlView().getTraceControlRoot();
108 ISystemRegistry registry
= RSECorePlugin
.getTheSystemRegistry();
109 ISystemProfile profile
= registry
.createSystemProfile("myProfile", true);
110 IHost host
= registry
.createLocalHost(profile
, "myProfile", "user");
112 TargetNodeComponent node
= new TargetNodeComponent(TARGET_NODE_NAME
, root
, host
, fProxy
);
117 TraceControlTestFacility
.getInstance().waitForJobs();
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
);
133 assertTrue(node
.isPassiveCommunicationsListener());
135 // ------------------------------------------------------------------------
136 // Verify Children of TargetNodeComponent
137 // ------------------------------------------------------------------------
138 ITraceControlComponent
[] groups
= node
.getChildren();
139 assertNotNull(groups
);
140 assertEquals(2, groups
.length
);
142 assertTrue(groups
[0] instanceof TraceProviderGroup
);
143 assertTrue(groups
[1] instanceof TraceSessionGroup
);
145 // Check for kernel provider
146 TraceProviderGroup providerGroup
= (TraceProviderGroup
) groups
[0];
147 assertFalse(providerGroup
.hasKernelProvider());
149 assertEquals("Provider", providerGroup
.getName());
150 assertEquals("Sessions", groups
[1].getName());
152 // ------------------------------------------------------------------------
153 // Verify TraceProviderGroup
154 // ------------------------------------------------------------------------
155 ITraceControlComponent
[] providers
= groups
[0].getChildren();
157 assertNotNull(providers
);
158 assertEquals(1, providers
.length
);
159 assertTrue(providers
[0] instanceof UstProviderComponent
);
163 assertEquals(TargetNodeState
.DISCONNECTED
, node
.getTargetNodeState());
164 assertNotNull(node
.getImage());
165 assertNotSame(connectedImage
, node
.getImage());
167 node
.getParent().removeChild(node
);