blob: 6ed759be2b26a9a9af9abcb8f03d2033606ee96c [file] [log] [blame]
/*******************************************************************************
* Copyright (c) 2013, 2015 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:
* Matthew Khouzam - Initial API and implementation
* Marc-Andre Laperle
* Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
*******************************************************************************/
package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
import static org.junit.Assert.fail;
import java.util.List;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.results.BoolResult;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.WorkbenchException;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.runner.RunWith;
/**
* Base SWTBot test for LTTng Kernel UI.
*
* @author Matthew Khouzam
*/
@RunWith(SWTBotJunit4ClassRunner.class)
public class KernelTest {
private static final String TRACE_TYPE = "org.eclipse.linuxtools.lttng2.kernel.tracetype";
private static final String KERNEL_PERSPECTIVE_ID = "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
private static final String TRACE_PROJECT_NAME = "test";
private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE;
/** The workbench bot */
protected static SWTWorkbenchBot fBot;
/** The Log4j logger instance. */
// private static final Logger fLogger = Logger.getRootLogger();
/**
* Before Class
*/
@BeforeClass
public static void beforeClass() {
SWTBotUtils.failIfUIThread();
/* set up for swtbot */
SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
// SWTBotPreferences.PLAYBACK_DELAY = 200;
// fLogger.removeAllAppenders();
// fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
fBot = new SWTWorkbenchBot();
final List<SWTBotView> openViews = fBot.views();
for (SWTBotView view : openViews) {
if (view.getTitle().equals("Welcome")) {
view.close();
fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
}
}
/* Switch perspectives */
switchKernelPerspective();
/* Finish waiting for eclipse to load */
SWTBotUtils.waitForJobs();
SWTBotUtils.createProject(TRACE_PROJECT_NAME);
}
/**
* After Class
*/
@AfterClass
public static void afterClass() {
SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
// fLogger.removeAllAppenders();
}
private static void switchKernelPerspective() {
final Exception retE[] = new Exception[1];
if (!UIThreadRunnable.syncExec(new BoolResult() {
@Override
public Boolean run() {
try {
PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
PlatformUI.getWorkbench().getActiveWorkbenchWindow());
} catch (WorkbenchException e) {
retE[0] = e;
return false;
}
return true;
}
})) {
fail(retE[0].getMessage());
}
}
/**
* Before Test
*/
@Before
public void before() {
SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE);
SWTBotUtils.activateEditor(fBot, CTT.getTrace().getName());
}
/**
* After Test
*/
@After
public void after() {
fBot.closeAllEditors();
}
}