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