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