lttng.ust: Improve debug-info binary tracking
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / projectexplorer / ProjectExplorerTraceActionsTest.java
CommitLineData
e834a6b4
MAL
1/******************************************************************************
2 * Copyright (c) 2016 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
10package org.eclipse.tracecompass.tmf.ui.swtbot.tests.projectexplorer;
11
12import static org.junit.Assert.assertEquals;
13import static org.junit.Assert.assertTrue;
14import static org.junit.Assert.fail;
15
16import java.io.File;
17import java.io.IOException;
18import java.net.URI;
19import java.net.URISyntaxException;
20import java.net.URL;
21import java.util.List;
22import java.util.stream.Collectors;
23
24import org.apache.log4j.ConsoleAppender;
25import org.apache.log4j.Logger;
26import org.apache.log4j.SimpleLayout;
27import org.eclipse.core.runtime.FileLocator;
28import org.eclipse.core.runtime.Path;
29import org.eclipse.jdt.annotation.NonNull;
30import org.eclipse.swt.widgets.MenuItem;
31import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
32import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
33import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
34import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
35import org.eclipse.swtbot.swt.finder.finders.ContextMenuFinder;
36import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
37import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
38import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
39import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
40import org.eclipse.swtbot.swt.finder.waits.Conditions;
41import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
42import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
43import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
44import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
45import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
46import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
47import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
48import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
49import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
50import org.eclipse.tracecompass.tmf.ui.views.statistics.TmfStatisticsView;
51import org.eclipse.ui.IEditorReference;
52import org.hamcrest.core.IsAnything;
53import org.junit.AfterClass;
54import org.junit.BeforeClass;
55import org.junit.Test;
56import org.junit.runner.RunWith;
57
58import com.google.common.collect.ImmutableList;
59
60/**
61 * SWTBot test for testing Project Explorer Trace actions (context-menus,
62 * keyboard)
63 */
64@RunWith(SWTBotJunit4ClassRunner.class)
65public class ProjectExplorerTraceActionsTest {
66 private static final String TRACE_PROJECT_NAME = "test";
67 private static final String TRACE_NAME = "syslog_collapse";
68 private static final String RENAMED_TRACE_NAME = TRACE_NAME + 2;
69 private static final String TRACE_PATH = "testfiles/" + TRACE_NAME;
70 private static final String TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
71
72 private static File fTestFile = null;
73
74 private static SWTWorkbenchBot fBot;
75
76 /** The Log4j logger instance. */
77 private static final Logger fLogger = Logger.getRootLogger();
78 private static final long NB_EVENTS = 22;
79
80 /**
81 * Test Class setup
82 */
83 @BeforeClass
84 public static void init() {
85 SWTBotUtils.initialize();
86
87 /* set up test trace */
88 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(TRACE_PATH), null);
89 URI uri;
90 try {
91 uri = FileLocator.toFileURL(location).toURI();
92 fTestFile = new File(uri);
93 } catch (URISyntaxException | IOException e) {
94 e.printStackTrace();
95 fail();
96 }
97
98 assertTrue(fTestFile.exists());
99
100 /* Set up for swtbot */
101 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
102 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
103 fLogger.removeAllAppenders();
104 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
105 fBot = new SWTWorkbenchBot();
106
107 /* Close welcome view */
108 SWTBotUtils.closeView("Welcome", fBot);
109
110 /* Switch perspectives */
111 SWTBotUtils.switchToTracingPerspective();
112
113 /* Finish waiting for eclipse to load */
114 SWTBotUtils.waitForJobs();
115 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
116 }
117
118 /**
119 * Test class tear down method.
120 */
121 @AfterClass
122 public static void tearDown() {
123 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
124 fLogger.removeAllAppenders();
125 }
126
127 /**
128 * Test that the expected context menu items are there
129 */
130 @Test
131 public void test4_01ContextMenuPresence() {
132 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
133 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
134
135 final List<String> EXPECTED_MENU_LABELS = ImmutableList.of(
136 "&Open\tShift+Ctrl+R", "Open With", "&Copy...\tCtrl+C", "Rena&me...\tF2", "&Delete\tDelete", "Delete &Supplementary Files...", "&Export Trace Package...", "Select &Trace Type...", "Apply Time Offset...", "Clear Time Offset", "Refresh\tF5");
137
138 // TODO: SWTBot needs a better way to do this
139 ContextMenuFinder finder = new ContextMenuFinder(fBot.tree().widget);
140 List<MenuItem> menuItems = finder.findMenus(traceItem.contextMenu().widget, new IsAnything<>(), false);
141 @NonNull
142 List<String> menuLabels = menuItems.stream().map((item) -> {
143 return UIThreadRunnable.syncExec(() -> item.getText());
144 }).collect(Collectors.toList());
145 assertEquals(EXPECTED_MENU_LABELS, menuLabels);
146
147 fBot.closeAllEditors();
148 }
149
150 /**
151 * Test that the trace opens with the context menu
152 */
153 @Test
154 public void test4_02Open() {
155 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
156 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
157
158 traceItem.contextMenu().menu("Open").click();
159 testEventsTable(TRACE_NAME);
160 testStatisticsView();
161 fBot.closeAllEditors();
162 }
163
164 /**
165 * Test that the trace can be copied with the context menu
166 */
167 @Test
168 public void test4_03Copy() {
169 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
170 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
171
172 createCopy(traceItem);
173
174 fBot.closeAllEditors();
175 SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME);
176 copiedItem.contextMenu().menu("Open").click();
177 testEventsTable(RENAMED_TRACE_NAME);
178 fBot.closeAllEditors();
179 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
180 }
181
182 /**
183 * Test that the trace can be renamed with the context menu
184 */
185 @Test
186 public void test4_04Rename() {
187 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
188 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
189
190 traceItem.contextMenu().menu("Rename...").click();
191 final String RENAME_TRACE_DIALOG_TITLE = "Rename Trace";
192 fBot.waitUntil(Conditions.shellIsActive(RENAME_TRACE_DIALOG_TITLE));
193 SWTBotShell shell = fBot.shell(RENAME_TRACE_DIALOG_TITLE);
194 SWTBotText text = shell.bot().textWithLabel("New Trace name:");
195 text.setText(RENAMED_TRACE_NAME);
196 shell.bot().button("OK").click();
197 fBot.waitUntil(Conditions.shellCloses(shell));
198 fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null));
199
200 SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME);
201 copiedItem.contextMenu().menu("Open").click();
202 testEventsTable(RENAMED_TRACE_NAME);
203 fBot.closeAllEditors();
204 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
205 }
206
207 /**
208 * Test that the trace can be deleted with the context menu
209 */
210 @Test
211 public void test4_05Delete() {
212 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
213 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
214
215 traceItem.contextMenu().menu("Delete").click();
216 final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete";
217 fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE));
218 SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE);
219 shell.bot().button("Yes").click();
220 fBot.waitUntil(Conditions.shellCloses(shell));
221 fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null));
222 }
223
224 /**
225 * Test that the trace opens with the keyboard
226 *
227 * @throws WidgetNotFoundException
228 * when a widget is not found
229 */
230 @Test
231 public void test4_06OpenKeyboard() throws WidgetNotFoundException {
232 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
233 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
234 traceItem.select();
235 fBot.activeShell().pressShortcut(Keystrokes.CR);
236
237 testEventsTable(TRACE_NAME);
238 testStatisticsView();
239 fBot.closeAllEditors();
240 }
241
242 /**
243 * Test that the trace can be deleted with the keyboard
244 */
245 @Test
246 public void test4_07DeleteKeyboard() {
247 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
248 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
249 traceItem.select();
250 fBot.activeShell().pressShortcut(Keystrokes.DELETE);
251 final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete";
252 fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE));
253 SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE);
254 shell.bot().button("Yes").click();
255 fBot.waitUntil(Conditions.shellCloses(shell));
256 fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null));
257 }
258
259 /**
260 * Test that the trace opens with double-click
261 *
262 * @throws WidgetNotFoundException
263 * when a widget is not found
264 */
265 @Test
266 public void test4_08OpenDoubleClick() throws WidgetNotFoundException {
267 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
268 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
269 traceItem.select();
270 traceItem.doubleClick();
271
272 testEventsTable(TRACE_NAME);
273 testStatisticsView();
274 fBot.closeAllEditors();
275 }
276
277 /**
278 * Test that the trace is brought to top if already opened
279 */
280 @Test
281 public void test4_09BringToTop() {
282 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), TRACE_TYPE);
283 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
284 traceItem.select();
285 traceItem.doubleClick();
286 fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME));
287 IEditorReference originalEditor = fBot.activeEditor().getReference();
288
289 createCopy(traceItem);
290
291 SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME);
292 copiedItem.select();
293 copiedItem.doubleClick();
294 copiedItem.doubleClick();
295 fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, RENAMED_TRACE_NAME));
296 SWTBotUtils.delay(1000);
297 traceItem.select();
298 traceItem.doubleClick();
299 fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME));
300 assertTrue(originalEditor == fBot.activeEditor().getReference());
301
302 fBot.closeAllEditors();
303 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
304 }
305
306 private static void createCopy(SWTBotTreeItem traceItem) {
307 traceItem.contextMenu().menu("Copy...").click();
308 final String COPY_TRACE_DIALOG_TITLE = "Copy Trace";
309 fBot.waitUntil(Conditions.shellIsActive(COPY_TRACE_DIALOG_TITLE));
310 SWTBotShell shell = fBot.shell(COPY_TRACE_DIALOG_TITLE);
311 SWTBotText text = shell.bot().textWithLabel("New Trace name:");
312 text.setText(RENAMED_TRACE_NAME);
313 shell.bot().button("OK").click();
314 fBot.waitUntil(Conditions.shellCloses(shell));
315 }
316
317 private static void testEventsTable(String editorName) {
318 SWTBotEditor editor = SWTBotUtils.activeEventsEditor(fBot, editorName);
319 fBot.waitUntil(ConditionHelpers.numberOfEventsInTrace(TmfTraceManager.getInstance().getActiveTrace(), NB_EVENTS));
320
321 SWTBotTable table = editor.bot().table();
322 fBot.waitUntil(new DefaultCondition() {
323 @Override
324 public boolean test() throws Exception {
325 return table.rowCount() > 1;
326 }
327
328 @Override
329 public String getFailureMessage() {
330 return "No items in table";
331 }
332 });
333 // Select first event (skip filter/search row)
334 table.getTableItem(1).select();
335
336 editor.bot().waitUntil(new DefaultCondition() {
337 @Override
338 public boolean test() throws Exception {
339 return table.selection().rowCount() == 1 && table.selection().get(0).toString().contains("01:01");
340 }
341
342 @Override
343 public String getFailureMessage() {
344 return "First event not selected";
345 }
346 });
347 }
348
349 private static void testStatisticsView() {
350 SWTBotUtils.openView(TmfStatisticsView.ID);
351 SWTBotView view = fBot.viewById(TmfStatisticsView.ID);
352 assertTrue(view.bot().tree().hasItems());
353 view.bot().tree().cell(0, 1).equals(Long.toString(NB_EVENTS));
354 }
355}
This page took 0.038029 seconds and 5 git commands to generate.