1 /*******************************************************************************
2 * Copyright (c) 2013, 2015 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 * Matthew Khouzam - Initial API and implementation
12 * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
13 *******************************************************************************/
15 package org
.eclipse
.tracecompass
.lttng2
.kernel
.ui
.swtbot
.tests
;
17 import static org
.junit
.Assert
.fail
;
19 import java
.util
.List
;
21 import org
.apache
.log4j
.ConsoleAppender
;
22 import org
.apache
.log4j
.Logger
;
23 import org
.apache
.log4j
.SimpleLayout
;
24 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
25 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
26 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
27 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
28 import org
.eclipse
.swtbot
.swt
.finder
.results
.BoolResult
;
29 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
30 import org
.eclipse
.tracecompass
.ctf
.core
.tests
.shared
.LttngKernelTraceGenerator
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
33 import org
.eclipse
.ui
.PlatformUI
;
34 import org
.eclipse
.ui
.WorkbenchException
;
35 import org
.junit
.After
;
36 import org
.junit
.AfterClass
;
37 import org
.junit
.Before
;
38 import org
.junit
.BeforeClass
;
39 import org
.junit
.runner
.RunWith
;
42 * Base SWTBot test for LTTng Kernel UI.
44 * @author Matthew Khouzam
46 @RunWith(SWTBotJunit4ClassRunner
.class)
47 public class KernelTest
{
49 private static final String TRACE_TYPE
= "org.eclipse.linuxtools.lttng2.kernel.tracetype";
50 private static final String KERNEL_PERSPECTIVE_ID
= "org.eclipse.linuxtools.lttng2.kernel.ui.perspective";
51 private static final String TRACE_PROJECT_NAME
= "test";
53 /** The workbench bot */
54 protected static SWTWorkbenchBot fBot
;
56 /** The Log4j logger instance. */
57 private static final Logger fLogger
= Logger
.getRootLogger();
63 public static void beforeClass() {
64 SWTBotUtils
.failIfUIThread();
66 /* set up for swtbot */
67 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
68 SWTBotPreferences
.KEYBOARD_LAYOUT
= "EN_US";
69 fLogger
.removeAllAppenders();
70 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
71 fBot
= new SWTWorkbenchBot();
73 final List
<SWTBotView
> openViews
= fBot
.views();
74 for (SWTBotView view
: openViews
) {
75 if (view
.getTitle().equals("Welcome")) {
77 fBot
.waitUntil(ConditionHelpers
.ViewIsClosed(view
));
80 /* Switch perspectives */
81 switchKernelPerspective();
82 /* Finish waiting for eclipse to load */
83 SWTBotUtils
.waitForJobs();
90 public static void afterClass() {
91 fLogger
.removeAllAppenders();
94 private static void switchKernelPerspective() {
95 final Exception retE
[] = new Exception
[1];
96 if (!UIThreadRunnable
.syncExec(new BoolResult() {
98 public Boolean
run() {
100 PlatformUI
.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID
,
101 PlatformUI
.getWorkbench().getActiveWorkbenchWindow());
102 } catch (WorkbenchException e
) {
109 fail(retE
[0].getMessage());
118 public void before() {
119 SWTBotUtils
.createProject(TRACE_PROJECT_NAME
);
120 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, LttngKernelTraceGenerator
.getPath(), TRACE_TYPE
);
121 SWTBotUtils
.activateEditor(fBot
, LttngKernelTraceGenerator
.getName());
128 public void after() {
129 fBot
.closeAllEditors();
130 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);