Analysis: Add unit tests for the critical path module
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / KernelTest.java
CommitLineData
2fe6a9ea
PT
1/*******************************************************************************
2 * Copyright (c) 2013, 2015 Ericsson
3 *
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
8 *
9 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 * Marc-Andre Laperle
12 * Patrick Tasse - Extract base class from ImportAndReadKernelSmokeTest
13 *******************************************************************************/
14
15package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
16
17import static org.junit.Assert.fail;
18
19import java.util.List;
20
21import org.apache.log4j.ConsoleAppender;
22import org.apache.log4j.Logger;
23import org.apache.log4j.SimpleLayout;
24import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
25import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
26import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
27import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
28import org.eclipse.swtbot.swt.finder.results.BoolResult;
29import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
30import org.eclipse.tracecompass.tmf.ctf.core.tests.shared.CtfTmfTestTrace;
31import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
32import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
33import org.eclipse.ui.PlatformUI;
34import org.eclipse.ui.WorkbenchException;
35import org.junit.After;
36import org.junit.AfterClass;
37import org.junit.Before;
38import org.junit.BeforeClass;
39import org.junit.runner.RunWith;
40
41/**
42 * Base SWTBot test for LTTng Kernel UI.
43 *
44 * @author Matthew Khouzam
45 */
46@RunWith(SWTBotJunit4ClassRunner.class)
47public class KernelTest {
48
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";
52 private static final CtfTmfTestTrace CTT = CtfTmfTestTrace.SYNTHETIC_TRACE;
53
54 /** The workbench bot */
55 protected static SWTWorkbenchBot fBot;
56
57 /** The Log4j logger instance. */
58 private static final Logger fLogger = Logger.getRootLogger();
59
60 /**
61 * Before Class
62 */
63 @BeforeClass
64 public static void beforeClass() {
65 SWTBotUtils.failIfUIThread();
66
67 /* set up for swtbot */
68 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
5cd20891 69 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
2fe6a9ea
PT
70 fLogger.removeAllAppenders();
71 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
72 fBot = new SWTWorkbenchBot();
73
74 final List<SWTBotView> openViews = fBot.views();
75 for (SWTBotView view : openViews) {
76 if (view.getTitle().equals("Welcome")) {
77 view.close();
78 fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
79 }
80 }
81 /* Switch perspectives */
82 switchKernelPerspective();
83 /* Finish waiting for eclipse to load */
84 SWTBotUtils.waitForJobs();
85 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
86 }
87
88 /**
89 * After Class
90 */
91 @AfterClass
92 public static void afterClass() {
93 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
94 fLogger.removeAllAppenders();
95 }
96
97 private static void switchKernelPerspective() {
98 final Exception retE[] = new Exception[1];
99 if (!UIThreadRunnable.syncExec(new BoolResult() {
100 @Override
101 public Boolean run() {
102 try {
103 PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
104 PlatformUI.getWorkbench().getActiveWorkbenchWindow());
105 } catch (WorkbenchException e) {
106 retE[0] = e;
107 return false;
108 }
109 return true;
110 }
111 })) {
112 fail(retE[0].getMessage());
113 }
114
115 }
116
117 /**
118 * Before Test
119 */
120 @Before
121 public void before() {
122 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE);
123 SWTBotUtils.activateEditor(fBot, CTT.getTrace().getName());
124 }
125
126 /**
127 * After Test
128 */
129 @After
130 public void after() {
131 fBot.closeAllEditors();
132 }
133}
This page took 0.034623 seconds and 5 git commands to generate.