tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / releng / org.eclipse.tracecompass.integration.swtbot.tests / src / org / eclipse / tracecompass / integration / swtbot / tests / projectexplorer / ProjectExplorerTracesFolderTest.java
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
10 package org.eclipse.tracecompass.integration.swtbot.tests.projectexplorer;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotEquals;
14
15 import java.io.File;
16 import java.io.IOException;
17 import java.util.List;
18 import java.util.Set;
19 import java.util.function.Supplier;
20
21 import org.apache.log4j.Logger;
22 import org.apache.log4j.varia.NullAppender;
23 import org.eclipse.core.runtime.IPath;
24 import org.eclipse.core.runtime.Path;
25 import org.eclipse.jdt.annotation.NonNull;
26 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
27 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
28 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
29 import org.eclipse.swtbot.swt.finder.SWTBot;
30 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
31 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
32 import org.eclipse.swtbot.swt.finder.waits.Conditions;
33 import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
34 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
35 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
36 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation;
37 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
38 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomTxtTraceDefinition;
39 import org.eclipse.tracecompass.tmf.core.parsers.custom.CustomXmlTraceDefinition;
40 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
41 import org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests.SWTBotImportWizardUtils;
42 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
43 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
44 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
45 import org.eclipse.ui.IPageLayout;
46 import org.junit.AfterClass;
47 import org.junit.BeforeClass;
48 import org.junit.FixMethodOrder;
49 import org.junit.Test;
50 import org.junit.runner.RunWith;
51 import org.junit.runners.MethodSorters;
52
53 import com.google.common.collect.ImmutableList;
54 import com.google.common.collect.ImmutableSet;
55
56 /**
57 * SWTBot test for testing Project Explorer trace folders (context-menu,
58 * import, etc).
59 */
60 @RunWith(SWTBotJunit4ClassRunner.class)
61 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
62 @SuppressWarnings({"restriction", "javadoc"})
63 public class ProjectExplorerTracesFolderTest {
64
65 private static final String PROP_LAST_MODIFIED_PROPERTY = "last modified";
66 private static final String TEXT_EDITOR_ID = "org.eclipse.ui.DefaultTextEditor";
67
68 private static final String GENERIC_CTF_TRACE_TYPE = "Common Trace Format : Generic CTF Trace";
69 private static final String LTTNG_KERNEL_TRACE_TYPE = "Common Trace Format : Linux Kernel Trace";
70 private static final String LTTNG_UST_TRACE_TYPE = "Common Trace Format : LTTng UST Trace";
71 private static final String CUSTOM_TEXT_TRACE_TYPE = "Custom Text : TmfGeneric";
72 private static final String CUSTOM_XML_TRACE_TYPE = "Custom XML : Custom XML Log";
73
74 private static final @NonNull TestTraceInfo CUSTOM_TEXT_LOG = new TestTraceInfo("ExampleCustomTxt.log", CUSTOM_TEXT_TRACE_TYPE, 10, "29:52.034");
75 private static final @NonNull TestTraceInfo CUSTOM_XML_LOG = new TestTraceInfo("ExampleCustomXml.xml", CUSTOM_XML_TRACE_TYPE, 6, "22:01:20");
76 private static final @NonNull TestTraceInfo LTTNG_KERNEL_TRACE = new TestTraceInfo("kernel-overlap-testing", LTTNG_KERNEL_TRACE_TYPE, 1000, "04:32.650 993 664");
77 private static final @NonNull TestTraceInfo SIMPLE_SERVER1_UST_TRACE = new TestTraceInfo("simple_server-thread1", LTTNG_UST_TRACE_TYPE, 1000, "04:32.650 993 664");
78 private static final @NonNull TestTraceInfo SIMPLE_SERVER2_UST_TRACE = new TestTraceInfo("simple_server-thread2", LTTNG_UST_TRACE_TYPE, 1000, "04:32.650 993 664");
79 private static final @NonNull TestTraceInfo UST_OVERLAP_TESTING_UST_TRACE = new TestTraceInfo("ust-overlap-testing", LTTNG_UST_TRACE_TYPE, 1000, "04:32.650 993 664");
80
81 private static final String CLASHES_DIR_NAME = "z-clashes";
82 private static final @NonNull TestTraceInfo CLASHES_CUSTOM_TEXT_LOG = new TestTraceInfo("ExampleCustomTxt.log", CLASHES_DIR_NAME + "/ExampleCustomTxt.log", CUSTOM_TEXT_TRACE_TYPE, 11, "29:52.034");
83 private static final @NonNull TestTraceInfo CLASHES_CUSTOM_XML_LOG = new TestTraceInfo("ExampleCustomXml.xml", CLASHES_DIR_NAME + "/ExampleCustomXml.xml", CUSTOM_XML_TRACE_TYPE, 7, "22:01:20");
84 private static final @NonNull TestTraceInfo CLASHES_LTTNG_KERNEL_TRACE = new TestTraceInfo("kernel-overlap-testing", CLASHES_DIR_NAME + "/kernel-overlap-testing", LTTNG_KERNEL_TRACE_TYPE, 1001, "04:32.650 993 664");
85 private static final @NonNull TestTraceInfo CLASHES_SIMPLE_SERVER1_UST_TRACE = new TestTraceInfo("simple_server-thread1", CLASHES_DIR_NAME + "/simple_server-thread1", LTTNG_UST_TRACE_TYPE, 1001, "04:32.650 993 664");
86 private static final @NonNull TestTraceInfo CLASHES_SIMPLE_SERVER2_UST_TRACE = new TestTraceInfo("simple_server-thread2", CLASHES_DIR_NAME + "/simple_server-thread2", LTTNG_UST_TRACE_TYPE, 1001, "04:32.650 993 664");
87 private static final @NonNull TestTraceInfo CLASHES_UST_OVERLAP_TESTING_UST_TRACE = new TestTraceInfo("ust-overlap-testing", CLASHES_DIR_NAME + "/ust-overlap-testing", LTTNG_UST_TRACE_TYPE, 1001, "04:32.650 993 664");
88
89
90 private static final @NonNull TestTraceInfo LTTNG_KERNEL_TRACE_METADATA = new TestTraceInfo(LTTNG_KERNEL_TRACE.getTraceName(), LTTNG_KERNEL_TRACE.getTraceName() + "/metadata", LTTNG_KERNEL_TRACE.getTraceType(), LTTNG_KERNEL_TRACE.getNbEvents(),
91 LTTNG_KERNEL_TRACE.getFirstEventTimestamp());
92 private static final @NonNull TestTraceInfo UNRECOGNIZED_LOG = new TestTraceInfo("unrecognized.log", "", 0, "");
93 private static final @NonNull TestTraceInfo CUSTOM_XML_LOG_AS_TEXT = new TestTraceInfo("ExampleCustomXml.xml", CUSTOM_TEXT_TRACE_TYPE, 0, "");
94
95 private static final TestTraceInfo[] ALL_TRACEINFOS = new TestTraceInfo[] {
96 CUSTOM_TEXT_LOG,
97 CUSTOM_XML_LOG,
98 LTTNG_KERNEL_TRACE,
99 SIMPLE_SERVER1_UST_TRACE,
100 SIMPLE_SERVER2_UST_TRACE,
101 UST_OVERLAP_TESTING_UST_TRACE,
102
103 CLASHES_CUSTOM_TEXT_LOG,
104 CLASHES_CUSTOM_XML_LOG,
105 CLASHES_LTTNG_KERNEL_TRACE,
106 CLASHES_SIMPLE_SERVER1_UST_TRACE,
107 CLASHES_SIMPLE_SERVER2_UST_TRACE,
108 CLASHES_UST_OVERLAP_TESTING_UST_TRACE
109 };
110
111 private static final Set<TestTraceInfo> CLASHING_TRACEINFOS = ImmutableSet.of(
112 CLASHES_CUSTOM_TEXT_LOG,
113 CLASHES_CUSTOM_XML_LOG,
114 CLASHES_LTTNG_KERNEL_TRACE,
115 CLASHES_SIMPLE_SERVER1_UST_TRACE,
116 CLASHES_SIMPLE_SERVER2_UST_TRACE,
117 CLASHES_UST_OVERLAP_TESTING_UST_TRACE);
118
119 // All normal traces plus the unrecognized trace
120 private static final int NUM_UNIQUE_TRACES = CLASHING_TRACEINFOS.size() + 1;
121
122
123 private static final File TEST_TRACES_PATH = new File(new Path(TmfTraceManager.getTemporaryDirPath()).append("testtraces").toOSString());
124 private static final String TRACE_PROJECT_NAME = "test";
125 private static final String MANAGE_CUSTOM_PARSERS_SHELL_TITLE = "Manage Custom Parsers";
126
127 private static SWTWorkbenchBot fBot;
128
129 /** The Log4j logger instance. */
130 private static final Logger fLogger = Logger.getRootLogger();
131
132 private static String getPath(String relativePath) {
133 return new Path(TEST_TRACES_PATH.getAbsolutePath()).append(relativePath).toOSString();
134 }
135
136 /**
137 * Test Class setup
138 *
139 * @throws IOException
140 */
141 @BeforeClass
142 public static void init() throws IOException {
143 TestDirectoryStructureUtil.generateTraceStructure(TEST_TRACES_PATH);
144
145 SWTBotUtils.initialize();
146
147 /* Set up for swtbot */
148 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
149 SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
150 fLogger.removeAllAppenders();
151 fLogger.addAppender(new NullAppender());
152 fBot = new SWTWorkbenchBot();
153
154 SWTBotUtils.closeView("Welcome", fBot);
155
156 SWTBotUtils.switchToTracingPerspective();
157
158 /* Finish waiting for eclipse to load */
159 WaitUtils.waitForJobs();
160 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
161 }
162
163 /**
164 * Test class tear down method.
165 */
166 @AfterClass
167 public static void tearDown() {
168 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
169 fLogger.removeAllAppenders();
170 }
171
172 private static void test3_01Preparation() {
173 // 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
174 CustomTxtTraceDefinition[] txtDefinitions = CustomTxtTraceDefinition.loadAll(getPath("customParsers/ExampleCustomTxtParser.xml"));
175 txtDefinitions[0].save();
176 CustomXmlTraceDefinition[] xmlDefinitions = CustomXmlTraceDefinition.loadAll(getPath("customParsers/ExampleCustomXmlParser.xml"));
177 xmlDefinitions[0].save();
178
179 SWTBotTreeItem traceFolder = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
180 traceFolder.contextMenu("Manage Custom Parsers...").click();
181 fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE));
182 SWTBotShell shell = fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE);
183 SWTBot shellBot = shell.bot();
184
185 // Make sure the custom text trace type is imported
186 shellBot.list().select(CUSTOM_TEXT_LOG.getTraceType());
187
188 // Make sure the custom xml trace type is imported
189 shellBot.radio("XML").click();
190 shellBot.list().select(CUSTOM_XML_LOG.getTraceType());
191 shellBot.button("Close").click();
192 shellBot.waitUntil(Conditions.shellCloses(shell));
193 }
194
195 /**
196 * Test that the expected context menu items are there
197 * <p>
198 * Action : Trace Folder menu
199 * <p>
200 * Procedure :Select the Traces folder and open its context menu
201 * <p>
202 * Expected Results: Correct menu opens (Import, Refresh, etc)
203 */
204 @Test
205 public void test3_01ContextMenuPresence() {
206 test3_01Preparation();
207
208 SWTBotTreeItem traceItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
209
210 final List<String> EXPECTED_MENU_LABELS = ImmutableList.of(
211 "Open Trace...",
212 "",
213 "Import...",
214 "",
215 "New Folder...",
216 "Clear",
217 "",
218 "Import Trace Package...",
219 "Fetch Remote Traces...",
220 "",
221 "Export Trace Package...",
222 "",
223 "Manage Custom Parsers...",
224 "Manage XML analyses...",
225 "",
226 "Apply Time Offset...",
227 "Clear Time Offset",
228 "",
229 "Refresh");
230
231 List<String> menuLabels = traceItem.contextMenu().menuItems();
232 for (int i = 0; i < menuLabels.size(); i++) {
233 assertEquals(EXPECTED_MENU_LABELS.get(i), menuLabels.get(i));
234 }
235
236 fBot.closeAllEditors();
237 }
238
239 /**
240 * Test that the trace import wizard appears
241 * <p>
242 * Action : Trace Import Wizard
243 * <p>
244 * Procedure : Select Import
245 * <p>
246 * Expected Results: Trace Import Wizard appears
247 */
248 @Test
249 public void test3_02Import() {
250 SWTBotTreeItem traceItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
251
252 SWTBotShell shell = openTraceFoldersImport(traceItem);
253 shell.bot().button("Cancel").click();
254 }
255
256 /**
257 * Test that the trace import wizard can import a single custom text trace
258 * <p>
259 * Action : Import single custom text trace (link to workspace)
260 * <p>
261 * <pre>
262 * Procedure : 1) Browse to directory ${local}/traces/import/
263 * 2) Select trace ExampleCustomTxt.log
264 * 3) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning" and select "Create Links to workspace" and
265 * 4) press Finish
266 * </pre>
267 * <p>
268 * Expected Results: Imported trace appear in Traces Folder and the Trace Type Tmf Generic is set. Make sure trace can be opened
269 */
270 @Test
271 public void test3_03SingleCustomTextTrace() {
272 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
273 testSingleTrace(CUSTOM_TEXT_LOG, optionFlags);
274 }
275
276 /**
277 * <p>
278 * Action : Import Single custom XML trace (link to workspace)
279 * <p>
280 *
281 * <pre>
282 * Procedure : redo 3.1-3.3 but this time select ExampleCustomXml.xml
283 * </pre>
284 * <p>
285 * Expected Results: Imported trace appear in Traces Folder and the Trace
286 * Type "Custom XML log" is set. Make sure that trace can be opened
287 */
288 @Test
289 public void test3_04SingleCustomXmlTrace() {
290 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
291 testSingleTrace(CUSTOM_XML_LOG, optionFlags);
292 }
293
294 /**
295 * <p>
296 * Action : Import LTTng Kernel CTF trace (link to workspace)
297 * <p>
298 *
299 * <pre>
300 * Procedure : redo 3.1-3.3 but this time select directory kernel-overlap-testing/
301 * </pre>
302 * <p>
303 * Expected Results: Imported trace appear in Traces Folder and the Trace
304 * Type "LTTng Kernel" is set. Make sure that trace can be opened
305 */
306 @Test
307 public void test3_05SingleCtfTrace() {
308 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
309 testSingleTrace(LTTNG_KERNEL_TRACE, optionFlags);
310 }
311
312 /**
313 * <p>
314 * Action : Rename + copy import
315 * <p>
316 *
317 * <pre>
318 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace"
319 * 2) When dialog box appear select Rename
320 * </pre>
321 * <p>
322 * Expected Results: Traces are imported with new name that has a suffix (2)
323 * at the end. Make sure that imported traces are copied to the project.
324 */
325 @Test
326 public void test3_06RenameCopyImport() {
327 testRenameCopyImport(CUSTOM_TEXT_LOG);
328 testRenameCopyImport(CUSTOM_XML_LOG);
329 testRenameCopyImport(LTTNG_KERNEL_TRACE);
330 }
331
332 private static void testRenameCopyImport(TestTraceInfo traceInfo) {
333 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES;
334 importTrace(optionFlags, ImportConfirmation.RENAME, traceInfo.getTraceName());
335 String renamed = toRenamedName(traceInfo.getTraceName());
336 verifyTrace(traceInfo, optionFlags, renamed);
337 }
338
339 /**
340 * <p>
341 * Action : Overwrite + copy import
342 * <p>
343 *
344 * <pre>
345 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace"
346 * 2) When dialog box appear select Overwrite
347 * </pre>
348 * <p>
349 * Expected Results: Existing traces are deleted and new traces are
350 * imported. Make sure that imported traces are copied to the project and
351 * can be opened
352 */
353 @Test
354 public void test3_07OverwriteCopyImport() {
355 testOverwriteCopyImport(CUSTOM_TEXT_LOG);
356 testOverwriteCopyImport(CUSTOM_XML_LOG);
357 testOverwriteCopyImport(LTTNG_KERNEL_TRACE);
358 }
359
360 private static void testOverwriteCopyImport(TestTraceInfo traceInfo) {
361 String traceName = traceInfo.getTraceName();
362 SWTBotTreeItem traceItem = SWTBotUtils.getTreeItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), traceName);
363 String lastModified = getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY);
364 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES;
365 importTrace(optionFlags, ImportConfirmation.OVERWRITE, traceName);
366 verifyTrace(traceInfo, optionFlags);
367
368 assertNotEquals(lastModified, getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY));
369 }
370
371 /**
372 * <p>
373 * Action : Skip
374 * <p>
375 *
376 * <pre>
377 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace"
378 * 2) When dialog box appear select Skip
379 * </pre>
380 * <p>
381 * Expected Results: Make sure that no new trace is imported
382 */
383 @Test
384 public void test3_08SkipImport() {
385 testSkipImport(CUSTOM_TEXT_LOG);
386 testSkipImport(CUSTOM_XML_LOG);
387 testSkipImport(LTTNG_KERNEL_TRACE);
388 }
389
390 private static void testSkipImport(TestTraceInfo traceInfo) {
391 String traceName = traceInfo.getTraceName();
392 SWTBotTreeItem traceItem = SWTBotUtils.getTreeItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), traceName);
393 String lastModified = getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY);
394 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES;
395 importTrace(optionFlags, ImportConfirmation.SKIP, traceName);
396 verifyTrace(traceInfo, optionFlags);
397
398 assertEquals(lastModified, getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY));
399 }
400
401 /**
402 * <p>
403 * Action : Default overwrite
404 * <p>
405 *
406 * <pre>
407 * Procedure : 1) redo 3.3, 3.4, 3.5. However, Unselect "Create Links to workspace" and select "Overwrite existing without warning"
408 * </pre>
409 * <p>
410 * Expected Results: Make sure that no dialog box appears (for renaming,
411 * overwriting, skipping) and existing traces are overwritten). Make sure
412 * trace can be opened
413 */
414 @Test
415 public void test3_09OverwriteOptionImport() {
416 testOverwriteOptionImport(CUSTOM_TEXT_LOG);
417 testOverwriteOptionImport(CUSTOM_XML_LOG);
418 testOverwriteOptionImport(LTTNG_KERNEL_TRACE);
419 }
420
421 private static void testOverwriteOptionImport(TestTraceInfo traceInfo) {
422 String traceName = traceInfo.getTraceName();
423 SWTBotTreeItem traceItem = SWTBotUtils.getTreeItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), traceName);
424 String lastModified = getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY);
425
426 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES;
427 importTrace(optionFlags, ImportConfirmation.CONTINUE, traceName);
428 verifyTrace(traceInfo, optionFlags);
429
430 assertNotEquals(lastModified, getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY));
431 }
432
433 /**
434 * <p>
435 * Action : Import unrecognized
436 * <p>
437 *
438 * <pre>
439 * Procedure : 1) Open Import wizard (see 3.1-3.2)
440 * 2) Browse to directory ${local}/traces/import
441 * 3) Select trace unrecognized.log
442 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning" and select "Create Links to workspace" and
443 * 5) press Finish
444 * </pre>
445 * <p>
446 * Expected Results: unrecognized.log is imported with trace type unknown.
447 * The default text file icon is displayed. The trace, when opened, is
448 * displayed in the text editor.
449 */
450 @Test
451 public void test3_10ImportUnrecognized() {
452 String traceName = UNRECOGNIZED_LOG.getTraceName();
453 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
454 importTrace(optionFlags, traceName);
455 verifyTrace(UNRECOGNIZED_LOG, optionFlags);
456 }
457
458 /**
459 * <p>
460 * Action : Import unrecognized (ignore)
461 * <p>
462 *
463 * <pre>
464 * Procedure : 1) redo 3.10, however unselect "Import unrecognized traces"
465 * </pre>
466 * <p>
467 * Expected Results: unrecognized.log is not imported
468 */
469 @Test
470 public void test3_11ImportUnrecognizedIgnore() {
471 String traceName = UNRECOGNIZED_LOG.getTraceName();
472 SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
473 int numTraces = tracesFolderItem.getItems().length;
474
475 SWTBotTreeItem traceItem = SWTBotUtils.getTreeItem(fBot, tracesFolderItem, traceName);
476 String lastModified = getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY);
477
478 int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
479 importTrace(optionFlags, traceName);
480 verifyTrace(UNRECOGNIZED_LOG, optionFlags);
481
482 assertEquals(lastModified, getTraceProperty(traceItem, PROP_LAST_MODIFIED_PROPERTY));
483 assertEquals(numTraces, tracesFolderItem.getItems().length);
484 }
485
486 /**
487 * <p>
488 * Action : Import CTF trace by selection metadata file only
489 * <p>
490 *
491 * <pre>
492 * Procedure : 1) Redo 3.5, However only select metadata file instead of directory trace
493 * </pre>
494 * <p>
495 * Expected Results: Imported trace appear in Traces Folder and the Trace
496 * Type "LTTng Kernel" is set. Make sure that trace can be opened
497 */
498 @Test
499 public void test3_12ImportCtfWithMetadataSelection() {
500 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
501 testSingleTrace(LTTNG_KERNEL_TRACE_METADATA, ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE);
502 }
503
504 /**
505 * <p>
506 * Action : Recursive import with auto-detection (Rename All)
507 * <p>
508 *
509 * <pre>
510 * Procedure : 1) Open Import wizard (see 3.1-3.2)
511 * 2) Browse to directory ${local}/traces/import
512 * 3) select directory import
513 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
514 * 5) press Finish
515 * 6) When dialog appears select "Rename All"
516 * </pre>
517 * <p>
518 * Expected Results: All Traces are imported with respective trace type set.
519 * Traces with name clashes are imported with suffix (2). 1 trace
520 * (unrecognized.log) is imported with trace type unknown. Make sure that
521 * traces can be opened which have a trace type set. The unknown trace type
522 * should open with the text editor.
523 */
524 @Test
525 public void test3_13ImportRecursiveAutoRenameAll() {
526 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
527
528 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
529 importTrace(optionFlags, ImportConfirmation.RENAME_ALL, "");
530
531 for (TestTraceInfo info : ALL_TRACEINFOS) {
532 String traceName = info.getTraceName();
533 if (CLASHING_TRACEINFOS.contains(info)) {
534 traceName = toRenamedName(traceName);
535 }
536 verifyTrace(info, optionFlags, traceName);
537 }
538
539 // Also check unrecognized file
540 verifyTrace(UNRECOGNIZED_LOG, optionFlags);
541 }
542
543 /**
544 * <p>
545 * Action : Recursive import with auto-detection (Overwrite All)
546 * <p>
547 *
548 * <pre>
549 * Procedure : 1) Open Import wizard (see 3.1-3.2)
550 * 2) Browse to directory ${local}/traces/import/
551 * 3) select directory import
552 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
553 * 5) press Finish
554 * 6) When dialog appears select Overwrite All"
555 * </pre>
556 * <p>
557 * Expected Results: All Traces are imported with respective trace type set.
558 * Traces with name clashes are overwritten . 1 trace (unrecognized.log) is
559 * imported with trace type unknown. Make sure that traces can be opened
560 * which have a trace type set. The unknown trace type should open with the
561 * text editor.
562 */
563 @Test
564 public void test3_14ImportRecursiveAutoOverwriteAll() {
565 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
566
567 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
568 importTrace(optionFlags, ImportConfirmation.OVERWRITE_ALL, "");
569
570 for (TestTraceInfo info : CLASHING_TRACEINFOS) {
571 verifyTrace(info, optionFlags);
572 }
573
574 // All traces should have clashed/overwritten (plus the unrecognized trace)
575 SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
576 assertEquals(NUM_UNIQUE_TRACES, tracesFolderItem.getItems().length);
577
578 // Also check unrecognized file
579 verifyTrace(UNRECOGNIZED_LOG, optionFlags);
580 }
581
582 /**
583 * <p>
584 * Action : Recursive import with auto-detection (Skip All)
585 * <p>
586 *
587 * <pre>
588 * Procedure : 1) Open Import wizard (see 3.1-3.2)
589 * 2) Browse to directory ${local}/traces/import/
590 * 3) select directory import
591 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning" and select "Create Links to workspace" and uncheck "preserve folder structure"
592 * 5) press Finish
593 * 6) When dialog appears select Skip All"
594 * </pre>
595 * <p>
596 * Expected Results: All Traces are imported with respective trace type set. Traces with name
597 * clashes are not imported. 1 trace (unrecognized.log) is imported with
598 * trace type unknown. The unknown trace type should open with the text
599 * editor.
600 */
601 @Test
602 public void test3_15ImportRecursiveAutoSkipAll() {
603 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
604
605 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
606 importTrace(optionFlags, ImportConfirmation.SKIP_ALL, "");
607
608 SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
609 for (TestTraceInfo info : ALL_TRACEINFOS) {
610 if (!CLASHING_TRACEINFOS.contains(info)) {
611 verifyTrace(info, optionFlags);
612 }
613 }
614
615 // All traces should have skipped (plus the unrecognized trace)
616 assertEquals(NUM_UNIQUE_TRACES, tracesFolderItem.getItems().length);
617
618 // Also check unrecognized file
619 verifyTrace(UNRECOGNIZED_LOG, optionFlags);
620 }
621
622 /**
623 * <p>
624 * Action : Recursive import with auto-detection (test rename, overwrite and
625 * skip)
626 * <p>
627 *
628 * <pre>
629 * Procedure : 1) Open Import wizard (see 3.1-3.2)
630 * 2) Browse to directory ${local}/traces/import/
631 * 3) select directory import
632 * 4) Keep <Auto Detection>, Select "Import unrecognized traces", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
633 * 5) press Finish
634 * 6) When dialog appears select "Rename"
635 * 7) When dialog appears select "Overwrite"
636 * 8) When dialog appears select "Skip"
637 * </pre>
638 * <p>
639 * Expected Results: All Traces are imported with respective trace type set. Traces with name
640 * clashes are either renamed, overwritten or skipped as per dialog action.
641 * Make sure that traces can be opened which have trace type set. The
642 * unknown trace type should open with the text editor.
643 */
644 @Test
645 public void test3_16ImportRecursiveAutoRenameOverwriteSkip() {
646 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
647
648 Supplier<ImportConfirmation> confirmationSupplier = new Supplier<ImportConfirmation>() {
649 final ImportConfirmation dialogConfirmationOrder[] = new ImportConfirmation[] { ImportConfirmation.RENAME, ImportConfirmation.OVERWRITE, ImportConfirmation.SKIP };
650 int fRsponseNum = 0;
651
652 @Override
653 public ImportConfirmation get() {
654 if (fRsponseNum >= dialogConfirmationOrder.length) {
655 return null;
656 }
657
658 ImportConfirmation confirmation = dialogConfirmationOrder[fRsponseNum];
659 fRsponseNum++;
660 return confirmation;
661 }
662 };
663 int optionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
664 importTrace(optionFlags, confirmationSupplier, LTTNG_KERNEL_TRACE.getTracePath(), CLASHES_LTTNG_KERNEL_TRACE.getTracePath(), SIMPLE_SERVER1_UST_TRACE.getTracePath(), CLASHES_SIMPLE_SERVER1_UST_TRACE.getTracePath(),
665 SIMPLE_SERVER2_UST_TRACE.getTracePath(), CLASHES_SIMPLE_SERVER2_UST_TRACE.getTracePath(), UNRECOGNIZED_LOG.getTracePath());
666
667 verifyTrace(LTTNG_KERNEL_TRACE, optionFlags);
668
669 // Renamed trace
670 String renamed = toRenamedName(CLASHES_LTTNG_KERNEL_TRACE.getTraceName());
671 verifyTrace(CLASHES_LTTNG_KERNEL_TRACE, optionFlags, renamed);
672
673 // Overwritten trace
674 verifyTrace(CLASHES_SIMPLE_SERVER1_UST_TRACE, optionFlags);
675
676 // Skipped trace
677 verifyTrace(SIMPLE_SERVER2_UST_TRACE, optionFlags);
678
679 // Also check unrecognized file
680 verifyTrace(UNRECOGNIZED_LOG, optionFlags);
681 }
682
683 /**
684 * <p>
685 * Action : Recursive import with specific trace type 1 (Skip All) skip)
686 * <p>
687 *
688 * <pre>
689 * Procedure : 1) Open Import wizard
690 * 2) Browse to directory ${local}/traces/import/
691 * 3) Select directory import
692 * 4) Select trace type "Generic CTF Trace", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"and
693 * 5) press Finish
694 * 6) When dialog appears select Skip All"
695 * </pre>
696 * <p>
697 * Expected Results: After selecting trace type, verify that button "Import
698 * unrecognized traces" is disabled. 4 CTF traces are imported with trace
699 * type "Generic CTF Trace" . Make sure that these traces can be opened
700 */
701 @Test
702 public void test3_17ImportRecursiveSpecityTraceTypeCTF() {
703 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
704
705 int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
706 importTrace(GENERIC_CTF_TRACE_TYPE, optionFlags, ImportConfirmation.SKIP_ALL, "");
707
708 final TestTraceInfo[] CTF_TRACEINFOS = new TestTraceInfo[] {
709 LTTNG_KERNEL_TRACE,
710 SIMPLE_SERVER1_UST_TRACE,
711 SIMPLE_SERVER2_UST_TRACE,
712 UST_OVERLAP_TESTING_UST_TRACE
713 };
714 for (TestTraceInfo info : CTF_TRACEINFOS) {
715 verifyTrace(info, optionFlags, info.getTraceName(), GENERIC_CTF_TRACE_TYPE);
716 }
717
718 SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
719 assertEquals(CTF_TRACEINFOS.length, tracesFolderItem.getItems().length);
720 }
721
722 /**
723 * <p>
724 * Action : Recursive import with specific trace type 2 (Skip All)
725 * <p>
726 *
727 * <pre>
728 * Procedure : 1) Open Import wizard (see 3.1-3.2)
729 * 2) Browse to directory ${local}/traces/import/
730 * 3) Select directory import
731 * 4) Select trace type "LTTng Kernel Trace", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
732 * 5) Press Finish
733 * 6) When dialog appears select Skip All"
734 * </pre>
735 * <p>
736 * Expected Results: After selecting trace type, verify that button "Import
737 * unrecognized traces" is disabled. One LTTng Kernel trace is imported with
738 * trace type "LTTng Kernel Trace". Make sure that this trace can be opened.
739 */
740 @Test
741 public void test3_18ImportRecursiveSpecityTraceTypeKernel() {
742 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
743
744 int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
745 importTrace(LTTNG_KERNEL_TRACE_TYPE, optionFlags, ImportConfirmation.SKIP_ALL, "");
746
747 verifyTrace(LTTNG_KERNEL_TRACE, optionFlags);
748
749 SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
750 assertEquals(1, tracesFolderItem.getItems().length);
751 }
752
753 /**
754 * <p>
755 * Action : Recursive import with specific trace type 3 (Skip All)
756 * <p>
757 *
758 * <pre>
759 * Procedure : 1) Open Import wizard
760 * 2) Browse to directory ${local}/traces/import/
761 * 3) Select directory import
762 * 4) Select trace type "LTTng UST Trace", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
763 * 5) Press Finish
764 * 6) When dialog appears select Skip All"
765 * </pre>
766 * <p>
767 * Expected Results: After selecting trace type, verify that button "Import
768 * unrecognized traces" is disabled. 3 LTTng UST traces are imported with
769 * trace type "LTTng UST Trace". Make sure that these traces can be opened.
770 */
771 @Test
772 public void test3_19ImportRecursiveSpecityTraceTypeUST() {
773 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
774
775 int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
776 importTrace(LTTNG_UST_TRACE_TYPE, optionFlags, ImportConfirmation.SKIP_ALL, "");
777
778 final TestTraceInfo[] UST_TRACEINFOS = new TestTraceInfo[] {
779 SIMPLE_SERVER1_UST_TRACE,
780 SIMPLE_SERVER2_UST_TRACE,
781 UST_OVERLAP_TESTING_UST_TRACE
782 };
783 for (TestTraceInfo info : UST_TRACEINFOS) {
784 verifyTrace(info, optionFlags);
785 }
786
787 SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
788 assertEquals(UST_TRACEINFOS.length, tracesFolderItem.getItems().length);
789 }
790
791 /**
792 * <p>
793 * Action : Recursive import with specific trace type 4 (Skip All)
794 * <p>
795 *
796 * <pre>
797 * Procedure : 1) Open Import wizard (see 3.1-3.2)
798 * 2) Browse to directory ${local}/traces/import/
799 * 3) select directory import
800 * 4) Select trace type "Tmf Generic", unselect "Overwrite existing without warning", select "Create Links to workspace" and unselect "Preserve Folder Structure"
801 * 5) press Finish
802 * 6) When dialog appears select Skip All"
803 * </pre>
804 * <p>
805 * Expected Results: All text files in directories are imported as trace and
806 * trace type "Tmf Generic" is set. Note that trace type validation only
807 * checks for file exists and that file is not a directory. Make sure that
808 * these traces can be opened. However traces with wrong trace type won't
809 * show any events in the table.
810 */
811 @Test
812 public void test3_20ImportRecursiveSpecityTraceTypeCustomText() {
813 SWTBotUtils.clearTracesFolderUI(fBot, TRACE_PROJECT_NAME);
814
815 int optionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
816 importTrace(CUSTOM_TEXT_TRACE_TYPE, optionFlags, ImportConfirmation.SKIP_ALL, "");
817 verifyTrace(CUSTOM_TEXT_LOG, optionFlags);
818
819 final TestTraceInfo[] TEXT_BASED_TRACEINFOS = new TestTraceInfo[] {
820 CUSTOM_TEXT_LOG,
821 CUSTOM_XML_LOG_AS_TEXT,
822 UNRECOGNIZED_LOG
823 };
824 for (TestTraceInfo info : TEXT_BASED_TRACEINFOS) {
825 verifyTrace(info, optionFlags, info.getTraceName(), CUSTOM_TEXT_TRACE_TYPE);
826 }
827
828 SWTBotTreeItem tracesFolderItem = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
829 assertEquals(TEXT_BASED_TRACEINFOS.length, tracesFolderItem.getItems().length);
830 }
831
832 private static void verifyTrace(TestTraceInfo traceInfo, int importOptionFlags) {
833 verifyTrace(traceInfo, importOptionFlags, traceInfo.getTraceName());
834 }
835
836 private static void verifyTrace(TestTraceInfo traceInfo, int importOptionFlags, String traceName) {
837 verifyTrace(traceInfo, importOptionFlags, traceName, traceInfo.getTraceType());
838 }
839
840 private static void verifyTrace(TestTraceInfo traceInfo, int importOptionFlags, String traceName, String traceType) {
841 SWTBotTreeItem traceItem = SWTBotUtils.getTreeItem(fBot, SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME), traceName);
842 checkTraceType(traceItem, traceType);
843 openTrace(traceItem);
844 if (traceType != null && !traceType.isEmpty()) {
845 SWTBotImportWizardUtils.testEventsTable(fBot, traceName, traceInfo.getNbEvents(), traceInfo.getFirstEventTimestamp());
846 } else {
847 // If there is no trace type, make sure it can be opened with the text editor
848 fBot.waitUntil(ConditionHelpers.isEditorOpened(fBot, traceName));
849 SWTBotEditor editor = fBot.editorByTitle(traceName);
850 assertEquals(TEXT_EDITOR_ID, editor.getReference().getId());
851 }
852 checkTraceLinked(traceItem, (importOptionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0);
853 }
854
855 private static String toRenamedName(String traceName) {
856 return traceName + "(2)";
857 }
858
859 private static void openTrace(SWTBotTreeItem traceItem) {
860 traceItem.select();
861 traceItem.doubleClick();
862 }
863
864 private static void testSingleTrace(TestTraceInfo traceInfo, int optionFlags) {
865 importTrace(optionFlags, traceInfo.getTracePath());
866 verifyTrace(traceInfo, optionFlags);
867 }
868
869 private static void importTrace(int optionFlags, String ... tracePaths) {
870 importTrace(optionFlags, ImportConfirmation.CONTINUE, tracePaths);
871 }
872
873 private static void importTrace(int optionFlags, ImportConfirmation confirmationMode, String ... tracePaths) {
874 importTrace(null, optionFlags, confirmationMode, tracePaths);
875 }
876
877 private static void importTrace(String traceType, int optionFlags, ImportConfirmation confirmationMode, String ... tracePaths) {
878 importTrace(traceType, optionFlags, new Supplier<ImportConfirmation>() {
879 boolean fDone = false;
880 @Override
881 public ImportConfirmation get() {
882 if (fDone) {
883 return null;
884 }
885 fDone = true;
886 return confirmationMode;
887 }
888 }, tracePaths);
889 }
890
891 private static void importTrace(int optionFlags, Supplier<ImportConfirmation> confirmationSuplier, String ... tracePaths) {
892 importTrace(null, optionFlags, confirmationSuplier, tracePaths);
893 }
894
895 /**
896 * @param tracePath relative to parent test traces folder
897 */
898 private static void importTrace(String traceType, int optionFlags, Supplier<ImportConfirmation> confirmationSuplier, String ... tracePaths) {
899 SWTBotTreeItem traceFolder = SWTBotUtils.selectTracesFolder(fBot, TRACE_PROJECT_NAME);
900
901 SWTBotShell shell = openTraceFoldersImport(traceFolder);
902 SWTBot bot = shell.bot();
903 final String importDirectoryRelativePath = "import";
904 String importDirectoryFullPath = getPath(importDirectoryRelativePath);
905
906 for (String tracePath : tracePaths) {
907 IPath somePath = new Path(importDirectoryRelativePath).append(tracePath);
908 IPath fullParentPath = somePath.removeLastSegments(1);
909 boolean isDirectory = new Path(importDirectoryFullPath).append(tracePath).toFile().isDirectory();
910
911 SWTBotImportWizardUtils.selectImportFromDirectory(bot, importDirectoryFullPath);
912 if (isDirectory) {
913 SWTBotImportWizardUtils.selectFolder(fBot, true, somePath.segments());
914 } else {
915 SWTBotImportWizardUtils.selectFile(bot, new Path(tracePath).lastSegment(), fullParentPath.segments());
916 }
917 }
918
919 SWTBotImportWizardUtils.setOptions(bot, optionFlags, traceType);
920 bot.button("Finish").click();
921
922 ImportConfirmation importConfirmation = confirmationSuplier.get();
923 while (importConfirmation != null) {
924 if (importConfirmation != ImportConfirmation.CONTINUE) {
925 fBot.waitUntil(Conditions.shellIsActive("Confirmation"));
926 SWTBotShell shell2 = fBot.activeShell();
927 SWTBotButton button = shell2.bot().button(importConfirmation.getInName());
928 button.click();
929 }
930 importConfirmation = confirmationSuplier.get();
931 }
932
933 fBot.waitUntil(Conditions.shellCloses(shell));
934 }
935
936 private static void checkTraceType(SWTBotTreeItem traceItem, String traceType) {
937 assertEquals(traceType, getTraceProperty(traceItem, "type"));
938 }
939
940 private static void checkTraceLinked(SWTBotTreeItem traceItem, boolean linked) {
941 assertEquals(Boolean.toString(linked), getTraceProperty(traceItem, "linked"));
942 }
943
944 private static String getTraceProperty(SWTBotTreeItem traceItem, String property) {
945 SWTBotUtils.openView(IPageLayout.ID_PROP_SHEET);
946 SWTBotView view = fBot.viewById(IPageLayout.ID_PROP_SHEET);
947 view.show();
948 traceItem.select();
949 SWTBotTreeItem traceTypeItem = SWTBotUtils.getTreeItem(view.bot(), view.bot().tree(), "Resource properties", property);
950 return traceTypeItem.cell(1);
951 }
952
953 private static SWTBotShell openTraceFoldersImport(SWTBotTreeItem traceItem) {
954 traceItem.contextMenu().menu("Import...").click();
955 fBot.waitUntil(Conditions.shellIsActive("Trace Import"));
956
957 SWTBotShell shell = fBot.shell("Trace Import");
958 return shell;
959 }
960 }
This page took 0.090101 seconds and 5 git commands to generate.