tmf: Bug 494689: fix failing name conflict handling in trace import
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / StandardImportAndReadSmokeTest.java
CommitLineData
2f7b3dd7 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 Ericsson
2f7b3dd7
BH
3 *
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
8 *
9 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
bbdb3d6d 11 * Marc-Andre Laperle - Added tests for extracting archives during import
2f7b3dd7
BH
12 *******************************************************************************/
13
2bdf0193 14package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
2f7b3dd7 15
fa74050c 16import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.withMnemonic;
40ba27e1 17import static org.eclipse.tracecompass.common.core.NonNullUtils.checkNotNull;
9b3f4afe
MAL
18import static org.junit.Assert.assertEquals;
19import static org.junit.Assert.assertFalse;
2f7b3dd7 20import static org.junit.Assert.assertNotNull;
9b3f4afe 21import static org.junit.Assert.assertTrue;
2f7b3dd7 22
fc4a373f 23import java.io.ByteArrayInputStream;
93c91230 24import java.io.File;
bbdb3d6d
MAL
25import java.io.IOException;
26import java.net.URISyntaxException;
29fe7911
MAL
27import java.nio.file.Files;
28import java.nio.file.Paths;
9b3f4afe
MAL
29import java.util.Collections;
30import java.util.Comparator;
31import java.util.List;
32
d34c9ed8 33import org.eclipse.core.resources.IFile;
bbdb3d6d 34import org.eclipse.core.resources.IFolder;
9b3f4afe
MAL
35import org.eclipse.core.resources.IProject;
36import org.eclipse.core.resources.IResource;
37import org.eclipse.core.resources.ResourcesPlugin;
bbdb3d6d 38import org.eclipse.core.runtime.CoreException;
9b3f4afe 39import org.eclipse.core.runtime.IPath;
93c91230 40import org.eclipse.core.runtime.Path;
bbdb3d6d 41import org.eclipse.core.runtime.URIUtil;
40ba27e1 42import org.eclipse.jdt.annotation.NonNull;
2f7b3dd7
BH
43import org.eclipse.jface.viewers.StructuredSelection;
44import org.eclipse.jface.wizard.WizardDialog;
2f7b3dd7
BH
45import org.eclipse.swt.widgets.Shell;
46import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
47import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
48import org.eclipse.swtbot.swt.finder.results.VoidResult;
49import org.eclipse.swtbot.swt.finder.waits.Conditions;
9b3f4afe 50import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
2f7b3dd7 51import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
93c91230 52import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
bbdb3d6d
MAL
53import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
54import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
55import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
2f7b3dd7
BH
56import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
57import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
58import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
fa74050c 59import org.eclipse.swtbot.swt.finder.widgets.TimeoutException;
c47c8803 60import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportConfirmation;
2bdf0193
AM
61import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
62import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
63import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
bbdb3d6d 64import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
2bdf0193 65import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
40ba27e1
BH
66import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement;
67import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder;
2bdf0193
AM
68import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
69import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
70import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
71import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder;
72import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder;
fa24d78b
AM
73import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
74import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
2f7b3dd7
BH
75import org.eclipse.ui.IWorkbench;
76import org.eclipse.ui.IWorkbenchWindow;
77import org.eclipse.ui.PlatformUI;
29fe7911
MAL
78import org.junit.AfterClass;
79import org.junit.BeforeClass;
2f7b3dd7
BH
80import org.junit.Test;
81import org.junit.runner.RunWith;
82
83/**
84 * SWTBot Smoke test using ImportTraceWizard.
85 *
86 * @author Bernd Hufmann
87 */
88@RunWith(SWTBotJunit4ClassRunner.class)
89public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
90
c4d57ac1 91 private static final String TRACE_FOLDER_PARENT_PATH = "../../ctf/org.eclipse.tracecompass.ctf.core.tests/traces/";
bbdb3d6d 92 private static final String ARCHIVE_FILE_NAME = "synctraces.tar.gz";
d34c9ed8 93 private static final String EMPTY_ARCHIVE_FOLDER = "emptyArchiveFolder";
fc4a373f 94 private static final String EMPTY_FILE_NAME = "emptyFile";
bbdb3d6d
MAL
95 private static final String TRACE_ARCHIVE_PATH = TRACE_FOLDER_PARENT_PATH + ARCHIVE_FILE_NAME;
96 private static final String TRACE_FOLDER_PARENT_NAME = "traces";
2f7b3dd7
BH
97 private static final String TRACE_PROJECT_NAME = "Tracing";
98
bbdb3d6d
MAL
99 private static final String ARCHIVE_ROOT_ELEMENT_NAME = "/";
100 private static final String GENERATED_ARCHIVE_NAME = "testtraces.zip";
101 private static final String URI_SEPARATOR = "/";
102 private static final String URI_FILE_SCHEME = "file:";
103 private static final String URI_JAR_FILE_SCHEME = "jar:file:";
104 private static final boolean IS_WIN32 = System.getProperty("os.name").startsWith("Windows"); //$NON-NLS-1$//$NON-NLS-2$
105 private static final String URI_DEVICE_SEPARATOR = IS_WIN32 ? URI_SEPARATOR : "";
106
29fe7911
MAL
107 /** Test Class setup */
108 @BeforeClass
109 public static void beforeClass() {
110 createProject(TRACE_PROJECT_NAME);
111 }
112
113 /** Test Class tear down */
114 @AfterClass
115 public static void afterClass() {
116 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
117 }
118
2f7b3dd7 119 /**
9b3f4afe 120 * Test import from directory
bbdb3d6d
MAL
121 *
122 * @throws Exception
123 * on error
2f7b3dd7
BH
124 */
125 @Test
bbdb3d6d 126 public void testImportFromDirectory() throws Exception {
9b3f4afe
MAL
127 testImport(0, false, false);
128 }
2f7b3dd7 129
9b3f4afe
MAL
130 /**
131 * Test import from directory, create links
bbdb3d6d
MAL
132 *
133 * @throws Exception
134 * on error
9b3f4afe
MAL
135 */
136 @Test
bbdb3d6d 137 public void testImportFromDirectoryLinks() throws Exception {
9b3f4afe
MAL
138 testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false);
139 }
2f7b3dd7 140
40ba27e1
BH
141 /**
142 * Test import from directory, create experiment
143 *
144 * @throws Exception
145 * on error
146 */
147 @Test
148 public void testImportWithExperiment() throws Exception {
149 testImport(ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, false);
150 }
151
152 /**
153 * Test import from directory, create experiment (validate experiment name)
154 *
155 * @throws Exception
156 * on error
157 */
158 @Test
159 public void testImportWithExperimentValidation() throws Exception {
c47c8803 160 testImport(ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, false, false, true, ImportConfirmation.CONTINUE);
40ba27e1
BH
161 }
162
9b3f4afe
MAL
163 /**
164 * Test import from directory, preserve folder structure
bbdb3d6d
MAL
165 *
166 * @throws Exception
167 * on error
9b3f4afe
MAL
168 */
169 @Test
bbdb3d6d 170 public void testImportFromDirectoryPreserveFolder() throws Exception {
9b3f4afe
MAL
171 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, false);
172 }
2f7b3dd7 173
9b3f4afe
MAL
174 /**
175 * Test import from directory, create links, preserve folder structure
bbdb3d6d
MAL
176 *
177 * @throws Exception
178 * on error
9b3f4afe
MAL
179 */
180 @Test
bbdb3d6d 181 public void testImportFromDirectoryLinksPreserveFolder() throws Exception {
9b3f4afe
MAL
182 int options = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
183 testImport(options, false, false);
184 }
93c91230 185
9b3f4afe
MAL
186 /**
187 * Test import from directory, overwrite all
bbdb3d6d
MAL
188 *
189 * @throws Exception
190 * on error
9b3f4afe
MAL
191 */
192 @Test
bbdb3d6d 193 public void testImportFromDirectoryOverwrite() throws Exception {
c47c8803 194 testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
9b3f4afe 195 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
93c91230
MAL
196 }
197
c47c8803
BH
198 /**
199 * Test import from directory, overwrite all
200 *
201 * @throws Exception
202 * on error
203 */
204 @Test
205 public void testImportFromDirectoryOverwriteRenameAll() throws Exception {
206 testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
207 testImport(0, false, false, true, true, ImportConfirmation.RENAME_ALL);
208 }
209
210 /**
211 * Test import from directory, overwrite all
212 *
213 * @throws Exception
214 * on error
215 */
216 @Test
217 public void testImportFromDirectoryOverwriteOverwriteAll() throws Exception {
218 testImport(0, false, false, true, false, ImportConfirmation.CONTINUE);
219 testImport(0, false, false, true, true, ImportConfirmation.OVERWRITE_ALL);
220 }
221
93c91230
MAL
222 /**
223 * Test import from archive
bbdb3d6d
MAL
224 *
225 * @throws Exception
226 * on error
93c91230
MAL
227 */
228 @Test
bbdb3d6d 229 public void testImportFromArchive() throws Exception {
9b3f4afe
MAL
230 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true);
231 }
232
40ba27e1
BH
233 /**
234 * Test import from archive, create Experiment
235 *
236 * @throws Exception
237 * on error
238 */
239 @Test
240 public void testImportFromArchiveWithExperiment() throws Exception {
241 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE | ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT, false, true);
242 }
243
9b3f4afe
MAL
244 /**
245 * Test import from directory, preserve folder structure
bbdb3d6d 246 * @throws Exception on error
9b3f4afe
MAL
247 */
248 @Test
bbdb3d6d 249 public void testImportFromArchivePreserveFolder() throws Exception {
9b3f4afe
MAL
250 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
251 }
252
253 /**
254 * Test import from directory, overwrite all
bbdb3d6d
MAL
255 *
256 * @throws Exception
257 * on error
9b3f4afe
MAL
258 */
259 @Test
bbdb3d6d 260 public void testImportFromArchiveOverwrite() throws Exception {
c47c8803 261 testImport(0, false, true, true, false, ImportConfirmation.CONTINUE);
9b3f4afe
MAL
262 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
263 }
264
bbdb3d6d
MAL
265 /**
266 * Test import from directory containing archives
267 *
268 * @throws Exception
269 * on error
270 */
271 @Test
272 public void testExtractArchivesFromDirectory() throws Exception {
29fe7911 273 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
bbdb3d6d
MAL
274 }
275
276 /**
277 * Test import from directory containing archives, create links
278 * @throws Exception on error
279 */
280 @Test
281 public void testExtractArchivesFromDirectoryLinks() throws Exception {
29fe7911 282 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
bbdb3d6d
MAL
283 }
284
285 /**
286 * Test import from directory containing archives, create links, preserve folder structure
287 * @throws Exception on error
288 */
289 @Test
290 public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception {
29fe7911 291 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, false);
bbdb3d6d 292 }
93c91230 293
bbdb3d6d
MAL
294 /**
295 * Test import from archive containing archives
296 *
297 * @throws Exception
298 * on error
299 */
300 @Test
301 public void testExtractArchivesFromArchive() throws Exception {
29fe7911 302 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
bbdb3d6d
MAL
303 }
304
305 /**
306 * Test import from archive containing archives, preserve folder structure
307 *
308 * @throws Exception
309 * on error
310 */
311 @Test
312 public void testExtractArchivesFromArchivePreserveFolder() throws Exception {
29fe7911 313 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
bbdb3d6d
MAL
314 }
315
d34c9ed8
PT
316 /**
317 * Test import from an empty archive. This should not import anything.
318 *
319 * @throws Exception
320 * on error
321 */
322 @Test
323 public void testEmptyArchive() throws Exception {
d34c9ed8
PT
324 String testArchivePath = createEmptyArchive();
325
326 openImportWizard();
327 selectImportFromArchive(testArchivePath);
328 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
329 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
330 importFinish();
331
332 assertNoTraces();
333
29fe7911
MAL
334 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
335 Files.delete(Paths.get(testArchivePath));
d34c9ed8
PT
336 }
337
338 /**
339 * Test import from an empty directory. This should not import anything.
340 *
341 * @throws Exception
342 * on error
343 */
344 @Test
345 public void testEmptyDirectory() throws Exception {
29fe7911
MAL
346 IFolder emptyDirectory = createEmptyDirectory();
347 String testDirectoryPath = emptyDirectory.getLocation().toOSString();
d34c9ed8
PT
348
349 openImportWizard();
350 selectImportFromDirectory(testDirectoryPath);
351 selectFolder(EMPTY_ARCHIVE_FOLDER);
352 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
353 importFinish();
354
355 assertNoTraces();
356
29fe7911
MAL
357 Files.delete(Paths.get(testDirectoryPath));
358 emptyDirectory.delete(true, null);
359 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
d34c9ed8
PT
360 }
361
fc4a373f
BH
362 /**
363 * Test import from an directory with an empty file. This should not import anything.
364 *
365 * @throws Exception
366 * on error
367 */
368 @Test
369 public void testEmptyFile() throws Exception {
fc4a373f
BH
370 IFolder folder = createEmptyDirectory();
371 createEmptyFile(folder);
372 String testDirectoryPath = folder.getLocation().toOSString();
373 openImportWizard();
374 selectImportFromDirectory(testDirectoryPath);
375 selectFile(EMPTY_FILE_NAME, EMPTY_ARCHIVE_FOLDER);
376 setOptions(ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
377 importFinish();
378
379 assertNoTraces();
380
29fe7911
MAL
381 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
382 folder.delete(true, null);
fc4a373f
BH
383 }
384
d34c9ed8
PT
385 /**
386 * Test import from a directory containing an empty archive. This should not import anything.
387 *
388 * @throws Exception
389 * on error
390 */
391 @Test
392 public void testDirectoryWithEmptyArchive() throws Exception {
29fe7911 393 String testArchivePath = createEmptyArchive();
d34c9ed8
PT
394
395 openImportWizard();
396 selectImportFromDirectory(getProjectResource().getLocation().toOSString());
29fe7911 397 selectFile(GENERATED_ARCHIVE_NAME, TRACE_PROJECT_NAME);
d34c9ed8
PT
398 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
399 importFinish();
400
401 assertNoTraces();
402
29fe7911
MAL
403 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
404 Files.delete(Paths.get(testArchivePath));
d34c9ed8
PT
405 }
406
407 /**
408 * Test import from a nested empty archive. This should not import anything.
409 *
410 * @throws Exception
411 * on error
412 */
413 @Test
414 public void testNestedEmptyArchive() throws Exception {
d34c9ed8
PT
415 IProject project = getProjectResource();
416
417 // Create the empty archive from an empty folder
418 String testArchivePath = createEmptyArchive();
419
420 // Rename archive so that we can create a new one with the same name
421 project.refreshLocal(IResource.DEPTH_ONE, null);
422 IFile[] files = project.getWorkspace().getRoot().findFilesForLocationURI(new File(testArchivePath).toURI());
423 IFile archiveFile = files[0];
424 String newEmptyArchiveName = "nested" + archiveFile.getName();
425 IPath dest = archiveFile.getFullPath().removeLastSegments(1).append(newEmptyArchiveName);
426 archiveFile.move(dest, true, null);
427 IFile renamedArchiveFile = archiveFile.getWorkspace().getRoot().getFile(dest);
428
429 createArchive(renamedArchiveFile);
29fe7911 430 renamedArchiveFile.delete(true, null);
d34c9ed8
PT
431
432 openImportWizard();
433 selectImportFromArchive(testArchivePath);
434 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
435 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
436 importFinish();
437
438 assertNoTraces();
439
29fe7911
MAL
440 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
441 Files.delete(Paths.get(testArchivePath));
d34c9ed8
PT
442 }
443
29fe7911 444 private static void assertNoTraces() {
d34c9ed8
PT
445 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
446 assertNotNull(tmfProject);
447 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
448 assertNotNull(tracesFolder);
449 List<TmfTraceElement> traces = tracesFolder.getTraces();
450 assertTrue(traces.isEmpty());
451 }
452
bbdb3d6d 453 private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception {
c47c8803 454 testImport(options, testViews, fromArchive, true, true, ImportConfirmation.CONTINUE);
40ba27e1
BH
455 }
456
c47c8803 457 private void testImport(int options, boolean testViews, boolean fromArchive, boolean defaultExperiment, boolean clearTraces, ImportConfirmation confirmationMode) throws Exception {
bbdb3d6d 458 String expectedSourceLocation = null;
40ba27e1
BH
459
460 @NonNull String experimentName;
461 if (fromArchive) {
462 experimentName = checkNotNull(new Path(ARCHIVE_FILE_NAME).lastSegment());
463 } else {
464 experimentName = checkNotNull(new Path(TRACE_FOLDER_PARENT_PATH).lastSegment());
465 }
466
467 if (!defaultExperiment) {
468 SWTBotUtils.createExperiment(fBot, TRACE_PROJECT_NAME, experimentName);
469 }
470
bbdb3d6d 471 openImportWizard();
9b3f4afe 472 if (fromArchive) {
bbdb3d6d
MAL
473 expectedSourceLocation = URI_JAR_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(TRACE_ARCHIVE_PATH).getCanonicalPath()) + "!" + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
474 selectImportFromArchive(TRACE_ARCHIVE_PATH);
475 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
476 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
477 assertFalse(checkBox.isEnabled());
9b3f4afe 478 } else {
bbdb3d6d
MAL
479 String sourcePath = TRACE_FOLDER_PARENT_PATH + File.separator + TRACE_FOLDER + File.separator + TRACE_NAME;
480 expectedSourceLocation = URI_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(sourcePath).getCanonicalPath()) + URI_SEPARATOR;
481 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
482 selectFolder(new String [] {TRACE_FOLDER_PARENT_NAME, TRACE_FOLDER });
9b3f4afe 483 }
93c91230 484
9b3f4afe 485 setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
40ba27e1
BH
486
487 if (!defaultExperiment) {
488 experimentName = verifyExperimentNameHandling(experimentName);
489 }
490 checkFinishButton(true);
491
c47c8803 492 importFinish(confirmationMode);
93c91230 493
bbdb3d6d
MAL
494 IPath expectedElementPath = new Path(TRACE_NAME);
495 if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
496 expectedElementPath = new Path(TRACE_FOLDER).append(expectedElementPath);
497 }
498
c47c8803
BH
499 if (confirmationMode == ImportConfirmation.RENAME_ALL) {
500 IPath expectedElementPathRenamed = new Path(TRACE_NAME + "(2)");
501 checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName, expectedElementPathRenamed);
502 } else {
503 checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName, null);
504 }
505
29fe7911 506 TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
9b3f4afe
MAL
507 if (testViews) {
508 testViews(tmfEd);
509 }
93c91230 510
93c91230
MAL
511 fBot.closeAllEditors();
512
40ba27e1 513 SWTBotUtils.clearExperimentFolder(fBot, TRACE_PROJECT_NAME);
c47c8803
BH
514 if (clearTraces) {
515 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
516 }
93c91230
MAL
517 }
518
29fe7911 519 private void testImportAndExtractArchives(int options, boolean testViews, boolean fromArchive) throws Exception {
bbdb3d6d
MAL
520 String expectedSourceLocation;
521 IPath expectedElementPath;
29fe7911 522 String testArchivePath = null;
bbdb3d6d 523 if (fromArchive) {
29fe7911 524 testArchivePath = createNestedArchive();
bbdb3d6d
MAL
525 openImportWizard();
526 selectImportFromArchive(testArchivePath);
527 selectFile(ARCHIVE_FILE_NAME, ARCHIVE_ROOT_ELEMENT_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME);
528
529 expectedSourceLocation = URI_JAR_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(testArchivePath).getCanonicalPath()) + "!" + URI_SEPARATOR + TRACE_PROJECT_NAME + URI_SEPARATOR + TRACE_FOLDER_PARENT_NAME + URI_SEPARATOR + ARCHIVE_FILE_NAME
530 + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
531 expectedElementPath = new Path(TRACE_PROJECT_NAME).append(TRACE_FOLDER_PARENT_NAME).append(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
532 } else {
533 openImportWizard();
534 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
535 selectFile(ARCHIVE_FILE_NAME, TRACE_FOLDER_PARENT_NAME);
536 expectedElementPath = new Path(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
537 expectedSourceLocation = URI_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(TRACE_FOLDER_PARENT_PATH).getCanonicalPath()) + URI_SEPARATOR + ARCHIVE_FILE_NAME + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
538 }
539
540 if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) == 0) {
541 expectedElementPath = new Path(TRACE_NAME);
542 }
543
544 setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
545 importFinish();
546 // Archives should never be imported as links
547 int expectedOptions = options & ~ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
548 checkOptions(expectedOptions, expectedSourceLocation, expectedElementPath);
549
550 TmfEventsEditor editor = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
29fe7911
MAL
551 if (testViews) {
552 testViews(editor);
553 }
bbdb3d6d 554
40ba27e1
BH
555 SWTBotUtils.clearExperimentFolder(fBot, TRACE_PROJECT_NAME);
556
29fe7911
MAL
557 SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME);
558 if (testArchivePath != null) {
559 Files.delete(Paths.get(testArchivePath));
560 }
bbdb3d6d
MAL
561 }
562
563 /**
564 * Create a temporary archive containing a nested archive. For example,
565 * testtraces.zip/synctraces.tar.gz can be used to test a nested archive.
566 */
29fe7911 567 private static String createNestedArchive() throws IOException, CoreException, URISyntaxException {
bbdb3d6d
MAL
568 // Link to the test traces folder. We use a link so that we can safely
569 // delete the entire project when we are done.
570 IProject project = getProjectResource();
571 String canonicalPath = new File(TRACE_FOLDER_PARENT_PATH).getCanonicalPath();
572 IFolder folder = project.getFolder(TRACE_FOLDER_PARENT_NAME);
573 folder.createLink(new Path(canonicalPath), IResource.REPLACE, null);
d34c9ed8 574 IFile file = folder.getFile(ARCHIVE_FILE_NAME);
29fe7911
MAL
575 String archivePath = createArchive(file);
576 folder.delete(true, null);
577 return archivePath;
d34c9ed8
PT
578 }
579
580 /**
581 * Create the empty archive from an empty folder
582 */
29fe7911
MAL
583 private static String createEmptyArchive() throws CoreException, URISyntaxException {
584 IFolder tempEmptyDirectory = createEmptyDirectory();
585 String archivePath = createArchive(tempEmptyDirectory);
586 tempEmptyDirectory.delete(true, null);
587 return archivePath;
d34c9ed8
PT
588 }
589
29fe7911 590 private static IFolder createEmptyDirectory() throws CoreException {
d34c9ed8
PT
591 IProject project = getProjectResource();
592 IFolder folder = project.getFolder(EMPTY_ARCHIVE_FOLDER);
593 folder.create(true, true, null);
594 return folder;
595 }
596
fc4a373f
BH
597 private static void createEmptyFile(IFolder folder) throws CoreException {
598 // Create empty file
599 IFile file = folder.getFile(EMPTY_FILE_NAME);
600 file.create(new ByteArrayInputStream(new byte[0]), true, null);
601 }
602
d34c9ed8
PT
603 /**
604 * Create a temporary archive from the specified resource.
605 */
606 private static String createArchive(IResource sourceResource) throws URISyntaxException {
607 IPath exportedPath = sourceResource.getFullPath();
bbdb3d6d
MAL
608
609 SWTBotTreeItem traceFilesProject = SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME);
610 traceFilesProject.contextMenu("Export...").click();
611
612 fBot.waitUntil(Conditions.shellIsActive("Export"));
613 SWTBotShell activeShell = fBot.activeShell();
614 SWTBotTree exportWizardsTree = fBot.tree();
615 SWTBotTreeItem treeItem = SWTBotUtils.getTreeItem(fBot, exportWizardsTree, "General", "Archive File");
616 treeItem.select();
617 fBot.button("Next >").click();
618 fBot.button("&Deselect All").click();
13e9acb6 619 try {
fa74050c
MAL
620 String resolveLinkedResLabel = "Resolve and export linked resources";
621 fBot.waitUntil(Conditions.waitForWidget(withMnemonic(resolveLinkedResLabel)), 100);
622 fBot.checkBox(resolveLinkedResLabel).select();
623 } catch (TimeoutException e) {
13e9acb6
MAL
624 // Ignore, doesn't exist pre-4.6M5
625 }
d34c9ed8
PT
626
627 if (sourceResource instanceof IFile) {
628 String[] folderPath = exportedPath.removeLastSegments(1).segments();
629 String fileName = exportedPath.lastSegment();
630 selectFile(fileName, folderPath);
631 } else {
632 selectFolder(exportedPath.segments());
633 }
bbdb3d6d
MAL
634
635 String workspacePath = URIUtil.toFile(URIUtil.fromString(System.getProperty("osgi.instance.area"))).getAbsolutePath();
636 final String archiveDestinationPath = workspacePath + File.separator + TRACE_PROJECT_NAME + File.separator + GENERATED_ARCHIVE_NAME;
637 fBot.comboBox().setText(archiveDestinationPath);
638 fBot.button("&Finish").click();
639 fBot.waitUntil(Conditions.shellCloses(activeShell));
640 return archiveDestinationPath;
641 }
642
9b3f4afe
MAL
643 private void testViews(TmfEventsEditor editor) {
644 testHistogramView(getViewPart("Histogram"), editor);
645 testPropertyView(getViewPart("Properties"));
646 testStatisticsView(getViewPart("Statistics"));
2f7b3dd7
BH
647 }
648
bbdb3d6d 649 private static void openImportWizard() {
2f7b3dd7
BH
650 fWizard = new ImportTraceWizard();
651
652 UIThreadRunnable.asyncExec(new VoidResult() {
653 @Override
654 public void run() {
655 final IWorkbench workbench = PlatformUI.getWorkbench();
656 // Fire the Import Trace Wizard
657 if (workbench != null) {
658 final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
659 Shell shell = activeWorkbenchWindow.getShell();
660 assertNotNull(shell);
661 ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
662 WizardDialog dialog = new WizardDialog(shell, fWizard);
663 dialog.open();
664 }
665 }
666 });
667
668 fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
669 }
670
bbdb3d6d 671 private static void selectImportFromDirectory(String directoryPath) {
93c91230
MAL
672 SWTBotRadio button = fBot.radio("Select roo&t directory:");
673 button.click();
674
2f7b3dd7 675 SWTBotCombo sourceCombo = fBot.comboBox();
bbdb3d6d 676 File traceFolderParent = new File(directoryPath);
93c91230 677 sourceCombo.setText(traceFolderParent.getAbsolutePath());
2f7b3dd7
BH
678
679 SWTBotText text = fBot.text();
680 text.setFocus();
2f7b3dd7
BH
681 }
682
bbdb3d6d 683 private static void selectImportFromArchive(String archivePath) {
9b3f4afe
MAL
684 SWTBotRadio button = fBot.radio("Select &archive file:");
685 button.click();
686
687 SWTBotCombo sourceCombo = fBot.comboBox(1);
688
bbdb3d6d 689 sourceCombo.setText(new File(archivePath).getAbsolutePath());
9b3f4afe
MAL
690
691 SWTBotText text = fBot.text();
692 text.setFocus();
bbdb3d6d 693 }
9b3f4afe 694
bbdb3d6d 695 private static void selectFolder(String... treePath) {
d34c9ed8
PT
696 selectFolder(true, treePath);
697 }
698
699 private static void selectFolder(boolean check, String... treePath) {
9b3f4afe
MAL
700 SWTBotTree tree = fBot.tree();
701 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
bbdb3d6d 702 SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, tree, treePath);
d34c9ed8
PT
703 if (check) {
704 folderNode.check();
705 } else {
706 folderNode.select();
707 }
bbdb3d6d 708 }
9b3f4afe 709
bbdb3d6d 710 private static void selectFile(String fileName, String... folderTreePath) {
d34c9ed8 711 selectFolder(false, folderTreePath);
bbdb3d6d
MAL
712
713 SWTBotTable fileTable = fBot.table();
714 fBot.waitUntil(Conditions.widgetIsEnabled(fileTable));
715 fBot.waitUntil(ConditionHelpers.isTableItemAvailable(fileName, fileTable));
716 SWTBotTableItem tableItem = fileTable.getTableItem(fileName);
717 tableItem.check();
2f7b3dd7
BH
718 }
719
9b3f4afe
MAL
720 private static void setOptions(int optionFlags, String traceTypeName) {
721 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
722 if (checkBox.isEnabled()) {
723 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) {
724 checkBox.select();
725 } else {
726 checkBox.deselect();
727 }
728 }
729
730 checkBox = fBot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure);
731 if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
732 checkBox.select();
733 } else {
734 checkBox.deselect();
735 }
736
737 checkBox = fBot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized);
738 if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
739 checkBox.select();
740 } else {
741 checkBox.deselect();
742 }
743
744 checkBox = fBot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace);
745 if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) {
746 checkBox.select();
747 } else {
748 checkBox.deselect();
749 }
750
40ba27e1
BH
751 checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateExperiment);
752 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT) != 0) {
753 checkBox.select();
754 } else {
755 checkBox.deselect();
756 }
757
9b3f4afe
MAL
758 SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
759 if (traceTypeName != null && !traceTypeName.isEmpty()) {
760 comboBox.setSelection(traceTypeName);
761 } else {
762 comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
763 }
93c91230
MAL
764 }
765
29fe7911 766 private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
c47c8803 767 checkOptions(optionFlags, expectedSourceLocation, expectedElementPath, null, null);
40ba27e1
BH
768 }
769
c47c8803 770 private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath, String experimentName, IPath expectedElementPathRenamed) throws CoreException {
bbdb3d6d 771 IProject project = getProjectResource();
9b3f4afe
MAL
772 assertTrue(project.exists());
773 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
774 assertNotNull(tmfProject);
775 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
776 assertNotNull(tracesFolder);
777 List<TmfTraceElement> traces = tracesFolder.getTraces();
778 assertFalse(traces.isEmpty());
779 Collections.sort(traces, new Comparator<TmfTraceElement>() {
780 @Override
781 public int compare(TmfTraceElement arg0, TmfTraceElement arg1) {
782 return arg0.getElementPath().compareTo(arg1.getElementPath());
783 }
784 });
785
786 TmfTraceElement tmfTraceElement = traces.get(0);
787 IResource traceResource = tmfTraceElement.getResource();
788
789 assertEquals((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0, traceResource.isLinked());
790
791 // i.e. /Tracing/Traces
bbdb3d6d 792 IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPath);
9b3f4afe 793 assertEquals(expectedPath, traceResource.getFullPath());
9b3f4afe 794
c47c8803
BH
795 if (expectedElementPathRenamed != null) {
796 IPath expectedPathRenamed = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPathRenamed);
797 IResource traceResourceRenamed = traces.get(1).getResource();
798 assertEquals(expectedPathRenamed, traceResourceRenamed.getFullPath());
799 }
800
bbdb3d6d
MAL
801 String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
802 assertNotNull(sourceLocation);
803 assertEquals(expectedSourceLocation, sourceLocation);
40ba27e1
BH
804
805 TmfExperimentFolder expFolder = tmfProject.getExperimentsFolder();
806 assertNotNull(expFolder);
807 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT) != 0) {
808 if (experimentName != null) {
809 TmfExperimentElement expElement = expFolder.getExperiment(experimentName);
810 assertNotNull(expElement);
811 assertEquals(2, expElement.getTraces().size());
812 }
813 } else {
814 assertTrue(expFolder.getExperiments().size() == 0);
815 }
9b3f4afe
MAL
816 }
817
29fe7911
MAL
818 private static IProject getProjectResource() {
819 return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
bbdb3d6d 820 }
40ba27e1
BH
821
822 private @NonNull String verifyExperimentNameHandling(String aExperimentName) {
823 String experimentName = aExperimentName;
824
825 // experiment already exists
826 checkFinishButton(false);
827
828 SWTBotText expText = fBot.textInGroup("Options");
829
830 // Invalid experiment name (only whitespaces)
831 expText.setText(String.valueOf(' '));
832 checkFinishButton(false);
833
834 // Invalid experiment name
835 expText.setText(String.valueOf('/'));
836 checkFinishButton(false);
837
838 // Set valid experiment name
839 experimentName += '_';
840 expText.setText(experimentName);
841 return experimentName;
842 }
843
2f7b3dd7 844}
This page took 0.119359 seconds and 5 git commands to generate.