Commit | Line | Data |
---|---|---|
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 | ||
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; | |
c4d57ac1 | 30 | import org.eclipse.tracecompass.ctf.core.tests.shared.LttngKernelTraceGenerator; |
2fe6a9ea PT |
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 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"; | |
2fe6a9ea PT |
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() { | |
5785ab49 | 64 | SWTBotUtils.initialize(); |
2fe6a9ea PT |
65 | |
66 | /* set up for swtbot */ | |
67 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
5cd20891 | 68 | SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; |
2fe6a9ea PT |
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(); | |
2fe6a9ea PT |
84 | } |
85 | ||
86 | /** | |
87 | * After Class | |
88 | */ | |
89 | @AfterClass | |
90 | public static void afterClass() { | |
2fe6a9ea PT |
91 | fLogger.removeAllAppenders(); |
92 | } | |
93 | ||
94 | private static void switchKernelPerspective() { | |
95 | final Exception retE[] = new Exception[1]; | |
96 | if (!UIThreadRunnable.syncExec(new BoolResult() { | |
97 | @Override | |
98 | public Boolean run() { | |
99 | try { | |
100 | PlatformUI.getWorkbench().showPerspective(KERNEL_PERSPECTIVE_ID, | |
101 | PlatformUI.getWorkbench().getActiveWorkbenchWindow()); | |
102 | } catch (WorkbenchException e) { | |
103 | retE[0] = e; | |
104 | return false; | |
105 | } | |
106 | return true; | |
107 | } | |
108 | })) { | |
109 | fail(retE[0].getMessage()); | |
110 | } | |
111 | ||
112 | } | |
113 | ||
114 | /** | |
115 | * Before Test | |
116 | */ | |
117 | @Before | |
118 | public void before() { | |
c4d57ac1 AM |
119 | SWTBotUtils.createProject(TRACE_PROJECT_NAME); |
120 | SWTBotUtils.openTrace(TRACE_PROJECT_NAME, LttngKernelTraceGenerator.getPath(), TRACE_TYPE); | |
121 | SWTBotUtils.activateEditor(fBot, LttngKernelTraceGenerator.getName()); | |
2fe6a9ea PT |
122 | } |
123 | ||
124 | /** | |
125 | * After Test | |
126 | */ | |
127 | @After | |
128 | public void after() { | |
129 | fBot.closeAllEditors(); | |
c4d57ac1 | 130 | SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot); |
2fe6a9ea PT |
131 | } |
132 | } |