/**********************************************************************
- * Copyright (c) 2012 Ericsson
- *
+ * Copyright (c) 2012, 2013 Ericsson
+ *
* All rights reserved. This program and the accompanying materials are
* made available under the terms of the Eclipse Public License v1.0 which
* accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
+ *
+ * Contributors:
* Bernd Hufmann - Initial API and implementation
+ * Alexandre Montplaisir - Port to JUnit4
**********************************************************************/
+
package org.eclipse.linuxtools.lttng2.ui.tests.control.model.component;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
import java.io.File;
import java.net.URL;
-import junit.framework.Test;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.internal.lttng2.core.control.model.TargetNodeState;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TargetNodeComponent;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceChannelComponent;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceEventComponent;
+import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceProviderGroup;
import org.eclipse.linuxtools.internal.lttng2.ui.views.control.model.impl.TraceSessionComponent;
import org.eclipse.rse.core.RSECorePlugin;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.core.model.ISystemRegistry;
import org.junit.After;
import org.junit.Before;
+import org.junit.Test;
import org.osgi.framework.FrameworkUtil;
/**
- * The class <code>TraceControlKernelProviderTests</code> contains UST provider handling
- * test cases.
+ * The class <code>TraceControlKernelProviderTests</code> contains UST provider
+ * handling test cases.
*/
-@SuppressWarnings("nls")
-public class TraceControlKernelProviderTests extends TestCase {
+public class TraceControlKernelProviderTests {
// ------------------------------------------------------------------------
// Constants
// ------------------------------------------------------------------------
+
private static final String TEST_STREAM = "CreateTreeTest.cfg";
private static final String SCEN_SCENARIO1_TEST = "Scenario1";
// ------------------------------------------------------------------------
// Test data
// ------------------------------------------------------------------------
+
private TraceControlTestFacility fFacility;
private TestRemoteSystemProxy fProxy;
- private String fTestFile;
-
- // ------------------------------------------------------------------------
- // Static methods
- // ------------------------------------------------------------------------
-
- /**
- * Returns test setup used when executing test case stand-alone.
- * @return Test setup class
- */
- public static Test suite() {
- return new ModelImplTestSetup(new TestSuite(TraceControlKernelProviderTests.class));
- }
+ private String fTestFile;
// ------------------------------------------------------------------------
// Housekeeping
*
* @throws Exception
* if the initialization fails for some reason
- *
*/
- @Override
@Before
public void setUp() throws Exception {
fFacility = TraceControlTestFacility.getInstance();
+ fFacility.init();
fProxy = new TestRemoteSystemProxy();
URL location = FileLocator.find(FrameworkUtil.getBundle(this.getClass()), new Path(TraceControlTestFacility.DIRECTORY + File.separator + TEST_STREAM), null);
File testfile = new File(FileLocator.toFileURL(location).toURI());
/**
* Perform post-test clean-up.
- *
- * @throws Exception
- * if the clean-up fails for some reason
- *
*/
- @Override
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
fFacility.waitForJobs();
+ fFacility.dispose();
}
-
+
/**
* Run the TraceControlComponent.
+ *
+ * @throws Exception
+ * Would fail the test
*/
+ @Test
public void testKernelProviderTree() throws Exception {
-
-
+
fProxy.setTestFile(fTestFile);
fProxy.setScenario(TraceControlTestFacility.SCEN_INIT_TEST);
-
- ITraceControlComponent root = TraceControlTestFacility.getInstance().getControlView().getTraceControlRoot();
+
+ ITraceControlComponent root = fFacility.getControlView().getTraceControlRoot();
ISystemRegistry registry = RSECorePlugin.getTheSystemRegistry();
ISystemProfile profile = registry.createSystemProfile("myProfile", true);
IHost host = registry.createLocalHost(profile, "myProfile", "user");
-
+
TargetNodeComponent node = new TargetNodeComponent("myNode", root, host, fProxy);
root.addChild(node);
// Verify that node is connected
assertEquals(TargetNodeState.CONNECTED, node.getTargetNodeState());
- // Get provider groups
+ // Get provider and session group
ITraceControlComponent[] groups = node.getChildren();
assertNotNull(groups);
assertEquals(2, groups.length);
+ // Check for kernel provider
+ TraceProviderGroup providerGroup = (TraceProviderGroup) groups[0];
+ assertTrue(providerGroup.hasKernelProvider());
+
// Get kernel provider
- ITraceControlComponent[] providers = groups[0].getChildren();
+ ITraceControlComponent[] providers = providerGroup.getChildren();
KernelProviderComponent kernelProvider = (KernelProviderComponent) providers[0];
- // Get kernel provider events and select 2 events
+ // Get kernel provider events and select 2 events
ITraceControlComponent[] events = kernelProvider.getChildren();
assertNotNull(events);
assertEquals(3, events.length);
// Initialize session handling scenario
fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
-
+
// ------------------------------------------------------------------------
// Create session
// ------------------------------------------------------------------------
TraceSessionComponent session = fFacility.createSession(groups[1]);
-
+
// Verify that session was created
assertNotNull(session);
assertEquals("mysession", session.getName());
ITraceControlComponent[] components = { baseEventInfo0, baseEventInfo1 };
fFacility.executeCommand(components, "assign.event");
-
+
// Verify that kernel domain was created
ITraceControlComponent[] domains = session.getChildren();
assertNotNull(domains);
assertEquals(1, domains.length);
assertEquals("Kernel", domains[0].getName());
-
+
// Verify that channel0 was created with default values
ITraceControlComponent[] channels = domains[0].getChildren();
assertNotNull(channels);
assertEquals(1, channels.length);
assertTrue(channels[0] instanceof TraceChannelComponent);
- TraceChannelComponent channel = (TraceChannelComponent) channels[0];
+ TraceChannelComponent channel = (TraceChannelComponent) channels[0];
assertEquals("channel0", channel.getName());
assertEquals(4, channel.getNumberOfSubBuffers());
assertEquals("splice()", channel.getOutputType());
assertEquals(TraceEnablement.ENABLED, event1.getState());
// ------------------------------------------------------------------------
- // Disable event components
+ // Disable event components
// ------------------------------------------------------------------------
ITraceControlComponent[] selection = { event, event1 };
fFacility.executeCommand(selection, "disableEvent");
-
+
assertEquals(TraceEnablement.DISABLED, event.getState());
assertEquals(TraceEnablement.DISABLED, event1.getState());
// ------------------------------------------------------------------------
- // Enable event component
+ // Enable event component
// ------------------------------------------------------------------------
fFacility.executeCommand(event1, "enableEvent");
-
+
// Verify event state
assertEquals(TraceEnablement.ENABLED, event1.getState());
-
+
// ------------------------------------------------------------------------
- // Destroy session
+ // Destroy session
// ------------------------------------------------------------------------
// Initialize session handling scenario
fProxy.setScenario(TraceControlTestFacility.SCEN_SCENARIO_SESSION_HANDLING);
-
+
fFacility.destroySession(session);
-
+
// Verify that no more session components exist
assertEquals(0, groups[1].getChildren().length);
//-------------------------------------------------------------------------
fFacility.executeCommand(node, "disconnect");
assertEquals(TargetNodeState.DISCONNECTED, node.getTargetNodeState());
-
+
//-------------------------------------------------------------------------
// Delete node
//-------------------------------------------------------------------------