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
.setText(traceFolderParent
.getAbsolutePath());
55 SWTBotText text
= bot
.text();
60 * While in the import wizard, select the specified archive as a source.
65 * the archive path to set as a source
67 public static void selectImportFromArchive(SWTBot bot
, String archivePath
) {
68 SWTBotRadio button
= bot
.radio("Select &archive file:");
71 SWTBotCombo sourceCombo
= bot
.comboBox(1);
73 sourceCombo
.setText(new File(archivePath
).getAbsolutePath());
75 SWTBotText text
= bot
.text();
80 * While in the import wizard, select an item in the file selection control.
81 * The item can be a folder in the left tree or a file in the right table.
82 * The item will be checked.
87 * the path to the item, ending with a file or folder
89 public static void selectItem(SWTBot bot
, String
... treePath
) {
90 SWTBotTree tree
= bot
.tree();
91 bot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
92 if (treePath
.length
== 0) {
95 if (treePath
.length
== 1) {
96 SWTBotTreeItem rootNode
= SWTBotUtils
.getTreeItem(bot
, tree
, treePath
);
101 String
[] parentPath
= Arrays
.copyOf(treePath
, treePath
.length
- 1);
102 String itemName
= treePath
[treePath
.length
- 1];
103 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(bot
, tree
, parentPath
);
105 if (folderNode
.getNodes().contains(itemName
)) {
106 folderNode
= folderNode
.getNode(itemName
);
111 SWTBotTable fileTable
= bot
.table();
112 bot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
113 bot
.waitUntil(ConditionHelpers
.isTableItemAvailable(itemName
, fileTable
));
114 SWTBotTableItem tableItem
= fileTable
.getTableItem(itemName
);
120 * While in the import wizard, select a folder in the file selection tree.
125 * whether or not to check the folder item
127 * the path to the folder in the tree
129 public static void selectFolder(SWTBot bot
, boolean check
, String
... treePath
) {
130 SWTBotTree tree
= bot
.tree();
131 bot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
132 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(bot
, tree
, treePath
);
140 * While in the import wizard, select a file in the file selection tree.
145 * the name of the file to select
146 * @param folderTreePath
147 * the path to the parent folder in the tree
149 public static void selectFile(SWTBot bot
, String fileName
, String
... folderTreePath
) {
150 selectFolder(bot
, false, folderTreePath
);
152 SWTBotTable fileTable
= bot
.table();
153 bot
.waitUntil(Conditions
.widgetIsEnabled(fileTable
));
154 bot
.waitUntil(ConditionHelpers
.isTableItemAvailable(fileName
, fileTable
));
155 SWTBotTableItem tableItem
= fileTable
.getTableItem(fileName
);
160 * While in the import wizard, set the various options (checkboxes, trace
166 * options that affects mostly checkboxes, see
167 * {@link ImportTraceWizardPage#OPTION_CREATE_LINKS_IN_WORKSPACE}
169 * @param traceTypeName
170 * the trace type to select in the combobox, or null for
173 public static void setOptions(SWTBot bot
, int optionFlags
, String traceTypeName
) {
174 SWTBotCombo comboBox
= bot
.comboBoxWithLabel(Messages
.ImportTraceWizard_TraceType
);
175 if (traceTypeName
!= null && !traceTypeName
.isEmpty()) {
176 comboBox
.setSelection(traceTypeName
);
178 comboBox
.setSelection(ImportTraceWizardPage
.TRACE_TYPE_AUTO_DETECT
);
181 SWTBotCheckBox checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_CreateLinksInWorkspace
);
182 if (checkBox
.isEnabled()) {
183 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_LINKS_IN_WORKSPACE
) != 0) {
190 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_PreserveFolderStructure
);
191 if ((optionFlags
& ImportTraceWizardPage
.OPTION_PRESERVE_FOLDER_STRUCTURE
) != 0) {
197 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_ImportUnrecognized
);
198 if (checkBox
.isEnabled()) {
199 if ((optionFlags
& ImportTraceWizardPage
.OPTION_IMPORT_UNRECOGNIZED_TRACES
) != 0) {
206 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_OverwriteExistingTrace
);
207 if ((optionFlags
& ImportTraceWizardPage
.OPTION_OVERWRITE_EXISTING_RESOURCES
) != 0) {
213 checkBox
= bot
.checkBox(Messages
.ImportTraceWizard_CreateExperiment
);
214 if ((optionFlags
& ImportTraceWizardPage
.OPTION_CREATE_EXPERIMENT
) != 0) {
222 * Test that the events editor gets activated and that the first event is
228 * the expected name of the editor
230 * the expected number of events
231 * @param firstEventStr
232 * the first event timestamp in string form. This is used to see
233 * if the cell contains this text (String.contains()). Since
234 * there can be timezone issues with hours and days, this value
235 * should only specify minutes and more precise digits. For
236 * example: 04:32.650 993 664
238 public static void testEventsTable(SWTWorkbenchBot bot
, String editorName
, long nbEvents
, String firstEventStr
) {
239 SWTBotEditor editor
= SWTBotUtils
.activeEventsEditor(bot
, editorName
);
240 bot
.waitUntil(ConditionHelpers
.numberOfEventsInTrace(TmfTraceManager
.getInstance().getActiveTrace(), nbEvents
));
242 if (nbEvents
== 0 || firstEventStr
== null || firstEventStr
.isEmpty()) {
246 SWTBotTable table
= editor
.bot().table();
247 bot
.waitUntil(new DefaultCondition() {
249 public boolean test() throws Exception
{
250 return table
.rowCount() > 1;
254 public String
getFailureMessage() {
255 return "No items in table";
258 // Select first event (skip filter/search row)
259 table
.getTableItem(1).select();
261 editor
.bot().waitUntil(new DefaultCondition() {
263 public boolean test() throws Exception
{
264 boolean ret
= table
.selection().rowCount() == 1 && table
.selection().get(0).toString().contains(firstEventStr
);
266 // FIXME: Not sure why, sometimes the first select() ends up
267 // selecting an empty item. Retry selecting here.
268 table
.getTableItem(1).select();
274 public String
getFailureMessage() {
275 return "First event not selected.";