fcdddf7ccca242f948e8f8b0dde14ad5e73456e5
[deliverable/tracecompass.git] / ctf / org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ctf / ui / swtbot / tests / SWTBotImportWizardUtils.java
1 /******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 package org.eclipse.tracecompass.tmf.ctf.ui.swtbot.tests;
11
12 import java.io.File;
13
14 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
15 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
16 import org.eclipse.swtbot.swt.finder.SWTBot;
17 import org.eclipse.swtbot.swt.finder.waits.Conditions;
18 import org.eclipse.swtbot.swt.finder.waits.DefaultCondition;
19 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
20 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
21 import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
22 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
23 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTableItem;
24 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
25 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
26 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
27 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
28 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
29 import org.eclipse.tracecompass.tmf.core.trace.TmfTraceManager;
30 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
31 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
32
33 /**
34 * Several SWTBot utility methods common to testing import test cases.
35 */
36 public final class SWTBotImportWizardUtils {
37
38 /**
39 * While in the import wizard, select the specified directory as a source.
40 *
41 * @param bot
42 * the SWTBot
43 * @param directoryPath
44 * the directory path to set as a source
45 */
46 public static void selectImportFromDirectory(SWTBot bot, String directoryPath) {
47 SWTBotRadio button = bot.radio("Select roo&t directory:");
48 button.click();
49
50 SWTBotCombo sourceCombo = bot.comboBox();
51 File traceFolderParent = new File(directoryPath);
52 sourceCombo.setText(traceFolderParent.getAbsolutePath());
53
54 SWTBotText text = bot.text();
55 text.setFocus();
56 }
57
58 /**
59 * While in the import wizard, select the specified archive as a source.
60 *
61 * @param bot
62 * the SWTBot
63 * @param archivePath
64 * the archive path to set as a source
65 */
66 public static void selectImportFromArchive(SWTBot bot, String archivePath) {
67 SWTBotRadio button = bot.radio("Select &archive file:");
68 button.click();
69
70 SWTBotCombo sourceCombo = bot.comboBox(1);
71
72 sourceCombo.setText(new File(archivePath).getAbsolutePath());
73
74 SWTBotText text = bot.text();
75 text.setFocus();
76 }
77
78 /**
79 * While in the import wizard, select a folder in the file selection tree.
80 *
81 * @param bot
82 * the SWTBot
83 * @param check
84 * whether or not to check the folder item
85 * @param treePath
86 * the path to the folder in the tree
87 */
88 public static void selectFolder(SWTBot bot, boolean check, String... treePath) {
89 SWTBotTree tree = bot.tree();
90 bot.waitUntil(Conditions.widgetIsEnabled(tree));
91 SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(bot, tree, treePath);
92 folderNode.select();
93 if (check) {
94 folderNode.check();
95 }
96 }
97
98 /**
99 * While in the import wizard, select a file in the file selection tree.
100 *
101 * @param bot
102 * the SWTBot
103 * @param fileName
104 * the name of the file to select
105 * @param folderTreePath
106 * the path to the parent folder in the tree
107 */
108 public static void selectFile(SWTBot bot, String fileName, String... folderTreePath) {
109 selectFolder(bot, false, folderTreePath);
110
111 SWTBotTable fileTable = bot.table();
112 bot.waitUntil(Conditions.widgetIsEnabled(fileTable));
113 bot.waitUntil(ConditionHelpers.isTableItemAvailable(fileName, fileTable));
114 SWTBotTableItem tableItem = fileTable.getTableItem(fileName);
115 tableItem.check();
116 }
117
118 /**
119 * While in the import wizard, set the various options (checkboxes, trace
120 * type combo).
121 *
122 * @param bot
123 * the SWTBot
124 * @param optionFlags
125 * options that affects mostly checkboxes, see
126 * {@link ImportTraceWizardPage#OPTION_CREATE_LINKS_IN_WORKSPACE}
127 * for example.
128 * @param traceTypeName
129 * the trace type to select in the combobox, or null for
130 * auto-detect.
131 */
132 public static void setOptions(SWTBot bot, int optionFlags, String traceTypeName) {
133 SWTBotCombo comboBox = bot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
134 if (traceTypeName != null && !traceTypeName.isEmpty()) {
135 comboBox.setSelection(traceTypeName);
136 } else {
137 comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
138 }
139
140 SWTBotCheckBox checkBox = bot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
141 if (checkBox.isEnabled()) {
142 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) {
143 checkBox.select();
144 } else {
145 checkBox.deselect();
146 }
147 }
148
149 checkBox = bot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure);
150 if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
151 checkBox.select();
152 } else {
153 checkBox.deselect();
154 }
155
156 checkBox = bot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized);
157 if (checkBox.isEnabled()) {
158 if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
159 checkBox.select();
160 } else {
161 checkBox.deselect();
162 }
163 }
164
165 checkBox = bot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace);
166 if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) {
167 checkBox.select();
168 } else {
169 checkBox.deselect();
170 }
171
172 checkBox = bot.checkBox(Messages.ImportTraceWizard_CreateExperiment);
173 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_EXPERIMENT) != 0) {
174 checkBox.select();
175 } else {
176 checkBox.deselect();
177 }
178 }
179
180 /**
181 * Test that the events editor gets activated and that the first event is
182 * selectable.
183 *
184 * @param bot
185 * the SWTBot
186 * @param editorName
187 * the expected name of the editor
188 * @param nbEvents
189 * the expected number of events
190 * @param firstEventStr
191 * the first event timestamp in string form. This is used to see
192 * if the cell contains this text (String.contains()). Since
193 * there can be timezone issues with hours and days, this value
194 * should only specify minutes and more precise digits. For
195 * example: 04:32.650 993 664
196 */
197 public static void testEventsTable(SWTWorkbenchBot bot, String editorName, long nbEvents, String firstEventStr) {
198 SWTBotEditor editor = SWTBotUtils.activeEventsEditor(bot, editorName);
199 bot.waitUntil(ConditionHelpers.numberOfEventsInTrace(TmfTraceManager.getInstance().getActiveTrace(), nbEvents));
200
201 if (nbEvents == 0 || firstEventStr == null || firstEventStr.isEmpty()) {
202 return;
203 }
204
205 SWTBotTable table = editor.bot().table();
206 bot.waitUntil(new DefaultCondition() {
207 @Override
208 public boolean test() throws Exception {
209 return table.rowCount() > 1;
210 }
211
212 @Override
213 public String getFailureMessage() {
214 return "No items in table";
215 }
216 });
217 // Select first event (skip filter/search row)
218 table.getTableItem(1).select();
219
220 editor.bot().waitUntil(new DefaultCondition() {
221 @Override
222 public boolean test() throws Exception {
223 boolean ret = table.selection().rowCount() == 1 && table.selection().get(0).toString().contains(firstEventStr);
224 if (!ret) {
225 // FIXME: Not sure why, sometimes the first select() ends up
226 // selecting an empty item. Retry selecting here.
227 table.getTableItem(1).select();
228 }
229 return ret;
230 }
231
232 @Override
233 public String getFailureMessage() {
234 return "First event not selected.";
235 }
236 });
237 }
238 }
This page took 0.036527 seconds and 4 git commands to generate.