1 /******************************************************************************
2 * Copyright (c) 2015 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.tmf
.ctf
.ui
.swtbot
.tests
;
13 import java
.util
.Arrays
;
15 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
16 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotEditor
;
17 import org
.eclipse
.swtbot
.swt
.finder
.SWTBot
;
18 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
19 import org
.eclipse
.swtbot
.swt
.finder
.waits
.DefaultCondition
;
20 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCheckBox
;
21 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCombo
;
22 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotRadio
;
23 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
24 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTableItem
;
25 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
26 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
27 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
28 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizardPage
;
29 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.Messages
;
30 import org
.eclipse
.tracecompass
.tmf
.core
.trace
.TmfTraceManager
;
31 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
32 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
35 * Several SWTBot utility methods common to testing import test cases.
37 public final class SWTBotImportWizardUtils
{
40 * While in the import wizard, select the specified directory as a source.
44 * @param directoryPath
45 * the directory path to set as a source
47 public static void selectImportFromDirectory(SWTBot bot
, String directoryPath
) {
48 SWTBotRadio button
= bot
.radio("Select roo&t directory:");
51 SWTBotCombo sourceCombo
= bot
.comboBox();
52 File traceFolderParent
= new File(directoryPath
);
53 sourceCombo
.setFocus();
54 sourceCombo
.setText(traceFolderParent
.getAbsolutePath());
56 /* the resource tree gets updated when the combo loses focus */
57 SWTBotText text
= bot
.text();
62 * While in the import wizard, select the specified archive as a source.
67 * the archive path to set as a source
69 public static void selectImportFromArchive(SWTBot bot
, String archivePath
) {
70 SWTBotRadio button
= bot
.radio("Select &archive file:");
73 SWTBotCombo sourceCombo
= bot
.comboBox(1);
75 sourceCombo
.setFocus();
76 sourceCombo
.setText(new File(archivePath
).getAbsolutePath());
78 /* the resource tree gets updated when the combo loses focus */
79 SWTBotText text
= bot
.text();
84 * While in the import wizard, select an item in the file selection control.
85 * The item can be a folder in the left tree or a file in the right table.
86 * The item will be checked.
91 * the path to the item, ending with a file or folder
93 public static void selectItem(SWTBot bot
, String
... treePath
) {
94 SWTBotTree tree
= bot
.tree();
95 bot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
96 if (treePath
.length
== 0) {
99 if (treePath
.length
== 1) {
100 SWTBotTreeItem rootNode
= SWTBotUtils
.getTreeItem(bot
, tree
, treePath
);
105 String
[] parentPath
= Arrays
.copyOf(treePath
, treePath
.length
- 1);
106 String itemName
= treePath
[treePath
.length
- 1];
107 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(bot
, tree
, parentPath
);
109 if (folderNode
.getNodes().contains(itemName
)) {
110 folderNode
= folderNode
.getNode(itemName
);
115 SWTBotTable fileTable
= bot
.table();
116 bot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
117 bot
.waitUntil(ConditionHelpers
.isTableItemAvailable(itemName
, fileTable
));
118 SWTBotTableItem tableItem
= fileTable
.getTableItem(itemName
);
124 * While in the import wizard, select a folder in the file selection tree.
129 * whether or not to check the folder item
131 * the path to the folder in the tree
133 public static void selectFolder(SWTBot bot
, boolean check
, String
... treePath
) {
134 SWTBotTree tree
= bot
.tree();
135 bot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
136 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(bot
, tree
, treePath
);
144 * While in the import wizard, select a file in the file selection tree.
149 * the name of the file to select
150 * @param folderTreePath
151 * the path to the parent folder in the tree
153 public static void selectFile(SWTBot bot
, String fileName
, String
... folderTreePath
) {
154 selectFolder(bot
, false, folderTreePath
);
156 SWTBotTable fileTable
= bot
.table();
157 bot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
158 bot
.waitUntil(ConditionHelpers
.isTableItemAvailable(fileName
, fileTable
));
159 SWTBotTableItem tableItem
= fileTable
.getTableItem(fileName
);
164 * While in the import wizard, set the various options (checkboxes, trace
170 * options that affects mostly checkboxes, see
171 * {@link ImportTraceWizardPage#OPTION_CREATE_LINKS_IN_WORKSPACE}
173 * @param traceTypeName
174 * the trace type to select in the combobox, or null for
177 public static void setOptions(SWTBot bot
, int optionFlags
, String traceTypeName
) {
178 SWTBotCombo comboBox
= bot
.comboBoxWithLabel(Messages
.ImportTraceWizard_TraceType
);
179 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
180 comboBox
.setSelection(traceTypeName
);
182 comboBox
.setSelection(ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
185 SWTBotCheckBox checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_CreateLinksInWorkspace
);
186 if (checkBox
.isEnabled()) {
187 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0) {
194 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_PreserveFolderStructure
);
195 if ((optionFlags
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
201 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_ImportUnrecognized
);
202 if (checkBox
.isEnabled()) {
203 if ((optionFlags
& ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
) != 0) {
210 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_OverwriteExistingTrace
);
211 if ((optionFlags
& ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
) != 0) {
217 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_CreateExperiment
);
218 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
) != 0) {
226 * Test that the events editor gets activated and that the first event is
232 * the expected name of the editor
234 * the expected number of events
235 * @param firstEventStr
236 * the first event timestamp in string form. This is used to see
237 * if the cell contains this text (String.contains()). Since
238 * there can be timezone issues with hours and days, this value
239 * should only specify minutes and more precise digits. For
240 * example: 04:32.650 993 664
242 public static void testEventsTable(SWTWorkbenchBot bot
, String editorName
, long nbEvents
, String firstEventStr
) {
243 SWTBotEditor editor
= SWTBotUtils
.activeEventsEditor(bot
, editorName
);
244 bot
.waitUntil(ConditionHelpers
.numberOfEventsInTrace(TmfTraceManager
.getInstance().getActiveTrace(), nbEvents
));
246 if (nbEvents
== 0 || firstEventStr
== null || firstEventStr
.isEmpty()) {
250 SWTBotTable table
= editor
.bot().table();
251 bot
.waitUntil(new DefaultCondition() {
253 public boolean test() throws Exception
{
254 return table
.rowCount() > 1;
258 public String
getFailureMessage() {
259 return "No items in table";
262 // Select first event (skip filter/search row)
263 table
.getTableItem(1).select();
265 editor
.bot().waitUntil(new DefaultCondition() {
267 public boolean test() throws Exception
{
268 boolean ret
= table
.selection().rowCount() == 1 && table
.selection().get(0).toString().contains(firstEventStr
);
270 // FIXME: Not sure why, sometimes the first select() ends up
271 // selecting an empty item. Retry selecting here.
272 table
.getTableItem(1).select();
278 public String
getFailureMessage() {
279 return "First event not selected.";