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; |
2f7b3dd7 | 51 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo; |
93c91230 | 52 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; |
bbdb3d6d MAL |
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; | |
2f7b3dd7 BH |
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; | |
fa74050c | 59 | import org.eclipse.swtbot.swt.finder.widgets.TimeoutException; |
2bdf0193 AM |
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; | |
bbdb3d6d | 63 | import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; |
2bdf0193 | 64 | import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
40ba27e1 BH |
65 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement; |
66 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentFolder; | |
2bdf0193 AM |
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; | |
fa24d78b AM |
72 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
73 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
2f7b3dd7 BH |
74 | import org.eclipse.ui.IWorkbench; |
75 | import org.eclipse.ui.IWorkbenchWindow; | |
76 | import org.eclipse.ui.PlatformUI; | |
29fe7911 MAL |
77 | import org.junit.AfterClass; |
78 | import org.junit.BeforeClass; | |
2f7b3dd7 BH |
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 | ||
c4d57ac1 | 90 | private static final String TRACE_FOLDER_PARENT_PATH = "../../ctf/org.eclipse.tracecompass.ctf.core.tests/traces/"; |
bbdb3d6d | 91 | private static final String ARCHIVE_FILE_NAME = "synctraces.tar.gz"; |
d34c9ed8 | 92 | private static final String EMPTY_ARCHIVE_FOLDER = "emptyArchiveFolder"; |
fc4a373f | 93 | private static final String EMPTY_FILE_NAME = "emptyFile"; |
bbdb3d6d MAL |
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"; | |
2f7b3dd7 BH |
96 | private static final String TRACE_PROJECT_NAME = "Tracing"; |
97 | ||
bbdb3d6d MAL |
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 | ||
29fe7911 MAL |
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 | ||
2f7b3dd7 | 118 | /** |
9b3f4afe | 119 | * Test import from directory |
bbdb3d6d MAL |
120 | * |
121 | * @throws Exception | |
122 | * on error | |
2f7b3dd7 BH |
123 | */ |
124 | @Test | |
bbdb3d6d | 125 | public void testImportFromDirectory() throws Exception { |
9b3f4afe MAL |
126 | testImport(0, false, false); |
127 | } | |
2f7b3dd7 | 128 | |
9b3f4afe MAL |
129 | /** |
130 | * Test import from directory, create links | |
bbdb3d6d MAL |
131 | * |
132 | * @throws Exception | |
133 | * on error | |
9b3f4afe MAL |
134 | */ |
135 | @Test | |
bbdb3d6d | 136 | public void testImportFromDirectoryLinks() throws Exception { |
9b3f4afe MAL |
137 | testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false); |
138 | } | |
2f7b3dd7 | 139 | |
40ba27e1 BH |
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 | ||
9b3f4afe MAL |
162 | /** |
163 | * Test import from directory, preserve folder structure | |
bbdb3d6d MAL |
164 | * |
165 | * @throws Exception | |
166 | * on error | |
9b3f4afe MAL |
167 | */ |
168 | @Test | |
bbdb3d6d | 169 | public void testImportFromDirectoryPreserveFolder() throws Exception { |
9b3f4afe MAL |
170 | testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, false); |
171 | } | |
2f7b3dd7 | 172 | |
9b3f4afe MAL |
173 | /** |
174 | * Test import from directory, create links, preserve folder structure | |
bbdb3d6d MAL |
175 | * |
176 | * @throws Exception | |
177 | * on error | |
9b3f4afe MAL |
178 | */ |
179 | @Test | |
bbdb3d6d | 180 | public void testImportFromDirectoryLinksPreserveFolder() throws Exception { |
9b3f4afe MAL |
181 | int options = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE; |
182 | testImport(options, false, false); | |
183 | } | |
93c91230 | 184 | |
9b3f4afe MAL |
185 | /** |
186 | * Test import from directory, overwrite all | |
bbdb3d6d MAL |
187 | * |
188 | * @throws Exception | |
189 | * on error | |
9b3f4afe MAL |
190 | */ |
191 | @Test | |
bbdb3d6d | 192 | public void testImportFromDirectoryOverwrite() throws Exception { |
9b3f4afe MAL |
193 | testImport(0, false, false); |
194 | testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false); | |
93c91230 MAL |
195 | } |
196 | ||
197 | /** | |
198 | * Test import from archive | |
bbdb3d6d MAL |
199 | * |
200 | * @throws Exception | |
201 | * on error | |
93c91230 MAL |
202 | */ |
203 | @Test | |
bbdb3d6d | 204 | public void testImportFromArchive() throws Exception { |
9b3f4afe MAL |
205 | testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true); |
206 | } | |
207 | ||
40ba27e1 BH |
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 | ||
9b3f4afe MAL |
219 | /** |
220 | * Test import from directory, preserve folder structure | |
bbdb3d6d | 221 | * @throws Exception on error |
9b3f4afe MAL |
222 | */ |
223 | @Test | |
bbdb3d6d | 224 | public void testImportFromArchivePreserveFolder() throws Exception { |
9b3f4afe MAL |
225 | testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true); |
226 | } | |
227 | ||
228 | /** | |
229 | * Test import from directory, overwrite all | |
bbdb3d6d MAL |
230 | * |
231 | * @throws Exception | |
232 | * on error | |
9b3f4afe MAL |
233 | */ |
234 | @Test | |
bbdb3d6d | 235 | public void testImportFromArchiveOverwrite() throws Exception { |
9b3f4afe MAL |
236 | testImport(0, false, true); |
237 | testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true); | |
238 | } | |
239 | ||
bbdb3d6d MAL |
240 | /** |
241 | * Test import from directory containing archives | |
242 | * | |
243 | * @throws Exception | |
244 | * on error | |
245 | */ | |
246 | @Test | |
247 | public void testExtractArchivesFromDirectory() throws Exception { | |
29fe7911 | 248 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false); |
bbdb3d6d MAL |
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 { | |
29fe7911 | 257 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false); |
bbdb3d6d MAL |
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 { | |
29fe7911 | 266 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, false); |
bbdb3d6d | 267 | } |
93c91230 | 268 | |
bbdb3d6d MAL |
269 | /** |
270 | * Test import from archive containing archives | |
271 | * | |
272 | * @throws Exception | |
273 | * on error | |
274 | */ | |
275 | @Test | |
276 | public void testExtractArchivesFromArchive() throws Exception { | |
29fe7911 | 277 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true); |
bbdb3d6d MAL |
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 { | |
29fe7911 | 288 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true); |
bbdb3d6d MAL |
289 | } |
290 | ||
d34c9ed8 PT |
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 { | |
d34c9ed8 PT |
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 | ||
29fe7911 MAL |
309 | SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); |
310 | Files.delete(Paths.get(testArchivePath)); | |
d34c9ed8 PT |
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 { | |
29fe7911 MAL |
321 | IFolder emptyDirectory = createEmptyDirectory(); |
322 | String testDirectoryPath = emptyDirectory.getLocation().toOSString(); | |
d34c9ed8 PT |
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 | ||
29fe7911 MAL |
332 | Files.delete(Paths.get(testDirectoryPath)); |
333 | emptyDirectory.delete(true, null); | |
334 | SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); | |
d34c9ed8 PT |
335 | } |
336 | ||
fc4a373f BH |
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 { | |
fc4a373f BH |
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 | ||
29fe7911 MAL |
356 | SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); |
357 | folder.delete(true, null); | |
fc4a373f BH |
358 | } |
359 | ||
d34c9ed8 PT |
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 { | |
29fe7911 | 368 | String testArchivePath = createEmptyArchive(); |
d34c9ed8 PT |
369 | |
370 | openImportWizard(); | |
371 | selectImportFromDirectory(getProjectResource().getLocation().toOSString()); | |
29fe7911 | 372 | selectFile(GENERATED_ARCHIVE_NAME, TRACE_PROJECT_NAME); |
d34c9ed8 PT |
373 | setOptions(0, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT); |
374 | importFinish(); | |
375 | ||
376 | assertNoTraces(); | |
377 | ||
29fe7911 MAL |
378 | SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); |
379 | Files.delete(Paths.get(testArchivePath)); | |
d34c9ed8 PT |
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 { | |
d34c9ed8 PT |
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); | |
29fe7911 | 405 | renamedArchiveFile.delete(true, null); |
d34c9ed8 PT |
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 | ||
29fe7911 MAL |
415 | SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); |
416 | Files.delete(Paths.get(testArchivePath)); | |
d34c9ed8 PT |
417 | } |
418 | ||
29fe7911 | 419 | private static void assertNoTraces() { |
d34c9ed8 PT |
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 | ||
bbdb3d6d | 428 | private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception { |
40ba27e1 BH |
429 | testImport(options, testViews, fromArchive, true); |
430 | } | |
431 | ||
432 | private void testImport(int options, boolean testViews, boolean fromArchive, boolean defaultExperiment) throws Exception { | |
bbdb3d6d | 433 | String expectedSourceLocation = null; |
40ba27e1 BH |
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 | ||
bbdb3d6d | 446 | openImportWizard(); |
9b3f4afe | 447 | if (fromArchive) { |
bbdb3d6d MAL |
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()); | |
9b3f4afe | 453 | } else { |
bbdb3d6d MAL |
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 }); | |
9b3f4afe | 458 | } |
93c91230 | 459 | |
9b3f4afe | 460 | setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT); |
40ba27e1 BH |
461 | |
462 | if (!defaultExperiment) { | |
463 | experimentName = verifyExperimentNameHandling(experimentName); | |
464 | } | |
465 | checkFinishButton(true); | |
466 | ||
93c91230 MAL |
467 | importFinish(); |
468 | ||
bbdb3d6d MAL |
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 | ||
40ba27e1 | 474 | checkOptions(options, expectedSourceLocation, expectedElementPath, experimentName); |
29fe7911 | 475 | TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath); |
9b3f4afe MAL |
476 | if (testViews) { |
477 | testViews(tmfEd); | |
478 | } | |
93c91230 | 479 | |
93c91230 MAL |
480 | fBot.closeAllEditors(); |
481 | ||
40ba27e1 | 482 | SWTBotUtils.clearExperimentFolder(fBot, TRACE_PROJECT_NAME); |
29fe7911 | 483 | SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); |
93c91230 MAL |
484 | } |
485 | ||
29fe7911 | 486 | private void testImportAndExtractArchives(int options, boolean testViews, boolean fromArchive) throws Exception { |
bbdb3d6d MAL |
487 | String expectedSourceLocation; |
488 | IPath expectedElementPath; | |
29fe7911 | 489 | String testArchivePath = null; |
bbdb3d6d | 490 | if (fromArchive) { |
29fe7911 | 491 | testArchivePath = createNestedArchive(); |
bbdb3d6d MAL |
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); | |
29fe7911 MAL |
518 | if (testViews) { |
519 | testViews(editor); | |
520 | } | |
bbdb3d6d | 521 | |
40ba27e1 BH |
522 | SWTBotUtils.clearExperimentFolder(fBot, TRACE_PROJECT_NAME); |
523 | ||
29fe7911 MAL |
524 | SWTBotUtils.clearTracesFolder(fBot, TRACE_PROJECT_NAME); |
525 | if (testArchivePath != null) { | |
526 | Files.delete(Paths.get(testArchivePath)); | |
527 | } | |
bbdb3d6d MAL |
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 | */ | |
29fe7911 | 534 | private static String createNestedArchive() throws IOException, CoreException, URISyntaxException { |
bbdb3d6d MAL |
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); | |
d34c9ed8 | 541 | IFile file = folder.getFile(ARCHIVE_FILE_NAME); |
29fe7911 MAL |
542 | String archivePath = createArchive(file); |
543 | folder.delete(true, null); | |
544 | return archivePath; | |
d34c9ed8 PT |
545 | } |
546 | ||
547 | /** | |
548 | * Create the empty archive from an empty folder | |
549 | */ | |
29fe7911 MAL |
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; | |
d34c9ed8 PT |
555 | } |
556 | ||
29fe7911 | 557 | private static IFolder createEmptyDirectory() throws CoreException { |
d34c9ed8 PT |
558 | IProject project = getProjectResource(); |
559 | IFolder folder = project.getFolder(EMPTY_ARCHIVE_FOLDER); | |
560 | folder.create(true, true, null); | |
561 | return folder; | |
562 | } | |
563 | ||
fc4a373f BH |
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 | ||
d34c9ed8 PT |
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(); | |
bbdb3d6d MAL |
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(); | |
13e9acb6 | 586 | try { |
fa74050c MAL |
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) { | |
13e9acb6 MAL |
591 | // Ignore, doesn't exist pre-4.6M5 |
592 | } | |
d34c9ed8 PT |
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 | } | |
bbdb3d6d MAL |
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 | ||
9b3f4afe MAL |
610 | private void testViews(TmfEventsEditor editor) { |
611 | testHistogramView(getViewPart("Histogram"), editor); | |
612 | testPropertyView(getViewPart("Properties")); | |
613 | testStatisticsView(getViewPart("Statistics")); | |
2f7b3dd7 BH |
614 | } |
615 | ||
bbdb3d6d | 616 | private static void openImportWizard() { |
2f7b3dd7 BH |
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 | ||
bbdb3d6d | 638 | private static void selectImportFromDirectory(String directoryPath) { |
93c91230 MAL |
639 | SWTBotRadio button = fBot.radio("Select roo&t directory:"); |
640 | button.click(); | |
641 | ||
2f7b3dd7 | 642 | SWTBotCombo sourceCombo = fBot.comboBox(); |
bbdb3d6d | 643 | File traceFolderParent = new File(directoryPath); |
93c91230 | 644 | sourceCombo.setText(traceFolderParent.getAbsolutePath()); |
2f7b3dd7 BH |
645 | |
646 | SWTBotText text = fBot.text(); | |
647 | text.setFocus(); | |
2f7b3dd7 BH |
648 | } |
649 | ||
bbdb3d6d | 650 | private static void selectImportFromArchive(String archivePath) { |
9b3f4afe MAL |
651 | SWTBotRadio button = fBot.radio("Select &archive file:"); |
652 | button.click(); | |
653 | ||
654 | SWTBotCombo sourceCombo = fBot.comboBox(1); | |
655 | ||
bbdb3d6d | 656 | sourceCombo.setText(new File(archivePath).getAbsolutePath()); |
9b3f4afe MAL |
657 | |
658 | SWTBotText text = fBot.text(); | |
659 | text.setFocus(); | |
bbdb3d6d | 660 | } |
9b3f4afe | 661 | |
bbdb3d6d | 662 | private static void selectFolder(String... treePath) { |
d34c9ed8 PT |
663 | selectFolder(true, treePath); |
664 | } | |
665 | ||
666 | private static void selectFolder(boolean check, String... treePath) { | |
9b3f4afe MAL |
667 | SWTBotTree tree = fBot.tree(); |
668 | fBot.waitUntil(Conditions.widgetIsEnabled(tree)); | |
bbdb3d6d | 669 | SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, tree, treePath); |
d34c9ed8 PT |
670 | if (check) { |
671 | folderNode.check(); | |
672 | } else { | |
673 | folderNode.select(); | |
674 | } | |
bbdb3d6d | 675 | } |
9b3f4afe | 676 | |
bbdb3d6d | 677 | private static void selectFile(String fileName, String... folderTreePath) { |
d34c9ed8 | 678 | selectFolder(false, folderTreePath); |
bbdb3d6d MAL |
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(); | |
2f7b3dd7 BH |
685 | } |
686 | ||
9b3f4afe MAL |
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 | ||
40ba27e1 BH |
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 | ||
9b3f4afe MAL |
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 | } | |
93c91230 MAL |
731 | } |
732 | ||
29fe7911 | 733 | private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException { |
40ba27e1 BH |
734 | checkOptions(optionFlags, expectedSourceLocation, expectedElementPath, null); |
735 | } | |
736 | ||
737 | private static void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath, String experimentName) throws CoreException { | |
bbdb3d6d | 738 | IProject project = getProjectResource(); |
9b3f4afe MAL |
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 | |
bbdb3d6d | 759 | IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPath); |
9b3f4afe | 760 | assertEquals(expectedPath, traceResource.getFullPath()); |
9b3f4afe | 761 | |
bbdb3d6d MAL |
762 | String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION); |
763 | assertNotNull(sourceLocation); | |
764 | assertEquals(expectedSourceLocation, sourceLocation); | |
40ba27e1 BH |
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 | } | |
9b3f4afe MAL |
777 | } |
778 | ||
29fe7911 MAL |
779 | private static IProject getProjectResource() { |
780 | return ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME); | |
bbdb3d6d | 781 | } |
40ba27e1 BH |
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 | ||
2f7b3dd7 | 805 | } |