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