tmf: Add a way to clear the traces using SWTBot only
[deliverable/tracecompass.git] / releng / org.eclipse.tracecompass.integration.swtbot.tests / src / org / eclipse / tracecompass / integration / 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
a4f6f73b 10package org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer;
e834a6b4
MAL
11
12import static org.junit.Assert.assertEquals;
13import static org.junit.Assert.assertTrue;
e834a6b4
MAL
14
15import java.io.File;
16import java.io.IOException;
e834a6b4 17import java.util.List;
e834a6b4
MAL
18
19import org.apache.log4j.ConsoleAppender;
20import org.apache.log4j.Logger;
21import org.apache.log4j.SimpleLayout;
e9a570ab 22import org.eclipse.core.resources.ResourcesPlugin;
e834a6b4
MAL
23import org.eclipse.core.runtime.Path;
24import org.eclipse.jdt.annotation.NonNull;
e834a6b4
MAL
25import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
26import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
27import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
28import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
e834a6b4
MAL
29import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
30import org.eclipse.swtbot.swt.finder.keyboard.Keystrokes;
31import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
32import org.eclipse.swtbot.swt.finder.waits.Conditions;
33import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
34import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
35import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
36import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
37import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
a4f6f73b 38import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
e834a6b4
MAL
39import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
40import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
41import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
42import org.eclipse.tracecompass.tmf.ui.views.statistics.TmfStatisticsView;
43import org.eclipse.ui.IEditorReference;
e834a6b4
MAL
44import org.junit.AfterClass;
45import org.junit.BeforeClass;
46import org.junit.Test;
47import org.junit.runner.RunWith;
48
49import com.google.common.collect.ImmutableList;
50
51/**
52 * SWTBot test for testing Project Explorer Trace actions (context-menus,
53 * keyboard)
54 */
55@RunWith(SWTBotJunit4ClassRunner.class)
56public class ProjectExplorerTraceActionsTest {
a4f6f73b 57 private static @NonNull TestTraceInfo CUSTOM_TEXT_LOG = new TestTraceInfo("ExampleCustomTxt.log", "Custom Text : TmfGeneric", 10, "29:52.034");
e834a6b4 58 private static final String TRACE_PROJECT_NAME = "test";
a4f6f73b 59 private static final String TRACE_NAME = CUSTOM_TEXT_LOG.getTraceName();
e834a6b4 60 private static final String RENAMED_TRACE_NAME = TRACE_NAME + 2;
e834a6b4
MAL
61
62 private static File fTestFile = null;
63
64 private static SWTWorkbenchBot fBot;
65
66 /** The Log4j logger instance. */
67 private static final Logger fLogger = Logger.getRootLogger();
a4f6f73b
MAL
68
69 private static final File TEST_TRACES_PATH = new File(new Path(TmfTraceManager.getTemporaryDirPath()).append("testtraces").toOSString());
70 private static String getPath(String relativePath) {
71 return new Path(TEST_TRACES_PATH.getAbsolutePath()).append(relativePath).toOSString();
72 }
e834a6b4
MAL
73
74 /**
75 * Test Class setup
a4f6f73b
MAL
76 *
77 * @throws IOException
78 * on error
e834a6b4
MAL
79 */
80 @BeforeClass
a4f6f73b
MAL
81 public static void init() throws IOException {
82 TestDirectoryStructureUtil.generateTraceStructure(TEST_TRACES_PATH);
83
e834a6b4
MAL
84 SWTBotUtils.initialize();
85
a4f6f73b
MAL
86 // FIXME: We can't use Manage Custom Parsers > Import because it uses a native dialog. We'll still check that they show up in the dialog
87 CustomTxtTraceDefinition[] txtDefinitions = CustomTxtTraceDefinition.loadAll(getPath("customParsers/ExampleCustomTxtParser.xml"));
88 txtDefinitions[0].save();
e834a6b4 89 /* set up test trace */
a4f6f73b 90 fTestFile = new File(getPath(new Path("import").append(CUSTOM_TEXT_LOG.getTracePath()).toString()));
e834a6b4
MAL
91
92 assertTrue(fTestFile.exists());
93
94 /* Set up for swtbot */
95 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
96 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
97 fLogger.removeAllAppenders();
98 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
99 fBot = new SWTWorkbenchBot();
100
101 /* Close welcome view */
102 SWTBotUtils.closeView("Welcome", fBot);
103
104 /* Switch perspectives */
105 SWTBotUtils.switchToTracingPerspective();
106
107 /* Finish waiting for eclipse to load */
108 SWTBotUtils.waitForJobs();
109 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
110 }
111
112 /**
113 * Test class tear down method.
114 */
115 @AfterClass
116 public static void tearDown() {
117 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
118 fLogger.removeAllAppenders();
119 }
120
121 /**
122 * Test that the expected context menu items are there
bb92c458
MK
123 * <p>
124 * Action : Trace menu
125 * <p>
126 * Procedure :Select an LTTng trace and open its context menu
127 * <p>
128 * Expected Results: Correct menu opens (Open , Copy, Rename, …)
129 *
e834a6b4
MAL
130 */
131 @Test
132 public void test4_01ContextMenuPresence() {
a4f6f73b 133 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
134 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
135
a4f6f73b
MAL
136 final List<String> EXPECTED_MENU_LABELS = ImmutableList.of("Open", "Open With", "", "Copy...", "Rename...", "Delete", "", "Delete Supplementary Files...", "", "Export Trace Package...", "", "Select Trace Type...", "", "Apply Time Offset...",
137 "Clear Time Offset", "", "Refresh");
138 List<String> menuItems = traceItem.contextMenu().menuItems();
139 assertEquals(EXPECTED_MENU_LABELS, menuItems);
e834a6b4
MAL
140
141 fBot.closeAllEditors();
142 }
143
144 /**
145 * Test that the trace opens with the context menu
bb92c458
MK
146 * <p>
147 * Action : Open trace
148 * <p>
149 * Procedure :Select the Open menu
150 * <p>
151 * Expected Results: Trace is opened and views are populated
152 *
e834a6b4
MAL
153 */
154 @Test
155 public void test4_02Open() {
a4f6f73b 156 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
157 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
158
159 traceItem.contextMenu().menu("Open").click();
160 testEventsTable(TRACE_NAME);
161 testStatisticsView();
162 fBot.closeAllEditors();
163 }
164
165 /**
166 * Test that the trace can be copied with the context menu
bb92c458
MK
167 * <p>
168 * Action : Copy trace
169 * <p>
170 * Procedure :Select the Copy menu and provide a new name. Open.
171 * <p>
172 * Expected Results: Trace is replicated under the new name
173 *
e834a6b4
MAL
174 */
175 @Test
176 public void test4_03Copy() {
a4f6f73b 177 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
178 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
179
180 createCopy(traceItem);
181
182 fBot.closeAllEditors();
183 SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME);
184 copiedItem.contextMenu().menu("Open").click();
185 testEventsTable(RENAMED_TRACE_NAME);
186 fBot.closeAllEditors();
450daec8 187 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
e834a6b4
MAL
188 }
189
190 /**
191 * Test that the trace can be renamed with the context menu
bb92c458
MK
192 * <p>
193 * Action : Rename trace
194 * <p>
195 * Procedure :Select the Rename menu and provide a new name. Reopen.
196 * <p>
197 * Expected Results: Trace is renamed. The trace editor is closed.
e834a6b4
MAL
198 */
199 @Test
200 public void test4_04Rename() {
a4f6f73b 201 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
202 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
203
204 traceItem.contextMenu().menu("Rename...").click();
205 final String RENAME_TRACE_DIALOG_TITLE = "Rename Trace";
206 fBot.waitUntil(Conditions.shellIsActive(RENAME_TRACE_DIALOG_TITLE));
207 SWTBotShell shell = fBot.shell(RENAME_TRACE_DIALOG_TITLE);
208 SWTBotText text = shell.bot().textWithLabel("New Trace name:");
209 text.setText(RENAMED_TRACE_NAME);
210 shell.bot().button("OK").click();
211 fBot.waitUntil(Conditions.shellCloses(shell));
212 fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null));
213
214 SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME);
215 copiedItem.contextMenu().menu("Open").click();
216 testEventsTable(RENAMED_TRACE_NAME);
217 fBot.closeAllEditors();
450daec8 218 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
e834a6b4
MAL
219 }
220
221 /**
222 * Test that the trace can be deleted with the context menu
bb92c458
MK
223 * <p>
224 * Action : Delete trace
225 * <p>
226 * Procedure :Select the Delete menu and confirm deletion
227 * <p>
228 * Expected Results: Trace is deleted. The trace editor is closed.
229 *
e834a6b4
MAL
230 */
231 @Test
232 public void test4_05Delete() {
a4f6f73b 233 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
234 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
235
236 traceItem.contextMenu().menu("Delete").click();
237 final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete";
238 fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE));
239 SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE);
240 shell.bot().button("Yes").click();
241 fBot.waitUntil(Conditions.shellCloses(shell));
242 fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null));
e9a570ab 243 fBot.waitUntil(new TraceDeletedCondition());
e834a6b4
MAL
244 }
245
246 /**
247 * Test that the trace opens with the keyboard
bb92c458
MK
248 * <p>
249 * Action : Open Trace (Accelerator)
250 * <p>
251 * Procedure :Select trace and press Enter
252 * <p>
253 * Expected Results: Trace is opened
254 *
e834a6b4
MAL
255 *
256 * @throws WidgetNotFoundException
257 * when a widget is not found
258 */
259 @Test
260 public void test4_06OpenKeyboard() throws WidgetNotFoundException {
a4f6f73b 261 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
262 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
263 traceItem.select();
264 fBot.activeShell().pressShortcut(Keystrokes.CR);
265
266 testEventsTable(TRACE_NAME);
267 testStatisticsView();
268 fBot.closeAllEditors();
269 }
270
271 /**
272 * Test that the trace can be deleted with the keyboard
bb92c458
MK
273 * <p>
274 * Action : Delete Trace (Accelerator)
275 * <p>
276 * Procedure :Select trace and press Delete and confirm deletion
277 * <p>
278 * Expected Results: Trace is deleted. The trace editor is closed.
e834a6b4
MAL
279 */
280 @Test
281 public void test4_07DeleteKeyboard() {
a4f6f73b 282 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
283 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
284 traceItem.select();
285 fBot.activeShell().pressShortcut(Keystrokes.DELETE);
286 final String DELETE_TRACE_DIALOG_TITLE = "Confirm Delete";
287 fBot.waitUntil(Conditions.shellIsActive(DELETE_TRACE_DIALOG_TITLE));
288 SWTBotShell shell = fBot.shell(DELETE_TRACE_DIALOG_TITLE);
289 shell.bot().button("Yes").click();
290 fBot.waitUntil(Conditions.shellCloses(shell));
291 fBot.waitWhile(new ConditionHelpers.ActiveEventsEditor(fBot, null));
e9a570ab 292 fBot.waitUntil(new TraceDeletedCondition());
e834a6b4
MAL
293 }
294
295 /**
296 * Test that the trace opens with double-click
bb92c458
MK
297 * <p>
298 * Action : Open Trace (double click)
299 * <p>
300 * Procedure :Double-click a trace
301 * <p>
302 * Expected Results: Trace is opened
e834a6b4
MAL
303 *
304 * @throws WidgetNotFoundException
305 * when a widget is not found
306 */
307 @Test
308 public void test4_08OpenDoubleClick() throws WidgetNotFoundException {
a4f6f73b 309 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
310 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
311 traceItem.select();
312 traceItem.doubleClick();
313
314 testEventsTable(TRACE_NAME);
315 testStatisticsView();
316 fBot.closeAllEditors();
317 }
318
319 /**
320 * Test that the trace is brought to top if already opened
bb92c458
MK
321 * <p>
322 * Action : Open Trace (already open)
323 * <p>
324 * Procedure :Open two traces. Open the first trace again.
325 * <p>
326 * Expected Results: The first trace editor is simply brought to front.
e834a6b4
MAL
327 */
328 @Test
329 public void test4_09BringToTop() {
a4f6f73b 330 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CUSTOM_TEXT_LOG.getTraceType());
e834a6b4
MAL
331 SWTBotTreeItem traceItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), TRACE_NAME);
332 traceItem.select();
333 traceItem.doubleClick();
334 fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME));
335 IEditorReference originalEditor = fBot.activeEditor().getReference();
336
337 createCopy(traceItem);
338
339 SWTBotTreeItem copiedItem = SWTBotUtils.getTraceProjectItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), RENAMED_TRACE_NAME);
340 copiedItem.select();
341 copiedItem.doubleClick();
342 copiedItem.doubleClick();
343 fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, RENAMED_TRACE_NAME));
344 SWTBotUtils.delay(1000);
345 traceItem.select();
346 traceItem.doubleClick();
347 fBot.waitUntil(new ConditionHelpers.ActiveEventsEditor(fBot, TRACE_NAME));
348 assertTrue(originalEditor == fBot.activeEditor().getReference());
349
350 fBot.closeAllEditors();
450daec8 351 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
e834a6b4
MAL
352 }
353
354 private static void createCopy(SWTBotTreeItem traceItem) {
355 traceItem.contextMenu().menu("Copy...").click();
356 final String COPY_TRACE_DIALOG_TITLE = "Copy Trace";
357 fBot.waitUntil(Conditions.shellIsActive(COPY_TRACE_DIALOG_TITLE));
358 SWTBotShell shell = fBot.shell(COPY_TRACE_DIALOG_TITLE);
359 SWTBotText text = shell.bot().textWithLabel("New Trace name:");
360 text.setText(RENAMED_TRACE_NAME);
361 shell.bot().button("OK").click();
362 fBot.waitUntil(Conditions.shellCloses(shell));
363 }
364
365 private static void testEventsTable(String editorName) {
366 SWTBotEditor editor = SWTBotUtils.activeEventsEditor(fBot, editorName);
a4f6f73b 367 fBot.waitUntil(ConditionHelpers.numberOfEventsInTrace(TmfTraceManager.getInstance().getActiveTrace(), CUSTOM_TEXT_LOG.getNbEvents()));
e834a6b4
MAL
368
369 SWTBotTable table = editor.bot().table();
370 fBot.waitUntil(new DefaultCondition() {
371 @Override
372 public boolean test() throws Exception {
373 return table.rowCount() > 1;
374 }
375
376 @Override
377 public String getFailureMessage() {
378 return "No items in table";
379 }
380 });
381 // Select first event (skip filter/search row)
382 table.getTableItem(1).select();
383
384 editor.bot().waitUntil(new DefaultCondition() {
385 @Override
386 public boolean test() throws Exception {
a4f6f73b 387 return table.selection().rowCount() == 1 && table.selection().get(0).toString().contains(CUSTOM_TEXT_LOG.getFirstEventTimestamp());
e834a6b4
MAL
388 }
389
390 @Override
391 public String getFailureMessage() {
392 return "First event not selected";
393 }
394 });
395 }
396
397 private static void testStatisticsView() {
398 SWTBotUtils.openView(TmfStatisticsView.ID);
399 SWTBotView view = fBot.viewById(TmfStatisticsView.ID);
400 assertTrue(view.bot().tree().hasItems());
a4f6f73b 401 view.bot().tree().cell(0, 1).equals(Long.toString(CUSTOM_TEXT_LOG.getNbEvents()));
e834a6b4 402 }
e9a570ab
MAL
403
404 private final class TraceDeletedCondition extends DefaultCondition {
405 @Override
406 public boolean test() throws Exception {
407 return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME).findMember(new Path("Traces/" + TRACE_NAME)) == null;
408 }
409
410 @Override
411 public String getFailureMessage() {
412 return TRACE_NAME + " was not deleted successfully.";
413 }
414 }
e834a6b4 415}
This page took 0.057194 seconds and 5 git commands to generate.