tmf: Additional SWTBot tests for the standard import wizard
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests / src / org / eclipse / linuxtools / tmf / ctf / ui / swtbot / tests / StandardImportAndReadSmokeTest.java
CommitLineData
2f7b3dd7
BH
1/*******************************************************************************
2 * Copyright (c) 2014 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 * Contributors:
10 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests;
14
9b3f4afe
MAL
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertFalse;
2f7b3dd7 17import static org.junit.Assert.assertNotNull;
9b3f4afe 18import static org.junit.Assert.assertTrue;
2f7b3dd7 19
93c91230 20import java.io.File;
9b3f4afe
MAL
21import java.util.Collections;
22import java.util.Comparator;
23import java.util.List;
24
25import org.eclipse.core.resources.IProject;
26import org.eclipse.core.resources.IResource;
27import org.eclipse.core.resources.ResourcesPlugin;
28import org.eclipse.core.runtime.IPath;
93c91230 29import org.eclipse.core.runtime.Path;
2f7b3dd7
BH
30import org.eclipse.jface.viewers.StructuredSelection;
31import org.eclipse.jface.wizard.WizardDialog;
1de10308 32import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
9b3f4afe
MAL
33import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizardPage;
34import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.Messages;
2f7b3dd7 35import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
9b3f4afe
MAL
36import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectElement;
37import org.eclipse.linuxtools.tmf.ui.project.model.TmfProjectRegistry;
38import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceElement;
39import org.eclipse.linuxtools.tmf.ui.project.model.TmfTraceFolder;
40import org.eclipse.linuxtools.tmf.ui.project.model.TmfTracesFolder;
93c91230 41import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil;
2f7b3dd7
BH
42import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
43import org.eclipse.swt.widgets.Shell;
44import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
45import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
46import org.eclipse.swtbot.swt.finder.results.VoidResult;
47import org.eclipse.swtbot.swt.finder.waits.Conditions;
9b3f4afe 48import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
2f7b3dd7 49import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
93c91230 50import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
2f7b3dd7
BH
51import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
52import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
53import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
54import org.eclipse.ui.IWorkbench;
55import org.eclipse.ui.IWorkbenchWindow;
56import org.eclipse.ui.PlatformUI;
57import org.junit.Test;
58import org.junit.runner.RunWith;
59
60/**
61 * SWTBot Smoke test using ImportTraceWizard.
62 *
63 * @author Bernd Hufmann
64 */
65@RunWith(SWTBotJunit4ClassRunner.class)
66public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
67
93c91230
MAL
68 private static final String TRACE_FOLDER_PARENT_PATH = fTrace.getPath() + File.separator + ".." + File.separator + ".." + File.separator;
69 private static final String TRACE_ARCHIVE_PATH = TRACE_FOLDER_PARENT_PATH + "synctraces.tar.gz";
2f7b3dd7
BH
70 private static final String TRACE_PROJECT_NAME = "Tracing";
71
72 /**
9b3f4afe 73 * Test import from directory
2f7b3dd7
BH
74 */
75 @Test
93c91230 76 public void testImportFromDirectory() {
9b3f4afe
MAL
77 testImport(0, false, false);
78 }
2f7b3dd7 79
9b3f4afe
MAL
80 /**
81 * Test import from directory, create links
82 */
83 @Test
84 public void testImportFromDirectoryLinks() {
85 testImport(ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE, false, false);
86 }
2f7b3dd7 87
9b3f4afe
MAL
88 /**
89 * Test import from directory, preserve folder structure
90 */
91 @Test
92 public void testImportFromDirectoryPreserveFolder() {
93 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, false);
94 }
2f7b3dd7 95
9b3f4afe
MAL
96 /**
97 * Test import from directory, create links, preserve folder structure
98 */
99 @Test
100 public void testImportFromDirectoryLinksPreserveFolder() {
101 int options = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
102 testImport(options, false, false);
103 }
93c91230 104
9b3f4afe
MAL
105 /**
106 * Test import from directory, overwrite all
107 */
108 @Test
109 public void testImportFromDirectoryOverwrite() {
110 testImport(0, false, false);
111 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, false);
93c91230
MAL
112 }
113
114 /**
115 * Test import from archive
116 */
117 @Test
118 public void testImportFromArchive() {
9b3f4afe
MAL
119 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, true, true);
120 }
121
122 /**
123 * Test import from directory, preserve folder structure
124 */
125 @Test
126 public void testImportFromArchivePreserveFolder() {
127 testImport(ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE, false, true);
128 }
129
130 /**
131 * Test import from directory, overwrite all
132 */
133 @Test
134 public void testImportFromArchiveOverwrite() {
135 testImport(0, false, true);
136 testImport(ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES, false, true);
137 }
138
139 private void testImport(int options, boolean testViews, boolean fromArchive) {
93c91230
MAL
140 createProject();
141
142 importOpenWizard();
9b3f4afe
MAL
143 if (fromArchive) {
144 importAddArchive();
145 } else {
146 importAddDirectory();
147 }
93c91230 148
9b3f4afe 149 setOptions(options, ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
93c91230
MAL
150 importFinish();
151
9b3f4afe
MAL
152 checkOptions(options);
153 TmfEventsEditor tmfEd = openEditor(getTraceElementPath(options));
154 if (testViews) {
155 testViews(tmfEd);
156 }
93c91230 157
93c91230
MAL
158 fBot.closeAllEditors();
159
160 SWTBotUtil.deleteProject(getProjectName(), fBot);
161 }
162
9b3f4afe
MAL
163 private void testViews(TmfEventsEditor editor) {
164 testHistogramView(getViewPart("Histogram"), editor);
165 testPropertyView(getViewPart("Properties"));
166 testStatisticsView(getViewPart("Statistics"));
2f7b3dd7
BH
167 }
168
169 private static void importOpenWizard() {
170 fWizard = new ImportTraceWizard();
171
172 UIThreadRunnable.asyncExec(new VoidResult() {
173 @Override
174 public void run() {
175 final IWorkbench workbench = PlatformUI.getWorkbench();
176 // Fire the Import Trace Wizard
177 if (workbench != null) {
178 final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
179 Shell shell = activeWorkbenchWindow.getShell();
180 assertNotNull(shell);
181 ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
182 WizardDialog dialog = new WizardDialog(shell, fWizard);
183 dialog.open();
184 }
185 }
186 });
187
188 fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
189 }
190
191 private static void importAddDirectory() {
93c91230
MAL
192 SWTBotRadio button = fBot.radio("Select roo&t directory:");
193 button.click();
194
2f7b3dd7 195 SWTBotCombo sourceCombo = fBot.comboBox();
93c91230
MAL
196 File traceFolderParent = new File(TRACE_FOLDER_PARENT_PATH);
197 sourceCombo.setText(traceFolderParent.getAbsolutePath());
2f7b3dd7
BH
198
199 SWTBotText text = fBot.text();
200 text.setFocus();
201
202 fBot.activeShell();
203 SWTBotTree tree = fBot.tree();
204 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
93c91230
MAL
205
206 final String traceFolderParentName = new Path(traceFolderParent.getAbsolutePath()).lastSegment();
207 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(traceFolderParentName, tree));
208 final SWTBotTreeItem folderParentNode = tree.getTreeItem(traceFolderParentName);
209 folderParentNode.expand();
210
211 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(TRACE_FOLDER, folderParentNode));
212 final SWTBotTreeItem folderNode = folderParentNode.getNode(TRACE_FOLDER);
213 folderNode.check();
2f7b3dd7
BH
214 }
215
9b3f4afe
MAL
216 private static void importAddArchive() {
217 SWTBotRadio button = fBot.radio("Select &archive file:");
218 button.click();
219
220 SWTBotCombo sourceCombo = fBot.comboBox(1);
221
222 sourceCombo.setText(new File(TRACE_ARCHIVE_PATH).getAbsolutePath());
223
224 SWTBotText text = fBot.text();
225 text.setFocus();
226
227 SWTBotTree tree = fBot.tree();
228 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
229 final SWTBotTreeItem genericCtfTreeItem = tree.getTreeItem("/");
230 fBot.waitUntil(Conditions.widgetIsEnabled(genericCtfTreeItem));
231 genericCtfTreeItem.check();
232
233 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
234 assertFalse(checkBox.isEnabled());
2f7b3dd7
BH
235 }
236
9b3f4afe
MAL
237 private static void setOptions(int optionFlags, String traceTypeName) {
238 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
239 if (checkBox.isEnabled()) {
240 if ((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0) {
241 checkBox.select();
242 } else {
243 checkBox.deselect();
244 }
245 }
246
247 checkBox = fBot.checkBox(Messages.ImportTraceWizard_PreserveFolderStructure);
248 if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
249 checkBox.select();
250 } else {
251 checkBox.deselect();
252 }
253
254 checkBox = fBot.checkBox(Messages.ImportTraceWizard_ImportUnrecognized);
255 if ((optionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
256 checkBox.select();
257 } else {
258 checkBox.deselect();
259 }
260
261 checkBox = fBot.checkBox(Messages.ImportTraceWizard_OverwriteExistingTrace);
262 if ((optionFlags & ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES) != 0) {
263 checkBox.select();
264 } else {
265 checkBox.deselect();
266 }
267
268 SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
269 if (traceTypeName != null && !traceTypeName.isEmpty()) {
270 comboBox.setSelection(traceTypeName);
271 } else {
272 comboBox.setSelection(ImportTraceWizardPage.TRACE_TYPE_AUTO_DETECT);
273 }
93c91230
MAL
274 }
275
9b3f4afe
MAL
276 private static void checkOptions(int optionFlags) {
277 IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TRACE_PROJECT_NAME);
278 assertTrue(project.exists());
279 TmfProjectElement tmfProject = TmfProjectRegistry.getProject(project, true);
280 assertNotNull(tmfProject);
281 TmfTraceFolder tracesFolder = tmfProject.getTracesFolder();
282 assertNotNull(tracesFolder);
283 List<TmfTraceElement> traces = tracesFolder.getTraces();
284 assertFalse(traces.isEmpty());
285 Collections.sort(traces, new Comparator<TmfTraceElement>() {
286 @Override
287 public int compare(TmfTraceElement arg0, TmfTraceElement arg1) {
288 return arg0.getElementPath().compareTo(arg1.getElementPath());
289 }
290 });
291
292 TmfTraceElement tmfTraceElement = traces.get(0);
293 IResource traceResource = tmfTraceElement.getResource();
294
295 assertEquals((optionFlags & ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE) != 0, traceResource.isLinked());
296
297 // i.e. /Tracing/Traces
298 IPath expectedPath = Path.ROOT.append(new Path(TRACE_PROJECT_NAME)).append(TmfTracesFolder.TRACES_FOLDER_NAME);
299 expectedPath = expectedPath.append(getTraceElementPath(optionFlags));
300 assertEquals(expectedPath, traceResource.getFullPath());
301 }
302
303 private static IPath getTraceElementPath(int optionFlags) {
304 IPath traceElementPath = new Path("");
305 if ((optionFlags & ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE) != 0) {
306 traceElementPath = traceElementPath.append(TRACE_FOLDER);
307 }
308 return traceElementPath.append(TRACE_NAME);
309 }
310
311 @Override
312 protected String getProjectName() {
313 return TRACE_PROJECT_NAME;
314 }
2f7b3dd7 315}
This page took 0.042775 seconds and 5 git commands to generate.