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
.SWTBotCombo
;
52 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotRadio
;
53 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
54 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
55 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTableItem
;
56 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
57 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
58 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
59 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.TimeoutException
;
60 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportConfirmation
;
61 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizard
;
62 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizardPage
;
63 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.Messages
;
64 import org
.eclipse
.tracecompass
.tmf
.core
.TmfCommonConstants
;
65 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfEventsEditor
;
66 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfExperimentElement
;
67 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfExperimentFolder
;
68 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectElement
;
69 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfProjectRegistry
;
70 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceElement
;
71 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTraceFolder
;
72 import org
.eclipse
.tracecompass
.tmf
.ui
.project
.model
.TmfTracesFolder
;
73 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
74 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
75 import org
.eclipse
.ui
.IWorkbench
;
76 import org
.eclipse
.ui
.IWorkbenchWindow
;
77 import org
.eclipse
.ui
.PlatformUI
;
78 import org
.junit
.AfterClass
;
79 import org
.junit
.BeforeClass
;
80 import org
.junit
.Test
;
81 import org
.junit
.runner
.RunWith
;
84 * SWTBot Smoke test using ImportTraceWizard.
86 * @author Bernd Hufmann
88 @RunWith(SWTBotJunit4ClassRunner
.class)
89 public class StandardImportAndReadSmokeTest
extends AbstractImportAndReadSmokeTest
{
91 private static final String TRACE_FOLDER_PARENT_PATH
= "../../ctf/org.eclipse.tracecompass.ctf.core.tests/traces/";
92 private static final String ARCHIVE_FILE_NAME
= "synctraces.tar.gz";
93 private static final String EMPTY_ARCHIVE_FOLDER
= "emptyArchiveFolder";
94 private static final String EMPTY_FILE_NAME
= "emptyFile";
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";
97 private static final String TRACE_PROJECT_NAME
= "Tracing";
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
: "";
107 /** Test Class setup */
109 public static void beforeClass() {
110 createProject(TRACE_PROJECT_NAME
);
113 /** Test Class tear down */
115 public static void afterClass() {
116 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
120 * Test import from directory
126 public void testImportFromDirectory() throws Exception
{
127 testImport(0, false, false);
131 * Test import from directory, create links
137 public void testImportFromDirectoryLinks() throws Exception
{
138 testImport(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
, false, false);
142 * Test import from directory, create experiment
148 public void testImportWithExperiment() throws Exception
{
149 testImport(ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, false);
153 * Test import from directory, create experiment (validate experiment name)
159 public void testImportWithExperimentValidation() throws Exception
{
160 testImport(ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, false, false, true, ImportConfirmation
.CONTINUE
);
164 * Test import from directory, preserve folder structure
170 public void testImportFromDirectoryPreserveFolder() throws Exception
{
171 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, false);
175 * Test import from directory, create links, preserve folder structure
181 public void testImportFromDirectoryLinksPreserveFolder() throws Exception
{
182 int options
= ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
;
183 testImport(options
, false, false);
187 * Test import from directory, overwrite all
193 public void testImportFromDirectoryOverwrite() throws Exception
{
194 testImport(0, false, false, true, false, ImportConfirmation
.CONTINUE
);
195 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
199 * Test import from directory, overwrite all
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
);
211 * Test import from directory, overwrite all
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
);
223 * Test import from archive
229 public void testImportFromArchive() throws Exception
{
230 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, true, true);
234 * Test import from archive, create Experiment
240 public void testImportFromArchiveWithExperiment() throws Exception
{
241 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
| ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
, false, true);
245 * Test import from directory, preserve folder structure
246 * @throws Exception on error
249 public void testImportFromArchivePreserveFolder() throws Exception
{
250 testImport(ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
254 * Test import from directory, overwrite all
260 public void testImportFromArchiveOverwrite() throws Exception
{
261 testImport(0, false, true, true, false, ImportConfirmation
.CONTINUE
);
262 testImport(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
266 * Test import from directory containing archives
272 public void testExtractArchivesFromDirectory() throws Exception
{
273 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
277 * Test import from directory containing archives, create links
278 * @throws Exception on error
281 public void testExtractArchivesFromDirectoryLinks() throws Exception
{
282 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, false);
286 * Test import from directory containing archives, create links, preserve folder structure
287 * @throws Exception on error
290 public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception
{
291 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
| ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, true, false);
295 * Test import from archive containing archives
301 public void testExtractArchivesFromArchive() throws Exception
{
302 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
, false, true);
306 * Test import from archive containing archives, preserve folder structure
312 public void testExtractArchivesFromArchivePreserveFolder() throws Exception
{
313 testImportAndExtractArchives(ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
| ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
, false, true);
317 * Test import from an empty archive. This should not import anything.
323 public void testEmptyArchive() throws Exception
{
324 String testArchivePath
= createEmptyArchive();
327 selectImportFromArchive(testArchivePath
);
328 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
329 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
334 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
335 Files
.delete(Paths
.get(testArchivePath
));
339 * Test import from an empty directory. This should not import anything.
345 public void testEmptyDirectory() throws Exception
{
346 IFolder emptyDirectory
= createEmptyDirectory();
347 String testDirectoryPath
= emptyDirectory
.getLocation().toOSString();
350 selectImportFromDirectory(testDirectoryPath
);
351 selectFolder(EMPTY_ARCHIVE_FOLDER
);
352 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
357 Files
.delete(Paths
.get(testDirectoryPath
));
358 emptyDirectory
.delete(true, null);
359 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
363 * Test import from an directory with an empty file. This should not import anything.
369 public void testEmptyFile() throws Exception
{
370 IFolder folder
= createEmptyDirectory();
371 createEmptyFile(folder
);
372 String testDirectoryPath
= folder
.getLocation().toOSString();
374 selectImportFromDirectory(testDirectoryPath
);
375 selectFile(EMPTY_FILE_NAME
, EMPTY_ARCHIVE_FOLDER
);
376 setOptions(ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
381 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
382 folder
.delete(true, null);
386 * Test import from a directory containing an empty archive. This should not import anything.
392 public void testDirectoryWithEmptyArchive() throws Exception
{
393 String testArchivePath
= createEmptyArchive();
396 selectImportFromDirectory(getProjectResource().getLocation().toOSString());
397 selectFile(GENERATED_ARCHIVE_NAME
, TRACE_PROJECT_NAME
);
398 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
403 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
404 Files
.delete(Paths
.get(testArchivePath
));
408 * Test import from a nested empty archive. This should not import anything.
414 public void testNestedEmptyArchive() throws Exception
{
415 IProject project
= getProjectResource();
417 // Create the empty archive from an empty folder
418 String testArchivePath
= createEmptyArchive();
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
);
429 createArchive(renamedArchiveFile
);
430 renamedArchiveFile
.delete(true, null);
433 selectImportFromArchive(testArchivePath
);
434 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME
);
435 setOptions(0, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
440 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
441 Files
.delete(Paths
.get(testArchivePath
));
444 private static void assertNoTraces() {
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());
453 private void testImport(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
454 testImport(options
, testViews
, fromArchive
, true, true, ImportConfirmation
.CONTINUE
);
457 private void testImport(int options
, boolean testViews
, boolean fromArchive
, boolean defaultExperiment
, boolean clearTraces
, ImportConfirmation confirmationMode
) throws Exception
{
458 String expectedSourceLocation
= null;
460 @NonNull String experimentName
;
462 experimentName
= checkNotNull(new Path(ARCHIVE_FILE_NAME
).lastSegment());
464 experimentName
= checkNotNull(new Path(TRACE_FOLDER_PARENT_PATH
).lastSegment());
467 if (!defaultExperiment
) {
468 SWTBotUtils
.createExperiment(fBot
, TRACE_PROJECT_NAME
, experimentName
);
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());
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
});
485 setOptions(options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
487 if (!defaultExperiment
) {
488 experimentName
= verifyExperimentNameHandling(experimentName
);
490 checkFinishButton(true);
492 importFinish(confirmationMode
);
494 IPath expectedElementPath
= new Path(TRACE_NAME
);
495 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
496 expectedElementPath
= new Path(TRACE_FOLDER
).append(expectedElementPath
);
499 if (confirmationMode
== ImportConfirmation
.RENAME_ALL
) {
500 IPath expectedElementPathRenamed
= new Path(TRACE_NAME
+ "(2)");
501 checkOptions(options
, expectedSourceLocation
, expectedElementPath
, experimentName
, expectedElementPathRenamed
);
503 checkOptions(options
, expectedSourceLocation
, expectedElementPath
, experimentName
, null);
506 TmfEventsEditor tmfEd
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
511 fBot
.closeAllEditors();
513 SWTBotUtils
.clearExperimentFolder(fBot
, TRACE_PROJECT_NAME
);
515 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
519 private void testImportAndExtractArchives(int options
, boolean testViews
, boolean fromArchive
) throws Exception
{
520 String expectedSourceLocation
;
521 IPath expectedElementPath
;
522 String testArchivePath
= null;
524 testArchivePath
= createNestedArchive();
526 selectImportFromArchive(testArchivePath
);
527 selectFile(ARCHIVE_FILE_NAME
, ARCHIVE_ROOT_ELEMENT_NAME
, TRACE_PROJECT_NAME
, TRACE_FOLDER_PARENT_NAME
);
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
);
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
;
540 if ((options
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) == 0) {
541 expectedElementPath
= new Path(TRACE_NAME
);
544 setOptions(options
, ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
546 // Archives should never be imported as links
547 int expectedOptions
= options
& ~ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
;
548 checkOptions(expectedOptions
, expectedSourceLocation
, expectedElementPath
);
550 TmfEventsEditor editor
= SWTBotUtils
.openEditor(fBot
, TRACE_PROJECT_NAME
, expectedElementPath
);
555 SWTBotUtils
.clearExperimentFolder(fBot
, TRACE_PROJECT_NAME
);
557 SWTBotUtils
.clearTracesFolder(fBot
, TRACE_PROJECT_NAME
);
558 if (testArchivePath
!= null) {
559 Files
.delete(Paths
.get(testArchivePath
));
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.
567 private static String
createNestedArchive() throws IOException
, CoreException
, URISyntaxException
{
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);
574 IFile file
= folder
.getFile(ARCHIVE_FILE_NAME
);
575 String archivePath
= createArchive(file
);
576 folder
.delete(true, null);
581 * Create the empty archive from an empty folder
583 private static String
createEmptyArchive() throws CoreException
, URISyntaxException
{
584 IFolder tempEmptyDirectory
= createEmptyDirectory();
585 String archivePath
= createArchive(tempEmptyDirectory
);
586 tempEmptyDirectory
.delete(true, null);
590 private static IFolder
createEmptyDirectory() throws CoreException
{
591 IProject project
= getProjectResource();
592 IFolder folder
= project
.getFolder(EMPTY_ARCHIVE_FOLDER
);
593 folder
.create(true, true, null);
597 private static void createEmptyFile(IFolder folder
) throws CoreException
{
599 IFile file
= folder
.getFile(EMPTY_FILE_NAME
);
600 file
.create(new ByteArrayInputStream(new byte[0]), true, null);
604 * Create a temporary archive from the specified resource.
606 private static String
createArchive(IResource sourceResource
) throws URISyntaxException
{
607 IPath exportedPath
= sourceResource
.getFullPath();
609 SWTBotTreeItem traceFilesProject
= SWTBotUtils
.selectProject(fBot
, TRACE_PROJECT_NAME
);
610 traceFilesProject
.contextMenu("Export...").click();
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");
617 fBot
.button("Next >").click();
618 fBot
.button("&Deselect All").click();
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
) {
624 // Ignore, doesn't exist pre-4.6M5
627 if (sourceResource
instanceof IFile
) {
628 String
[] folderPath
= exportedPath
.removeLastSegments(1).segments();
629 String fileName
= exportedPath
.lastSegment();
630 selectFile(fileName
, folderPath
);
632 selectFolder(exportedPath
.segments());
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
;
643 private void testViews(TmfEventsEditor editor
) {
644 testHistogramView(getViewPart("Histogram"), editor
);
645 testPropertyView(getViewPart("Properties"));
646 testStatisticsView(getViewPart("Statistics"));
649 private static void openImportWizard() {
650 fWizard
= new ImportTraceWizard();
652 UIThreadRunnable
.asyncExec(new VoidResult() {
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
);
668 fBot
.waitUntil(ConditionHelpers
.isWizardReady(fWizard
));
671 private static void selectImportFromDirectory(String directoryPath
) {
672 SWTBotRadio button
= fBot
.radio("Select roo&t directory:");
675 SWTBotCombo sourceCombo
= fBot
.comboBox();
676 File traceFolderParent
= new File(directoryPath
);
677 sourceCombo
.setText(traceFolderParent
.getAbsolutePath());
679 SWTBotText text
= fBot
.text();
683 private static void selectImportFromArchive(String archivePath
) {
684 SWTBotRadio button
= fBot
.radio("Select &archive file:");
687 SWTBotCombo sourceCombo
= fBot
.comboBox(1);
689 sourceCombo
.setText(new File(archivePath
).getAbsolutePath());
691 SWTBotText text
= fBot
.text();
695 private static void selectFolder(String
... treePath
) {
696 selectFolder(true, treePath
);
699 private static void selectFolder(boolean check
, String
... treePath
) {
700 SWTBotTree tree
= fBot
.tree();
701 fBot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
702 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(fBot
, tree
, treePath
);
710 private static void selectFile(String fileName
, String
... folderTreePath
) {
711 selectFolder(false, folderTreePath
);
713 SWTBotTable fileTable
= fBot
.table();
714 fBot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
715 fBot
.waitUntil(ConditionHelpers
.isTableItemAvailable(fileName
, fileTable
));
716 SWTBotTableItem tableItem
= fileTable
.getTableItem(fileName
);
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) {
730 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_PreserveFolderStructure
);
731 if ((optionFlags
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
737 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_ImportUnrecognized
);
738 if ((optionFlags
& ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
) != 0) {
744 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_OverwriteExistingTrace
);
745 if ((optionFlags
& ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
) != 0) {
751 checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_CreateExperiment
);
752 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
) != 0) {
758 SWTBotCombo comboBox
= fBot
.comboBoxWithLabel(Messages
.ImportTraceWizard_TraceType
);
759 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
760 comboBox
.setSelection(traceTypeName
);
762 comboBox
.setSelection(ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
766 private static void checkOptions(int optionFlags
, String expectedSourceLocation
, IPath expectedElementPath
) throws CoreException
{
767 checkOptions(optionFlags
, expectedSourceLocation
, expectedElementPath
, null, null);
770 private static void checkOptions(int optionFlags
, String expectedSourceLocation
, IPath expectedElementPath
, String experimentName
, IPath expectedElementPathRenamed
) throws CoreException
{
771 IProject project
= getProjectResource();
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
>() {
781 public int compare(TmfTraceElement arg0
, TmfTraceElement arg1
) {
782 return arg0
.getElementPath().compareTo(arg1
.getElementPath());
786 TmfTraceElement tmfTraceElement
= traces
.get(0);
787 IResource traceResource
= tmfTraceElement
.getResource();
789 assertEquals((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0, traceResource
.isLinked());
791 // i.e. /Tracing/Traces
792 IPath expectedPath
= Path
.ROOT
.append(new Path(TRACE_PROJECT_NAME
)).append(TmfTracesFolder
.TRACES_FOLDER_NAME
).append(expectedElementPath
);
793 assertEquals(expectedPath
, traceResource
.getFullPath());
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());
801 String sourceLocation
= traceResource
.getPersistentProperty(TmfCommonConstants
.SOURCE_LOCATION
);
802 assertNotNull(sourceLocation
);
803 assertEquals(expectedSourceLocation
, sourceLocation
);
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());
814 assertTrue(expFolder
.getExperiments().size() == 0);
818 private static IProject
getProjectResource() {
819 return ResourcesPlugin
.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME
);
822 private @NonNull String
verifyExperimentNameHandling(String aExperimentName
) {
823 String experimentName
= aExperimentName
;
825 // experiment already exists
826 checkFinishButton(false);
828 SWTBotText expText
= fBot
.textInGroup("Options");
830 // Invalid experiment name (only whitespaces)
831 expText
.setText(String
.valueOf(' '));
832 checkFinishButton(false);
834 // Invalid experiment name
835 expText
.setText(String
.valueOf('/'));
836 checkFinishButton(false);
838 // Set valid experiment name
839 experimentName
+= '_';
840 expText
.setText(experimentName
);
841 return experimentName
;