swtbot: Add Control Flow view tests
[deliverable/tracecompass.git] / 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 */
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 /* Finish waiting for eclipse to load */
83 SWTBotUtils.waitForJobs();
84 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
85 }
86
87 /**
88 * After Class
89 */
90 @AfterClass
91 public static void afterClass() {
92 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
93 fLogger.removeAllAppenders();
94 }
95
96 private static void switchKernelPerspective() {
97 final Exception retE[] = new Exception[1];
98 if (!UIThreadRunnable.syncExec(new BoolResult() {
99 @Override
100 public Boolean run() {
101 try {
102 PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID,
103 PlatformUI.getWorkbench().getActiveWorkbenchWindow());
104 } catch (WorkbenchException e) {
105 retE[0] = e;
106 return false;
107 }
108 return true;
109 }
110 })) {
111 fail(retE[0].getMessage());
112 }
113
114 }
115
116 /**
117 * Before Test
118 */
119 @Before
120 public void before() {
121 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, CTT.getPath(), TRACE_TYPE);
122 SWTBotUtils.activateEditor(fBot, CTT.getTrace().getName());
123 }
124
125 /**
126 * After Test
127 */
128 @After
129 public void after() {
130 fBot.closeAllEditors();
131 }
132}
This page took 0.028027 seconds and 5 git commands to generate.