tmf: Fix exception importing empty archive or only folders
[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.junit.Assert.assertEquals;
17 import static org.junit.Assert.assertFalse;
18 import static org.junit.Assert.assertNotNull;
19 import static org.junit.Assert.assertTrue;
20
21 import java.io.File;
22 import java.io.IOException;
23 import java.net.URISyntaxException;
24 import java.util.Collections;
25 import java.util.Comparator;
26 import java.util.List;
27
28 import org.eclipse.core.resources.IFile;
29 import org.eclipse.core.resources.IFolder;
30 import org.eclipse.core.resources.IProject;
31 import org.eclipse.core.resources.IResource;
32 import org.eclipse.core.resources.ResourcesPlugin;
33 import org.eclipse.core.runtime.CoreException;
34 import org.eclipse.core.runtime.IPath;
35 import org.eclipse.core.runtime.Path;
36 import org.eclipse.core.runtime.URIUtil;
37 import org.eclipse.jface.viewers.StructuredSelection;
38 import org.eclipse.jface.wizard.WizardDialog;
39 import org.eclipse.swt.widgets.Shell;
40 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
41 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
42 import org.eclipse.swtbot.swt.finder.results.VoidResult;
43 import org.eclipse.swtbot.swt.finder.waits.Conditions;
44 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
45 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
46 import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
47 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
48 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
49 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
50 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
51 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
52 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
53 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
54 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
55 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
56 import org.eclipse.tracecompass.tmf.core.TmfCommonConstants;
57 import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor;
58 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement;
59 import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry;
60 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement;
61 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder;
62 import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder;
63 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
64 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
65 import org.eclipse.ui.IWorkbench;
66 import org.eclipse.ui.IWorkbenchWindow;
67 import org.eclipse.ui.PlatformUI;
68 import org.junit.Test;
69 import org.junit.runner.RunWith;
70
71 /**
72 * SWTBot Smoke test using ImportTraceWizard.
73 *
74 * @author Bernd Hufmann
75 */
76 @RunWith(SWTBotJunit4ClassRunner.class)
77 public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
78
79 private static final String TRACE_FOLDER_PARENT_PATH = fTrace.getPath() + File.separator + ".." + File.separator + ".." + File.separator;
80 private static final String ARCHIVE_FILE_NAME = "synctraces.tar.gz";
81 private static final String EMPTY_ARCHIVE_FOLDER = "emptyArchiveFolder";
82 private static final String TRACE_ARCHIVE_PATH = TRACE_FOLDER_PARENT_PATH + ARCHIVE_FILE_NAME;
83 private static final String TRACE_FOLDER_PARENT_NAME = "traces";
84 private static final String TRACE_PROJECT_NAME = "Tracing";
85
86 private static final String ARCHIVE_ROOT_ELEMENT_NAME = "/";
87 private static final String GENERATED_ARCHIVE_NAME = "testtraces.zip";
88 private static final String URI_SEPARATOR = "/";
89 private static final String URI_FILE_SCHEME = "file:";
90 private static final String URI_JAR_FILE_SCHEME = "jar:file:";
91 private static final boolean IS_WIN32 = System.getProperty("os.name").startsWith("Windows"); //$NON-NLS-1$//$NON-NLS-2$
92 private static final String URI_DEVICE_SEPARATOR = IS_WIN32 ? URI_SEPARATOR : "";
93
94 /**
95 * Test import from directory
96 *
97 * @throws Exception
98 * on error
99 */
100 @Test
101 public void testImportFromDirectory() throws Exception {
102 testImport(0, false, false);
103 }
104
105 /**
106 * Test import from directory, create links
107 *
108 * @throws Exception
109 * on error
110 */
111 @Test
112 public void testImportFromDirectoryLinks() throws Exception {
113 testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false);
114 }
115
116 /**
117 * Test import from directory, preserve folder structure
118 *
119 * @throws Exception
120 * on error
121 */
122 @Test
123 public void testImportFromDirectoryPreserveFolder() throws Exception {
124 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, false);
125 }
126
127 /**
128 * Test import from directory, create links, preserve folder structure
129 *
130 * @throws Exception
131 * on error
132 */
133 @Test
134 public void testImportFromDirectoryLinksPreserveFolder() throws Exception {
135 int options = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
136 testImport(options, false, false);
137 }
138
139 /**
140 * Test import from directory, overwrite all
141 *
142 * @throws Exception
143 * on error
144 */
145 @Test
146 public void testImportFromDirectoryOverwrite() throws Exception {
147 testImport(0, false, false);
148 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
149 }
150
151 /**
152 * Test import from archive
153 *
154 * @throws Exception
155 * on error
156 */
157 @Test
158 public void testImportFromArchive() throws Exception {
159 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true);
160 }
161
162 /**
163 * Test import from directory, preserve folder structure
164 * @throws Exception on error
165 */
166 @Test
167 public void testImportFromArchivePreserveFolder() throws Exception {
168 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
169 }
170
171 /**
172 * Test import from directory, overwrite all
173 *
174 * @throws Exception
175 * on error
176 */
177 @Test
178 public void testImportFromArchiveOverwrite() throws Exception {
179 testImport(0, false, true);
180 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
181 }
182
183 /**
184 * Test import from directory containing archives
185 *
186 * @throws Exception
187 * on error
188 */
189 @Test
190 public void testExtractArchivesFromDirectory() throws Exception {
191 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false);
192 }
193
194 /**
195 * Test import from directory containing archives, create links
196 * @throws Exception on error
197 */
198 @Test
199 public void testExtractArchivesFromDirectoryLinks() throws Exception {
200 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false);
201 }
202
203 /**
204 * Test import from directory containing archives, create links, preserve folder structure
205 * @throws Exception on error
206 */
207 @Test
208 public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception {
209 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false);
210 }
211
212 /**
213 * Test import from archive containing archives
214 *
215 * @throws Exception
216 * on error
217 */
218 @Test
219 public void testExtractArchivesFromArchive() throws Exception {
220 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, true);
221 }
222
223 /**
224 * Test import from archive containing archives, preserve folder structure
225 *
226 * @throws Exception
227 * on error
228 */
229 @Test
230 public void testExtractArchivesFromArchivePreserveFolder() throws Exception {
231 testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true);
232 }
233
234 /**
235 * Test import from an empty archive. This should not import anything.
236 *
237 * @throws Exception
238 * on error
239 */
240 @Test
241 public void testEmptyArchive() throws Exception {
242 createProject();
243 String testArchivePath = createEmptyArchive();
244
245 openImportWizard();
246 selectImportFromArchive(testArchivePath);
247 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
248 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
249 importFinish();
250
251 assertNoTraces();
252
253 SWTBotUtils.deleteProject(getProjectName(), fBot);
254 }
255
256 /**
257 * Test import from an empty directory. This should not import anything.
258 *
259 * @throws Exception
260 * on error
261 */
262 @Test
263 public void testEmptyDirectory() throws Exception {
264 createProject();
265 String testDirectoryPath = createEmptyDirectory().getLocation().toOSString();
266
267 openImportWizard();
268 selectImportFromDirectory(testDirectoryPath);
269 selectFolder(EMPTY_ARCHIVE_FOLDER);
270 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
271 importFinish();
272
273 assertNoTraces();
274
275 SWTBotUtils.deleteProject(getProjectName(), fBot);
276 }
277
278 /**
279 * Test import from a directory containing an empty archive. This should not import anything.
280 *
281 * @throws Exception
282 * on error
283 */
284 @Test
285 public void testDirectoryWithEmptyArchive() throws Exception {
286 createProject();
287 createEmptyArchive();
288
289 openImportWizard();
290 selectImportFromDirectory(getProjectResource().getLocation().toOSString());
291 selectFile(GENERATED_ARCHIVE_NAME, getProjectName());
292 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
293 importFinish();
294
295 assertNoTraces();
296
297 SWTBotUtils.deleteProject(getProjectName(), fBot);
298 }
299
300 /**
301 * Test import from a nested empty archive. This should not import anything.
302 *
303 * @throws Exception
304 * on error
305 */
306 @Test
307 public void testNestedEmptyArchive() throws Exception {
308 createProject();
309 IProject project = getProjectResource();
310
311 // Create the empty archive from an empty folder
312 String testArchivePath = createEmptyArchive();
313
314 // Rename archive so that we can create a new one with the same name
315 project.refreshLocal(IResource.DEPTH_ONE, null);
316 IFile[] files = project.getWorkspace().getRoot().findFilesForLocationURI(new File(testArchivePath).toURI());
317 IFile archiveFile = files[0];
318 String newEmptyArchiveName = "nested" + archiveFile.getName();
319 IPath dest = archiveFile.getFullPath().removeLastSegments(1).append(newEmptyArchiveName);
320 archiveFile.move(dest, true, null);
321 IFile renamedArchiveFile = archiveFile.getWorkspace().getRoot().getFile(dest);
322
323 createArchive(renamedArchiveFile);
324
325 openImportWizard();
326 selectImportFromArchive(testArchivePath);
327 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
328 setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
329 importFinish();
330
331 assertNoTraces();
332
333 SWTBotUtils.deleteProject(getProjectName(), fBot);
334 }
335
336 private void assertNoTraces() {
337 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(getProjectResource(), true);
338 assertNotNull(tmfProject);
339 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
340 assertNotNull(tracesFolder);
341 List<TmfTraceElement> traces = tracesFolder.getTraces();
342 assertTrue(traces.isEmpty());
343 }
344
345 private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception {
346 createProject();
347 String expectedSourceLocation = null;
348 openImportWizard();
349 if (fromArchive) {
350 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;
351 selectImportFromArchive(TRACE_ARCHIVE_PATH);
352 selectFolder(ARCHIVE_ROOT_ELEMENT_NAME);
353 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
354 assertFalse(checkBox.isEnabled());
355 } else {
356 String sourcePath = TRACE_FOLDER_PARENT_PATH + File.separator + TRACE_FOLDER + File.separator + TRACE_NAME;
357 expectedSourceLocation = URI_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(sourcePath).getCanonicalPath()) + URI_SEPARATOR;
358 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
359 selectFolder(new String [] {TRACE_FOLDER_PARENT_NAME, TRACE_FOLDER });
360 }
361
362 setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
363 importFinish();
364
365 IPath expectedElementPath = new Path(TRACE_NAME);
366 if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
367 expectedElementPath = new Path(TRACE_FOLDER).append(expectedElementPath);
368 }
369
370 checkOptions(options, expectedSourceLocation, expectedElementPath);
371 TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, getProjectName(), expectedElementPath);
372 if (testViews) {
373 testViews(tmfEd);
374 }
375
376 fBot.closeAllEditors();
377
378 SWTBotUtils.deleteProject(getProjectName(), fBot);
379 }
380
381 private void testImportAndExtractArchives(int options, boolean fromArchive) throws Exception {
382 createProject();
383
384 String expectedSourceLocation;
385 IPath expectedElementPath;
386 if (fromArchive) {
387 String testArchivePath = createNestedArchive();
388 openImportWizard();
389 selectImportFromArchive(testArchivePath);
390 selectFile(ARCHIVE_FILE_NAME, ARCHIVE_ROOT_ELEMENT_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME);
391
392 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
393 + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR;
394 expectedElementPath = new Path(TRACE_PROJECT_NAME).append(TRACE_FOLDER_PARENT_NAME).append(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
395 } else {
396 openImportWizard();
397 selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH);
398 selectFile(ARCHIVE_FILE_NAME, TRACE_FOLDER_PARENT_NAME);
399 expectedElementPath = new Path(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME);
400 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;
401 }
402
403 if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) == 0) {
404 expectedElementPath = new Path(TRACE_NAME);
405 }
406
407 setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
408 importFinish();
409 // Archives should never be imported as links
410 int expectedOptions = options & ~ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE;
411 checkOptions(expectedOptions, expectedSourceLocation, expectedElementPath);
412
413 TmfEventsEditor editor = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath);
414 testViews(editor);
415
416 SWTBotUtils.deleteProject(getProjectName(), fBot);
417 }
418
419 /**
420 * Create a temporary archive containing a nested archive. For example,
421 * testtraces.zip/synctraces.tar.gz can be used to test a nested archive.
422 */
423 private String createNestedArchive() throws IOException, CoreException, URISyntaxException {
424 // Link to the test traces folder. We use a link so that we can safely
425 // delete the entire project when we are done.
426 IProject project = getProjectResource();
427 String canonicalPath = new File(TRACE_FOLDER_PARENT_PATH).getCanonicalPath();
428 IFolder folder = project.getFolder(TRACE_FOLDER_PARENT_NAME);
429 folder.createLink(new Path(canonicalPath), IResource.REPLACE, null);
430 IFile file = folder.getFile(ARCHIVE_FILE_NAME);
431 return createArchive(file);
432 }
433
434 /**
435 * Create the empty archive from an empty folder
436 */
437 private String createEmptyArchive() throws CoreException, URISyntaxException {
438 return createArchive(createEmptyDirectory());
439 }
440
441 private IFolder createEmptyDirectory() throws CoreException {
442 IProject project = getProjectResource();
443 IFolder folder = project.getFolder(EMPTY_ARCHIVE_FOLDER);
444 folder.create(true, true, null);
445 return folder;
446 }
447
448 /**
449 * Create a temporary archive from the specified resource.
450 */
451 private static String createArchive(IResource sourceResource) throws URISyntaxException {
452 IPath exportedPath = sourceResource.getFullPath();
453
454 SWTBotTreeItem traceFilesProject = SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME);
455 traceFilesProject.contextMenu("Export...").click();
456
457 fBot.waitUntil(Conditions.shellIsActive("Export"));
458 SWTBotShell activeShell = fBot.activeShell();
459 SWTBotTree exportWizardsTree = fBot.tree();
460 SWTBotTreeItem treeItem = SWTBotUtils.getTreeItem(fBot, exportWizardsTree, "General", "Archive File");
461 treeItem.select();
462 fBot.button("Next >").click();
463 fBot.button("&Deselect All").click();
464
465 if (sourceResource instanceof IFile) {
466 String[] folderPath = exportedPath.removeLastSegments(1).segments();
467 String fileName = exportedPath.lastSegment();
468 selectFile(fileName, folderPath);
469 } else {
470 selectFolder(exportedPath.segments());
471 }
472
473 String workspacePath = URIUtil.toFile(URIUtil.fromString(System.getProperty("osgi.instance.area"))).getAbsolutePath();
474 final String archiveDestinationPath = workspacePath + File.separator + TRACE_PROJECT_NAME + File.separator + GENERATED_ARCHIVE_NAME;
475 fBot.comboBox().setText(archiveDestinationPath);
476 fBot.button("&Finish").click();
477 fBot.waitUntil(Conditions.shellCloses(activeShell));
478 return archiveDestinationPath;
479 }
480
481 private void testViews(TmfEventsEditor editor) {
482 testHistogramView(getViewPart("Histogram"), editor);
483 testPropertyView(getViewPart("Properties"));
484 testStatisticsView(getViewPart("Statistics"));
485 }
486
487 private static void openImportWizard() {
488 fWizard = new ImportTraceWizard();
489
490 UIThreadRunnable.asyncExec(new VoidResult() {
491 @Override
492 public void run() {
493 final IWorkbench workbench = PlatformUI.getWorkbench();
494 // Fire the Import Trace Wizard
495 if (workbench != null) {
496 final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
497 Shell shell = activeWorkbenchWindow.getShell();
498 assertNotNull(shell);
499 ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
500 WizardDialog dialog = new WizardDialog(shell, fWizard);
501 dialog.open();
502 }
503 }
504 });
505
506 fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
507 }
508
509 private static void selectImportFromDirectory(String directoryPath) {
510 SWTBotRadio button = fBot.radio("Select roo&t directory:");
511 button.click();
512
513 SWTBotCombo sourceCombo = fBot.comboBox();
514 File traceFolderParent = new File(directoryPath);
515 sourceCombo.setText(traceFolderParent.getAbsolutePath());
516
517 SWTBotText text = fBot.text();
518 text.setFocus();
519 }
520
521 private static void selectImportFromArchive(String archivePath) {
522 SWTBotRadio button = fBot.radio("Select &archive file:");
523 button.click();
524
525 SWTBotCombo sourceCombo = fBot.comboBox(1);
526
527 sourceCombo.setText(new File(archivePath).getAbsolutePath());
528
529 SWTBotText text = fBot.text();
530 text.setFocus();
531 }
532
533 private static void selectFolder(String... treePath) {
534 selectFolder(true, treePath);
535 }
536
537 private static void selectFolder(boolean check, String... treePath) {
538 SWTBotTree tree = fBot.tree();
539 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
540 SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, tree, treePath);
541 if (check) {
542 folderNode.check();
543 } else {
544 folderNode.select();
545 }
546 }
547
548 private static void selectFile(String fileName, String... folderTreePath) {
549 selectFolder(false, folderTreePath);
550
551 SWTBotTable fileTable = fBot.table();
552 fBot.waitUntil(Conditions.widgetIsEnabled(fileTable));
553 fBot.waitUntil(ConditionHelpers.isTableItemAvailable(fileName, fileTable));
554 SWTBotTableItem tableItem = fileTable.getTableItem(fileName);
555 tableItem.check();
556 }
557
558 private static void setOptions(int optionFlags, String traceTypeName) {
559 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
560 if (checkBox.isEnabled()) {
561 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) {
562 checkBox.select();
563 } else {
564 checkBox.deselect();
565 }
566 }
567
568 checkBox = fBot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure);
569 if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
570 checkBox.select();
571 } else {
572 checkBox.deselect();
573 }
574
575 checkBox = fBot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized);
576 if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
577 checkBox.select();
578 } else {
579 checkBox.deselect();
580 }
581
582 checkBox = fBot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace);
583 if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) {
584 checkBox.select();
585 } else {
586 checkBox.deselect();
587 }
588
589 SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
590 if (traceTypeName != null && !traceTypeName.isEmpty()) {
591 comboBox.setSelection(traceTypeName);
592 } else {
593 comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
594 }
595 }
596
597 private void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException {
598 IProject project = getProjectResource();
599 assertTrue(project.exists());
600 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
601 assertNotNull(tmfProject);
602 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
603 assertNotNull(tracesFolder);
604 List<TmfTraceElement> traces = tracesFolder.getTraces();
605 assertFalse(traces.isEmpty());
606 Collections.sort(traces, new Comparator<TmfTraceElement>() {
607 @Override
608 public int compare(TmfTraceElement arg0, TmfTraceElement arg1) {
609 return arg0.getElementPath().compareTo(arg1.getElementPath());
610 }
611 });
612
613 TmfTraceElement tmfTraceElement = traces.get(0);
614 IResource traceResource = tmfTraceElement.getResource();
615
616 assertEquals((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0, traceResource.isLinked());
617
618 // i.e. /Tracing/Traces
619 IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPath);
620 assertEquals(expectedPath, traceResource.getFullPath());
621
622 String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION);
623 assertNotNull(sourceLocation);
624 assertEquals(expectedSourceLocation, sourceLocation);
625 }
626
627 @Override
628 protected String getProjectName() {
629 return TRACE_PROJECT_NAME;
630 }
631
632 private IProject getProjectResource() {
633 return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName());
634 }
635 }
This page took 0.067249 seconds and 6 git commands to generate.