Remove all "AllTests" suites
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / kernel / ui / swtbot / tests / KernelTestBase.java
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
15 package org.eclipse.tracecompass.lttng2.kernel.ui.swtbot.tests;
16
17 import static org.junit.Assert.fail;
18
19 import java.util.List;
20
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;
40
41 /**
42 * Base SWTBot test for LTTng Kernel UI.
43 *
44 * @author Matthew Khouzam
45 */
46 @RunWith(SWTBotJunit4ClassRunner.class)
47 public abstract class KernelTestBase {
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
53 /** The workbench bot */
54 protected static SWTWorkbenchBot fBot;
55
56 /** The Log4j logger instance. */
57 private static final Logger fLogger = Logger.getRootLogger();
58
59 /**
60 * Before Class
61 */
62 @BeforeClass
63 public static void beforeClass() {
64 SWTBotUtils.initialize();
65
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();
72
73 final List<SWTBotView> openViews = fBot.views();
74 for (SWTBotView view : openViews) {
75 if (view.getTitle().equals("Welcome")) {
76 view.close();
77 fBot.waitUntil(ConditionHelpers.ViewIsClosed(view));
78 }
79 }
80 /* Switch perspectives */
81 switchKernelPerspective();
82 /* Create the trace project */
83 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
84 /* Finish waiting for eclipse to load */
85 SWTBotUtils.waitForJobs();
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, LttngKernelTraceGenerator.getPath(), TRACE_TYPE);
123 SWTBotUtils.activateEditor(fBot, LttngKernelTraceGenerator.getName());
124 }
125
126 /**
127 * After Test
128 */
129 @After
130 public void after() {
131 fBot.closeAllEditors();
132 }
133 }
This page took 0.046343 seconds and 5 git commands to generate.