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