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 | |
93c91230 | 21 | import java.io.File; |
bbdb3d6d MAL |
22 | import java.io.IOException; |
23 | import java.net.URISyntaxException; | |
9b3f4afe MAL |
24 | import java.util.Collections; |
25 | import java.util.Comparator; | |
26 | import java.util.List; | |
27 | ||
bbdb3d6d | 28 | import org.eclipse.core.resources.IFolder; |
9b3f4afe MAL |
29 | import org.eclipse.core.resources.IProject; |
30 | import org.eclipse.core.resources.IResource; | |
31 | import org.eclipse.core.resources.ResourcesPlugin; | |
bbdb3d6d | 32 | import org.eclipse.core.runtime.CoreException; |
9b3f4afe | 33 | import org.eclipse.core.runtime.IPath; |
93c91230 | 34 | import org.eclipse.core.runtime.Path; |
bbdb3d6d | 35 | import org.eclipse.core.runtime.URIUtil; |
2f7b3dd7 BH |
36 | import org.eclipse.jface.viewers.StructuredSelection; |
37 | import org.eclipse.jface.wizard.WizardDialog; | |
2f7b3dd7 BH |
38 | import org.eclipse.swt.widgets.Shell; |
39 | import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable; | |
40 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
41 | import org.eclipse.swtbot.swt.finder.results.VoidResult; | |
42 | import org.eclipse.swtbot.swt.finder.waits.Conditions; | |
9b3f4afe | 43 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox; |
2f7b3dd7 | 44 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo; |
93c91230 | 45 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio; |
bbdb3d6d MAL |
46 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; |
47 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; | |
48 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem; | |
2f7b3dd7 BH |
49 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotText; |
50 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
51 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
2bdf0193 AM |
52 | import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard; |
53 | import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage; | |
54 | import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages; | |
bbdb3d6d | 55 | import org.eclipse.tracecompass.tmf.core.TmfCommonConstants; |
2bdf0193 AM |
56 | import org.eclipse.tracecompass.tmf.ui.editors.TmfEventsEditor; |
57 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement; | |
58 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectRegistry; | |
59 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement; | |
60 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder; | |
61 | import org.eclipse.tracecompass.tmf.ui.project.model.TmfTracesFolder; | |
fa24d78b AM |
62 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; |
63 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
2f7b3dd7 BH |
64 | import org.eclipse.ui.IWorkbench; |
65 | import org.eclipse.ui.IWorkbenchWindow; | |
66 | import org.eclipse.ui.PlatformUI; | |
67 | import org.junit.Test; | |
68 | import org.junit.runner.RunWith; | |
69 | ||
70 | /** | |
71 | * SWTBot Smoke test using ImportTraceWizard. | |
72 | * | |
73 | * @author Bernd Hufmann | |
74 | */ | |
75 | @RunWith(SWTBotJunit4ClassRunner.class) | |
76 | public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest { | |
77 | ||
93c91230 | 78 | private static final String TRACE_FOLDER_PARENT_PATH = fTrace.getPath() + File.separator + ".." + File.separator + ".." + File.separator; |
bbdb3d6d MAL |
79 | private static final String ARCHIVE_FILE_NAME = "synctraces.tar.gz"; |
80 | private static final String TRACE_ARCHIVE_PATH = TRACE_FOLDER_PARENT_PATH + ARCHIVE_FILE_NAME; | |
81 | private static final String TRACE_FOLDER_PARENT_NAME = "traces"; | |
2f7b3dd7 BH |
82 | private static final String TRACE_PROJECT_NAME = "Tracing"; |
83 | ||
bbdb3d6d MAL |
84 | private static final String ARCHIVE_ROOT_ELEMENT_NAME = "/"; |
85 | private static final String GENERATED_ARCHIVE_NAME = "testtraces.zip"; | |
86 | private static final String URI_SEPARATOR = "/"; | |
87 | private static final String URI_FILE_SCHEME = "file:"; | |
88 | private static final String URI_JAR_FILE_SCHEME = "jar:file:"; | |
89 | private static final boolean IS_WIN32 = System.getProperty("os.name").startsWith("Windows"); //$NON-NLS-1$//$NON-NLS-2$ | |
90 | private static final String URI_DEVICE_SEPARATOR = IS_WIN32 ? URI_SEPARATOR : ""; | |
91 | ||
2f7b3dd7 | 92 | /** |
9b3f4afe | 93 | * Test import from directory |
bbdb3d6d MAL |
94 | * |
95 | * @throws Exception | |
96 | * on error | |
2f7b3dd7 BH |
97 | */ |
98 | @Test | |
bbdb3d6d | 99 | public void testImportFromDirectory() throws Exception { |
9b3f4afe MAL |
100 | testImport(0, false, false); |
101 | } | |
2f7b3dd7 | 102 | |
9b3f4afe MAL |
103 | /** |
104 | * Test import from directory, create links | |
bbdb3d6d MAL |
105 | * |
106 | * @throws Exception | |
107 | * on error | |
9b3f4afe MAL |
108 | */ |
109 | @Test | |
bbdb3d6d | 110 | public void testImportFromDirectoryLinks() throws Exception { |
9b3f4afe MAL |
111 | testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false); |
112 | } | |
2f7b3dd7 | 113 | |
9b3f4afe MAL |
114 | /** |
115 | * Test import from directory, preserve folder structure | |
bbdb3d6d MAL |
116 | * |
117 | * @throws Exception | |
118 | * on error | |
9b3f4afe MAL |
119 | */ |
120 | @Test | |
bbdb3d6d | 121 | public void testImportFromDirectoryPreserveFolder() throws Exception { |
9b3f4afe MAL |
122 | testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, false); |
123 | } | |
2f7b3dd7 | 124 | |
9b3f4afe MAL |
125 | /** |
126 | * Test import from directory, create links, preserve folder structure | |
bbdb3d6d MAL |
127 | * |
128 | * @throws Exception | |
129 | * on error | |
9b3f4afe MAL |
130 | */ |
131 | @Test | |
bbdb3d6d | 132 | public void testImportFromDirectoryLinksPreserveFolder() throws Exception { |
9b3f4afe MAL |
133 | int options = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE; |
134 | testImport(options, false, false); | |
135 | } | |
93c91230 | 136 | |
9b3f4afe MAL |
137 | /** |
138 | * Test import from directory, overwrite all | |
bbdb3d6d MAL |
139 | * |
140 | * @throws Exception | |
141 | * on error | |
9b3f4afe MAL |
142 | */ |
143 | @Test | |
bbdb3d6d | 144 | public void testImportFromDirectoryOverwrite() throws Exception { |
9b3f4afe MAL |
145 | testImport(0, false, false); |
146 | testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false); | |
93c91230 MAL |
147 | } |
148 | ||
149 | /** | |
150 | * Test import from archive | |
bbdb3d6d MAL |
151 | * |
152 | * @throws Exception | |
153 | * on error | |
93c91230 MAL |
154 | */ |
155 | @Test | |
bbdb3d6d | 156 | public void testImportFromArchive() throws Exception { |
9b3f4afe MAL |
157 | testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true); |
158 | } | |
159 | ||
160 | /** | |
161 | * Test import from directory, preserve folder structure | |
bbdb3d6d | 162 | * @throws Exception on error |
9b3f4afe MAL |
163 | */ |
164 | @Test | |
bbdb3d6d | 165 | public void testImportFromArchivePreserveFolder() throws Exception { |
9b3f4afe MAL |
166 | testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true); |
167 | } | |
168 | ||
169 | /** | |
170 | * Test import from directory, overwrite all | |
bbdb3d6d MAL |
171 | * |
172 | * @throws Exception | |
173 | * on error | |
9b3f4afe MAL |
174 | */ |
175 | @Test | |
bbdb3d6d | 176 | public void testImportFromArchiveOverwrite() throws Exception { |
9b3f4afe MAL |
177 | testImport(0, false, true); |
178 | testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true); | |
179 | } | |
180 | ||
bbdb3d6d MAL |
181 | /** |
182 | * Test import from directory containing archives | |
183 | * | |
184 | * @throws Exception | |
185 | * on error | |
186 | */ | |
187 | @Test | |
188 | public void testExtractArchivesFromDirectory() throws Exception { | |
189 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false); | |
190 | } | |
191 | ||
192 | /** | |
193 | * Test import from directory containing archives, create links | |
194 | * @throws Exception on error | |
195 | */ | |
196 | @Test | |
197 | public void testExtractArchivesFromDirectoryLinks() throws Exception { | |
198 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false); | |
199 | } | |
200 | ||
201 | /** | |
202 | * Test import from directory containing archives, create links, preserve folder structure | |
203 | * @throws Exception on error | |
204 | */ | |
205 | @Test | |
206 | public void testExtractArchivesFromDirectoryLinksPreserveStruture() throws Exception { | |
207 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false); | |
208 | } | |
93c91230 | 209 | |
bbdb3d6d MAL |
210 | /** |
211 | * Test import from archive containing archives | |
212 | * | |
213 | * @throws Exception | |
214 | * on error | |
215 | */ | |
216 | @Test | |
217 | public void testExtractArchivesFromArchive() throws Exception { | |
218 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, true); | |
219 | } | |
220 | ||
221 | /** | |
222 | * Test import from archive containing archives, preserve folder structure | |
223 | * | |
224 | * @throws Exception | |
225 | * on error | |
226 | */ | |
227 | @Test | |
228 | public void testExtractArchivesFromArchivePreserveFolder() throws Exception { | |
229 | testImportAndExtractArchives(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true); | |
230 | } | |
231 | ||
232 | private void testImport(int options, boolean testViews, boolean fromArchive) throws Exception { | |
233 | createProject(); | |
234 | String expectedSourceLocation = null; | |
235 | openImportWizard(); | |
9b3f4afe | 236 | if (fromArchive) { |
bbdb3d6d MAL |
237 | 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; |
238 | selectImportFromArchive(TRACE_ARCHIVE_PATH); | |
239 | selectFolder(ARCHIVE_ROOT_ELEMENT_NAME); | |
240 | SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace); | |
241 | assertFalse(checkBox.isEnabled()); | |
9b3f4afe | 242 | } else { |
bbdb3d6d MAL |
243 | String sourcePath = TRACE_FOLDER_PARENT_PATH + File.separator + TRACE_FOLDER + File.separator + TRACE_NAME; |
244 | expectedSourceLocation = URI_FILE_SCHEME + URI_DEVICE_SEPARATOR + new Path(new File(sourcePath).getCanonicalPath()) + URI_SEPARATOR; | |
245 | selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH); | |
246 | selectFolder(new String [] {TRACE_FOLDER_PARENT_NAME, TRACE_FOLDER }); | |
9b3f4afe | 247 | } |
93c91230 | 248 | |
9b3f4afe | 249 | setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT); |
93c91230 MAL |
250 | importFinish(); |
251 | ||
bbdb3d6d MAL |
252 | IPath expectedElementPath = new Path(TRACE_NAME); |
253 | if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) { | |
254 | expectedElementPath = new Path(TRACE_FOLDER).append(expectedElementPath); | |
255 | } | |
256 | ||
257 | checkOptions(options, expectedSourceLocation, expectedElementPath); | |
258 | TmfEventsEditor tmfEd = SWTBotUtils.openEditor(fBot, getProjectName(), expectedElementPath); | |
9b3f4afe MAL |
259 | if (testViews) { |
260 | testViews(tmfEd); | |
261 | } | |
93c91230 | 262 | |
93c91230 MAL |
263 | fBot.closeAllEditors(); |
264 | ||
fa24d78b | 265 | SWTBotUtils.deleteProject(getProjectName(), fBot); |
93c91230 MAL |
266 | } |
267 | ||
bbdb3d6d MAL |
268 | private void testImportAndExtractArchives(int options, boolean fromArchive) throws Exception { |
269 | createProject(); | |
270 | ||
271 | String expectedSourceLocation; | |
272 | IPath expectedElementPath; | |
273 | if (fromArchive) { | |
274 | String testArchivePath = createArchive(); | |
275 | openImportWizard(); | |
276 | selectImportFromArchive(testArchivePath); | |
277 | selectFile(ARCHIVE_FILE_NAME, ARCHIVE_ROOT_ELEMENT_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME); | |
278 | ||
279 | 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 | |
280 | + URI_SEPARATOR + TRACE_FOLDER + URI_SEPARATOR + TRACE_NAME + URI_SEPARATOR; | |
281 | expectedElementPath = new Path(TRACE_PROJECT_NAME).append(TRACE_FOLDER_PARENT_NAME).append(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME); | |
282 | } else { | |
283 | openImportWizard(); | |
284 | selectImportFromDirectory(TRACE_FOLDER_PARENT_PATH); | |
285 | selectFile(ARCHIVE_FILE_NAME, TRACE_FOLDER_PARENT_NAME); | |
286 | expectedElementPath = new Path(ARCHIVE_FILE_NAME).append(TRACE_FOLDER).append(TRACE_NAME); | |
287 | 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; | |
288 | } | |
289 | ||
290 | if ((options & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) == 0) { | |
291 | expectedElementPath = new Path(TRACE_NAME); | |
292 | } | |
293 | ||
294 | setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT); | |
295 | importFinish(); | |
296 | // Archives should never be imported as links | |
297 | int expectedOptions = options & ~ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE; | |
298 | checkOptions(expectedOptions, expectedSourceLocation, expectedElementPath); | |
299 | ||
300 | TmfEventsEditor editor = SWTBotUtils.openEditor(fBot, TRACE_PROJECT_NAME, expectedElementPath); | |
301 | testViews(editor); | |
302 | ||
303 | SWTBotUtils.deleteProject(getProjectName(), fBot); | |
304 | } | |
305 | ||
306 | /** | |
307 | * Create a temporary archive containing a nested archive. For example, | |
308 | * testtraces.zip/synctraces.tar.gz can be used to test a nested archive. | |
309 | */ | |
310 | private String createArchive() throws URISyntaxException, CoreException, IOException { | |
311 | ||
312 | // Link to the test traces folder. We use a link so that we can safely | |
313 | // delete the entire project when we are done. | |
314 | IProject project = getProjectResource(); | |
315 | String canonicalPath = new File(TRACE_FOLDER_PARENT_PATH).getCanonicalPath(); | |
316 | IFolder folder = project.getFolder(TRACE_FOLDER_PARENT_NAME); | |
317 | folder.createLink(new Path(canonicalPath), IResource.REPLACE, null); | |
318 | ||
319 | SWTBotTreeItem traceFilesProject = SWTBotUtils.selectProject(fBot, TRACE_PROJECT_NAME); | |
320 | traceFilesProject.contextMenu("Export...").click(); | |
321 | ||
322 | fBot.waitUntil(Conditions.shellIsActive("Export")); | |
323 | SWTBotShell activeShell = fBot.activeShell(); | |
324 | SWTBotTree exportWizardsTree = fBot.tree(); | |
325 | SWTBotTreeItem treeItem = SWTBotUtils.getTreeItem(fBot, exportWizardsTree, "General", "Archive File"); | |
326 | treeItem.select(); | |
327 | fBot.button("Next >").click(); | |
328 | fBot.button("&Deselect All").click(); | |
329 | selectFile(ARCHIVE_FILE_NAME, TRACE_PROJECT_NAME, TRACE_FOLDER_PARENT_NAME); | |
330 | ||
331 | String workspacePath = URIUtil.toFile(URIUtil.fromString(System.getProperty("osgi.instance.area"))).getAbsolutePath(); | |
332 | final String archiveDestinationPath = workspacePath + File.separator + TRACE_PROJECT_NAME + File.separator + GENERATED_ARCHIVE_NAME; | |
333 | fBot.comboBox().setText(archiveDestinationPath); | |
334 | fBot.button("&Finish").click(); | |
335 | fBot.waitUntil(Conditions.shellCloses(activeShell)); | |
336 | return archiveDestinationPath; | |
337 | } | |
338 | ||
9b3f4afe MAL |
339 | private void testViews(TmfEventsEditor editor) { |
340 | testHistogramView(getViewPart("Histogram"), editor); | |
341 | testPropertyView(getViewPart("Properties")); | |
342 | testStatisticsView(getViewPart("Statistics")); | |
2f7b3dd7 BH |
343 | } |
344 | ||
bbdb3d6d | 345 | private static void openImportWizard() { |
2f7b3dd7 BH |
346 | fWizard = new ImportTraceWizard(); |
347 | ||
348 | UIThreadRunnable.asyncExec(new VoidResult() { | |
349 | @Override | |
350 | public void run() { | |
351 | final IWorkbench workbench = PlatformUI.getWorkbench(); | |
352 | // Fire the Import Trace Wizard | |
353 | if (workbench != null) { | |
354 | final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow(); | |
355 | Shell shell = activeWorkbenchWindow.getShell(); | |
356 | assertNotNull(shell); | |
357 | ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY); | |
358 | WizardDialog dialog = new WizardDialog(shell, fWizard); | |
359 | dialog.open(); | |
360 | } | |
361 | } | |
362 | }); | |
363 | ||
364 | fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard)); | |
365 | } | |
366 | ||
bbdb3d6d | 367 | private static void selectImportFromDirectory(String directoryPath) { |
93c91230 MAL |
368 | SWTBotRadio button = fBot.radio("Select roo&t directory:"); |
369 | button.click(); | |
370 | ||
2f7b3dd7 | 371 | SWTBotCombo sourceCombo = fBot.comboBox(); |
bbdb3d6d | 372 | File traceFolderParent = new File(directoryPath); |
93c91230 | 373 | sourceCombo.setText(traceFolderParent.getAbsolutePath()); |
2f7b3dd7 BH |
374 | |
375 | SWTBotText text = fBot.text(); | |
376 | text.setFocus(); | |
2f7b3dd7 BH |
377 | } |
378 | ||
bbdb3d6d | 379 | private static void selectImportFromArchive(String archivePath) { |
9b3f4afe MAL |
380 | SWTBotRadio button = fBot.radio("Select &archive file:"); |
381 | button.click(); | |
382 | ||
383 | SWTBotCombo sourceCombo = fBot.comboBox(1); | |
384 | ||
bbdb3d6d | 385 | sourceCombo.setText(new File(archivePath).getAbsolutePath()); |
9b3f4afe MAL |
386 | |
387 | SWTBotText text = fBot.text(); | |
388 | text.setFocus(); | |
bbdb3d6d | 389 | } |
9b3f4afe | 390 | |
bbdb3d6d | 391 | private static void selectFolder(String... treePath) { |
9b3f4afe MAL |
392 | SWTBotTree tree = fBot.tree(); |
393 | fBot.waitUntil(Conditions.widgetIsEnabled(tree)); | |
bbdb3d6d MAL |
394 | SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, tree, treePath); |
395 | folderNode.check(); | |
396 | } | |
9b3f4afe | 397 | |
bbdb3d6d MAL |
398 | private static void selectFile(String fileName, String... folderTreePath) { |
399 | SWTBotTree folderTree = fBot.tree(); | |
400 | fBot.waitUntil(Conditions.widgetIsEnabled(folderTree)); | |
401 | SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, folderTree, folderTreePath); | |
402 | folderNode.select(); | |
403 | ||
404 | SWTBotTable fileTable = fBot.table(); | |
405 | fBot.waitUntil(Conditions.widgetIsEnabled(fileTable)); | |
406 | fBot.waitUntil(ConditionHelpers.isTableItemAvailable(fileName, fileTable)); | |
407 | SWTBotTableItem tableItem = fileTable.getTableItem(fileName); | |
408 | tableItem.check(); | |
2f7b3dd7 BH |
409 | } |
410 | ||
9b3f4afe MAL |
411 | private static void setOptions(int optionFlags, String traceTypeName) { |
412 | SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace); | |
413 | if (checkBox.isEnabled()) { | |
414 | if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) { | |
415 | checkBox.select(); | |
416 | } else { | |
417 | checkBox.deselect(); | |
418 | } | |
419 | } | |
420 | ||
421 | checkBox = fBot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure); | |
422 | if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) { | |
423 | checkBox.select(); | |
424 | } else { | |
425 | checkBox.deselect(); | |
426 | } | |
427 | ||
428 | checkBox = fBot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized); | |
429 | if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) { | |
430 | checkBox.select(); | |
431 | } else { | |
432 | checkBox.deselect(); | |
433 | } | |
434 | ||
435 | checkBox = fBot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace); | |
436 | if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) { | |
437 | checkBox.select(); | |
438 | } else { | |
439 | checkBox.deselect(); | |
440 | } | |
441 | ||
442 | SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType); | |
443 | if (traceTypeName != null && !traceTypeName.isEmpty()) { | |
444 | comboBox.setSelection(traceTypeName); | |
445 | } else { | |
446 | comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT); | |
447 | } | |
93c91230 MAL |
448 | } |
449 | ||
bbdb3d6d MAL |
450 | private void checkOptions(int optionFlags, String expectedSourceLocation, IPath expectedElementPath) throws CoreException { |
451 | IProject project = getProjectResource(); | |
9b3f4afe MAL |
452 | assertTrue(project.exists()); |
453 | TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true); | |
454 | assertNotNull(tmfProject); | |
455 | TmfTraceFolder tracesFolder = tmfProject.getTracesFolder(); | |
456 | assertNotNull(tracesFolder); | |
457 | List<TmfTraceElement> traces = tracesFolder.getTraces(); | |
458 | assertFalse(traces.isEmpty()); | |
459 | Collections.sort(traces, new Comparator<TmfTraceElement>() { | |
460 | @Override | |
461 | public int compare(TmfTraceElement arg0, TmfTraceElement arg1) { | |
462 | return arg0.getElementPath().compareTo(arg1.getElementPath()); | |
463 | } | |
464 | }); | |
465 | ||
466 | TmfTraceElement tmfTraceElement = traces.get(0); | |
467 | IResource traceResource = tmfTraceElement.getResource(); | |
468 | ||
469 | assertEquals((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0, traceResource.isLinked()); | |
470 | ||
471 | // i.e. /Tracing/Traces | |
bbdb3d6d | 472 | IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME).append(expectedElementPath); |
9b3f4afe | 473 | assertEquals(expectedPath, traceResource.getFullPath()); |
9b3f4afe | 474 | |
bbdb3d6d MAL |
475 | String sourceLocation = traceResource.getPersistentProperty(TmfCommonConstants.SOURCE_LOCATION); |
476 | assertNotNull(sourceLocation); | |
477 | assertEquals(expectedSourceLocation, sourceLocation); | |
9b3f4afe MAL |
478 | } |
479 | ||
480 | @Override | |
481 | protected String getProjectName() { | |
482 | return TRACE_PROJECT_NAME; | |
483 | } | |
bbdb3d6d MAL |
484 | |
485 | private IProject getProjectResource() { | |
486 | return ResourcesPlugin.getWorkspace().getRoot().getProject(getProjectName()); | |
487 | } | |
2f7b3dd7 | 488 | } |