1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
10 * Bernd Hufmann - Initial API and implementation
11 * Marc-Andre Laperle - Added tests for extracting archives during import
12 *******************************************************************************/
14 package org
.eclipse
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
;
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
;
23 import java
.io
.ByteArrayInputStream
;
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
;
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
;
80 * SWTBot Smoke test using ImportTraceWizard.
82 * @author Bernd Hufmann
84 @RunWith(SWTBotJunit4ClassRunner
.class)
85 public class StandardImportAndReadSmokeTest
extends AbstractImportAndReadSmokeTest
{
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";
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
: "";
103 /** Test Class setup */
105 public static void beforeClass() {
106 createProject(TRACE_PROJECT_NAME
);
109 /** Test Class tear down */
111 public static void afterClass() {
112 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
116 * Test import from directory
122 public void testImportFromDirectory() throws Exception
{
123 testImport(0, false, false);
127 * Test import from directory, create links
133 public void testImportFromDirectoryLinks() throws Exception
{
134 testImport(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
, false, false);
138 * Test import from directory, create experiment
144 public void testImportWithExperiment() throws Exception
{
145 testImport(ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, false);
149 * Test import from directory, create experiment (validate experiment name)
155 public void testImportWithExperimentValidation() throws Exception
{
156 testImport(ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, false, false, true, ImportConfirmation
.CONTINUE
);
160 * Test import from directory, preserve folder structure
166 public void testImportFromDirectoryPreserveFolder() throws Exception
{
167 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, false);
171 * Test import from directory, create links, preserve folder structure
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);
183 * Test import from directory, overwrite all
189 public void testImportFromDirectoryOverwrite() throws Exception
{
190 testImport(0, false, false, true, false, ImportConfirmation
.CONTINUE
);
191 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
195 * Test import from directory, overwrite all
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
);
207 * Test import from directory, overwrite all
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
);
219 * Test import from archive
225 public void testImportFromArchive() throws Exception
{
226 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, true, true);
230 * Test import from archive, create Experiment
236 public void testImportFromArchiveWithExperiment() throws Exception
{
237 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
| ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, true);
241 * Test import from directory, preserve folder structure
242 * @throws Exception on error
245 public void testImportFromArchivePreserveFolder() throws Exception
{
246 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
250 * Test import from directory, overwrite all
256 public void testImportFromArchiveOverwrite() throws Exception
{
257 testImport(0, false, true, true, false, ImportConfirmation
.CONTINUE
);
258 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
262 * Test import from directory containing archives
268 public void testExtractArchivesFromDirectory() throws Exception
{
269 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
273 * Test import from directory containing archives, create links
274 * @throws Exception on error
277 public void testExtractArchivesFromDirectoryLinks() throws Exception
{
278 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
282 * Test import from directory containing archives, create links, preserve folder structure
283 * @throws Exception on error
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);
291 * Test import from archive containing archives
297 public void testExtractArchivesFromArchive() throws Exception
{
298 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
302 * Test import from archive containing archives, preserve folder structure
308 public void testExtractArchivesFromArchivePreserveFolder() throws Exception
{
309 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
313 * Test import from an empty archive. This should not import anything.
319 public void testEmptyArchive() throws Exception
{
320 String testArchivePath
= createEmptyArchive();
323 SWTBotImportWizardUtils
.selectImportFromArchive(fBot
, testArchivePath
);
324 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
325 SWTBotImportWizardUtils
.setOptions(fBot
, 0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
330 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
331 Files
.delete(Paths
.get(testArchivePath
));
335 * Test import from an empty directory. This should not import anything.
341 public void testEmptyDirectory() throws Exception
{
342 IFolder emptyDirectory
= createEmptyDirectory();
343 String testDirectoryPath
= emptyDirectory
.getLocation().toOSString();
346 SWTBotImportWizardUtils
.selectImportFromDirectory(fBot
, testDirectoryPath
);
347 selectFolder(EMPTY_ARCHIVE_FOLDER
);
348 SWTBotImportWizardUtils
.setOptions(fBot
, 0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
353 Files
.delete(Paths
.get(testDirectoryPath
));
354 emptyDirectory
.delete(true, null);
355 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
359 * Test import from an directory with an empty file. This should not import anything.
365 public void testEmptyFile() throws Exception
{
366 IFolder folder
= createEmptyDirectory();
367 createEmptyFile(folder
);
368 String testDirectoryPath
= folder
.getLocation().toOSString();
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
);
377 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
378 folder
.delete(true, null);
382 * Test import from a directory containing an empty archive. This should not import anything.
388 public void testDirectoryWithEmptyArchive() throws Exception
{
389 String testArchivePath
= createEmptyArchive();
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
);
399 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
400 Files
.delete(Paths
.get(testArchivePath
));
404 * Test import from a nested empty archive. This should not import anything.
410 public void testNestedEmptyArchive() throws Exception
{
411 IProject project
= getProjectResource();
413 // Create the empty archive from an empty folder
414 String testArchivePath
= createEmptyArchive();
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
);
425 createArchive(renamedArchiveFile
);
426 renamedArchiveFile
.delete(true, null);
429 SWTBotImportWizardUtils
.selectImportFromArchive(fBot
, testArchivePath
);
430 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
431 SWTBotImportWizardUtils
.setOptions(fBot
, 0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
436 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
437 Files
.delete(Paths
.get(testArchivePath
));
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());
449 private void testImport(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
450 testImport(options
, testViews
, fromArchive
, true, true, ImportConfirmation
.CONTINUE
);
453 private void testImport(int options
, boolean testViews
, boolean fromArchive
, boolean defaultExperiment
, boolean clearTraces
, ImportConfirmation confirmationMode
) throws Exception
{
454 String expectedSourceLocation
= null;
456 @NonNull String experimentName
;
458 experimentName
= checkNotNull(new Path(ARCHIVE_FILE_NAME
).lastSegment());
460 experimentName
= checkNotNull(new Path(TRACE_FOLDER_PARENT_PATH
).lastSegment());
463 if (!defaultExperiment
) {
464 SWTBotUtils
.createExperiment(fBot
, TRACE_PROJECT_NAME
, experimentName
);
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());
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
});
481 SWTBotImportWizardUtils
.setOptions(fBot
, options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
483 if (!defaultExperiment
) {
484 experimentName
= verifyExperimentNameHandling(experimentName
);
486 checkFinishButton(true);
488 importFinish(confirmationMode
);
490 IPath expectedElementPath
= new Path(TRACE_NAME
);
491 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
492 expectedElementPath
= new Path(TRACE_FOLDER
).append(expectedElementPath
);
495 if (confirmationMode
== ImportConfirmation
.RENAME_ALL
) {
496 IPath expectedElementPathRenamed
= new Path(TRACE_NAME
+ "(2)");
497 checkOptions(options
, expectedSourceLocation
, expectedElementPath
, experimentName
, expectedElementPathRenamed
);
499 checkOptions(options
, expectedSourceLocation
, expectedElementPath
, experimentName
, null);
502 TmfEventsEditor tmfEd
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
507 fBot
.closeAllEditors();
509 SWTBotUtils
.clearExperimentFolder(fBot
, TRACE_PROJECT_NAME
);
511 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
515 private void testImportAndExtractArchives(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
516 String expectedSourceLocation
;
517 IPath expectedElementPath
;
518 String testArchivePath
= null;
520 testArchivePath
= createNestedArchive();
522 SWTBotImportWizardUtils
.selectImportFromArchive(fBot
, testArchivePath
);
523 SWTBotImportWizardUtils
.selectFile(fBot
, ARCHIVE_FILE_NAME
, ARCHIVE_ROOT_ELEMENT_NAME
, TRACE_PROJECT_NAME
, TRACE_FOLDER_PARENT_NAME
);
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
);
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
;
536 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) == 0) {
537 expectedElementPath
= new Path(TRACE_NAME
);
540 SWTBotImportWizardUtils
.setOptions(fBot
, options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
542 // Archives should never be imported as links
543 int expectedOptions
= options
& ~ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
544 checkOptions(expectedOptions
, expectedSourceLocation
, expectedElementPath
);
546 TmfEventsEditor editor
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
551 SWTBotUtils
.clearExperimentFolder(fBot
, TRACE_PROJECT_NAME
);
553 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
554 if (testArchivePath
!= null) {
555 Files
.delete(Paths
.get(testArchivePath
));
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.
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);
577 * Create the empty archive from an empty folder
579 private static String
createEmptyArchive() throws CoreException
, URISyntaxException
{
580 IFolder tempEmptyDirectory
= createEmptyDirectory();
581 String archivePath
= createArchive(tempEmptyDirectory
);
582 tempEmptyDirectory
.delete(true, null);
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);
593 private static void createEmptyFile(IFolder folder
) throws CoreException
{
595 IFile file
= folder
.getFile(EMPTY_FILE_NAME
);
596 file
.create(new ByteArrayInputStream(new byte[0]), true, null);
600 * Create a temporary archive from the specified resource.
602 private static String
createArchive(IResource sourceResource
) throws URISyntaxException
{
603 IPath exportedPath
= sourceResource
.getFullPath();
605 SWTBotTreeItem traceFilesProject
= SWTBotUtils
.selectProject(fBot
, TRACE_PROJECT_NAME
);
606 traceFilesProject
.contextMenu("Export...").click();
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");
613 fBot
.button("Next >").click();
614 fBot
.button("&Deselect All").click();
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
623 if (sourceResource
instanceof IFile
) {
624 String
[] folderPath
= exportedPath
.removeLastSegments(1).segments();
625 String fileName
= exportedPath
.lastSegment();
626 SWTBotImportWizardUtils
.selectFile(fBot
, fileName
, folderPath
);
628 selectFolder(exportedPath
.segments());
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
;
639 private void testViews(TmfEventsEditor editor
) {
640 testHistogramView(getViewPart("Histogram"), editor
);
641 testPropertyView(getViewPart("Properties"));
642 testStatisticsView(getViewPart("Statistics"));
645 private static void openImportWizard() {
646 fWizard
= new ImportTraceWizard();
648 UIThreadRunnable
.asyncExec(new VoidResult() {
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
);
664 fBot
.waitUntil(ConditionHelpers
.isWizardReady(fWizard
));
669 private static void selectFolder(String
... treePath
) {
670 SWTBotImportWizardUtils
.selectFolder(fBot
, true, treePath
);
673 private static void checkOptions(int optionFlags
, String expectedSourceLocation
, IPath expectedElementPath
) throws CoreException
{
674 checkOptions(optionFlags
, expectedSourceLocation
, expectedElementPath
, null, null);
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
>() {
688 public int compare(TmfTraceElement arg0
, TmfTraceElement arg1
) {
689 return arg0
.getElementPath().compareTo(arg1
.getElementPath());
693 TmfTraceElement tmfTraceElement
= traces
.get(0);
694 IResource traceResource
= tmfTraceElement
.getResource();
696 assertEquals((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0, traceResource
.isLinked());
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());
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());
708 String sourceLocation
= traceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
709 assertNotNull(sourceLocation
);
710 assertEquals(expectedSourceLocation
, sourceLocation
);
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());
721 assertTrue(expFolder
.getExperiments().size() == 0);
725 private static IProject
getProjectResource() {
726 return ResourcesPlugin
.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME
);
729 private @NonNull String
verifyExperimentNameHandling(String aExperimentName
) {
730 String experimentName
= aExperimentName
;
732 // experiment already exists
733 checkFinishButton(false);
735 SWTBotText expText
= fBot
.textInGroup("Options");
737 // Invalid experiment name (only whitespaces)
738 expText
.setText(String
.valueOf(' '));
739 checkFinishButton(false);
741 // Invalid experiment name
742 expText
.setText(String
.valueOf('/'));
743 checkFinishButton(false);
745 // Set valid experiment name
746 experimentName
+= '_';
747 expText
.setText(experimentName
);
748 return experimentName
;