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