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