tmf: Add SWTBot test for import from archive
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests / src / org / eclipse / linuxtools / tmf / ctf / ui / swtbot / tests / StandardImportAndReadSmokeTest.java
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
13 package org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests;
14
15 import static org.junit.Assert.assertNotNull;
16
17 import java.io.File;
18
19 import org.eclipse.core.runtime.Path;
20 import org.eclipse.jface.viewers.StructuredSelection;
21 import org.eclipse.jface.wizard.WizardDialog;
22 import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
23 import org.eclipse.linuxtools.tmf.ui.editors.TmfEventsEditor;
24 import org.eclipse.linuxtools.tmf.ui.swtbot.tests.SWTBotUtil;
25 import org.eclipse.linuxtools.tmf.ui.swtbot.tests.conditions.ConditionHelpers;
26 import org.eclipse.swt.widgets.Shell;
27 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
28 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
29 import org.eclipse.swtbot.swt.finder.results.VoidResult;
30 import org.eclipse.swtbot.swt.finder.waits.Conditions;
31 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
32 import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
33 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
34 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
35 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
36 import org.eclipse.ui.IWorkbench;
37 import org.eclipse.ui.IWorkbenchWindow;
38 import org.eclipse.ui.PlatformUI;
39 import org.junit.Test;
40 import org.junit.runner.RunWith;
41
42 /**
43 * SWTBot Smoke test using ImportTraceWizard.
44 *
45 * @author Bernd Hufmann
46 */
47 @RunWith(SWTBotJunit4ClassRunner.class)
48 public class StandardImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
49
50 private static final String TRACE_FOLDER_PARENT_PATH = fTrace.getPath() + File.separator + ".." + File.separator + ".." + File.separator;
51 private static final String TRACE_ARCHIVE_PATH = TRACE_FOLDER_PARENT_PATH + "synctraces.tar.gz";
52 private static final String TRACE_PROJECT_NAME = "Tracing";
53
54 /**
55 * Main test case
56 */
57 @Test
58 public void testImportFromDirectory() {
59 createProject();
60
61 importOpenWizard();
62 importAddDirectory();
63 importFinish();
64
65 TmfEventsEditor tmfEd = openEditor();
66
67 testHistogramView(getViewPart("Histogram"), tmfEd);
68 testPropertyView(getViewPart("Properties"));
69 testStatisticsView(getViewPart("Statistics"));
70 fBot.closeAllEditors();
71
72 SWTBotUtil.deleteProject(getProjectName(), fBot);
73 }
74
75 /**
76 * Test import from archive
77 */
78 @Test
79 public void testImportFromArchive() {
80 createProject();
81
82 importOpenWizard();
83
84 importAddArchive();
85 importFinish();
86
87 TmfEventsEditor tmfEd = openEditor();
88
89 testHistogramView(getViewPart("Histogram"), tmfEd);
90 testPropertyView(getViewPart("Properties"));
91 testStatisticsView(getViewPart("Statistics"));
92 fBot.closeAllEditors();
93
94 SWTBotUtil.deleteProject(getProjectName(), fBot);
95 }
96
97 private static void importAddArchive() {
98 SWTBotRadio button = fBot.radio("Select &archive file:");
99 button.click();
100
101 SWTBotCombo sourceCombo = fBot.comboBox(1);
102
103 sourceCombo.setText(new File(TRACE_ARCHIVE_PATH).getAbsolutePath());
104
105 SWTBotText text = fBot.text();
106 text.setFocus();
107
108 SWTBotTree tree = fBot.tree();
109 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
110 final SWTBotTreeItem genericCtfTreeItem = tree.getTreeItem("/");
111 fBot.waitUntil(Conditions.widgetIsEnabled(genericCtfTreeItem));
112 genericCtfTreeItem.check();
113 }
114
115 private static void importOpenWizard() {
116 fWizard = new ImportTraceWizard();
117
118 UIThreadRunnable.asyncExec(new VoidResult() {
119 @Override
120 public void run() {
121 final IWorkbench workbench = PlatformUI.getWorkbench();
122 // Fire the Import Trace Wizard
123 if (workbench != null) {
124 final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
125 Shell shell = activeWorkbenchWindow.getShell();
126 assertNotNull(shell);
127 ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
128 WizardDialog dialog = new WizardDialog(shell, fWizard);
129 dialog.open();
130 }
131 }
132 });
133
134 fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
135 }
136
137 private static void importAddDirectory() {
138 SWTBotRadio button = fBot.radio("Select roo&t directory:");
139 button.click();
140
141 SWTBotCombo sourceCombo = fBot.comboBox();
142 File traceFolderParent = new File(TRACE_FOLDER_PARENT_PATH);
143 sourceCombo.setText(traceFolderParent.getAbsolutePath());
144
145 SWTBotText text = fBot.text();
146 text.setFocus();
147
148 fBot.activeShell();
149 SWTBotTree tree = fBot.tree();
150 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
151
152 final String traceFolderParentName = new Path(traceFolderParent.getAbsolutePath()).lastSegment();
153 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(traceFolderParentName, tree));
154 final SWTBotTreeItem folderParentNode = tree.getTreeItem(traceFolderParentName);
155 folderParentNode.expand();
156
157 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(TRACE_FOLDER, folderParentNode));
158 final SWTBotTreeItem folderNode = folderParentNode.getNode(TRACE_FOLDER);
159 folderNode.check();
160 }
161
162 @Override
163 protected String getProjectName() {
164 return TRACE_PROJECT_NAME;
165 }
166
167 @Override
168 protected boolean supportsFolderStructure() {
169 return true;
170 }
171
172 }
This page took 0.036236 seconds and 6 git commands to generate.