6dfb8e982c89a4c4976033302512157b59fd3131
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / wizards / StandardImportGzipTraceTest.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 * Contributors:
10 * Matthew Khouzam - Initial API and implementation.
11 *******************************************************************************/
12 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.wizards;
13
14 import static org.junit.Assert.assertEquals;
15 import static org.junit.Assert.assertFalse;
16 import static org.junit.Assert.assertNotNull;
17 import static org.junit.Assert.assertTrue;
18 import static org.junit.Assert.fail;
19
20 import java.io.File;
21 import java.io.FileInputStream;
22 import java.io.FileOutputStream;
23 import java.io.IOException;
24 import java.util.zip.GZIPOutputStream;
25
26 import org.apache.log4j.Logger;
27 import org.apache.log4j.varia.NullAppender;
28 import org.eclipse.jface.viewers.StructuredSelection;
29 import org.eclipse.jface.wizard.Wizard;
30 import org.eclipse.jface.wizard.WizardDialog;
31 import org.eclipse.swt.widgets.Shell;
32 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
33 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
34 import org.eclipse.swtbot.swt.finder.SWTBot;
35 import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
36 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
37 import org.eclipse.swtbot.swt.finder.results.VoidResult;
38 import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
39 import org.eclipse.swtbot.swt.finder.waits.Conditions;
40 import org.eclipse.swtbot.swt.finder.widgets.SWTBotButton;
41 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
42 import org.eclipse.swtbot.swt.finder.widgets.SWTBotCombo;
43 import org.eclipse.swtbot.swt.finder.widgets.SWTBotRadio;
44 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
45 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
46 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
47 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
48 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
49 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.ImportTraceWizard;
50 import org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.Messages;
51 import org.eclipse.tracecompass.tmf.core.tests.shared.TmfTestTrace;
52 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
53 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
54 import org.eclipse.ui.IPageLayout;
55 import org.eclipse.ui.IWorkbench;
56 import org.eclipse.ui.IWorkbenchWindow;
57 import org.eclipse.ui.PlatformUI;
58 import org.junit.After;
59 import org.junit.AfterClass;
60 import org.junit.Before;
61 import org.junit.BeforeClass;
62 import org.junit.Test;
63 import org.junit.runner.RunWith;
64
65 /**
66 *
67 * Import operation for gz traces
68 *
69 */
70 @RunWith(SWTBotJunit4ClassRunner.class)
71 public class StandardImportGzipTraceTest {
72 private static final String ROOT_FOLDER = "/";
73 private static final String PROJECT_NAME = "Tracing";
74 private static File fGzipTrace;
75 private Wizard fWizard;
76 private SWTWorkbenchBot fBot;
77
78 /** The Log4j logger instance. */
79 protected static final Logger fLogger = Logger.getRootLogger();
80
81 /**
82 * create a gzip file
83 */
84 @BeforeClass
85 public static void init() {
86 SWTBotUtils.initialize();
87 zipTrace();
88 fLogger.removeAllAppenders();
89 fLogger.addAppender(new NullAppender());
90 }
91
92 /**
93 * create the project
94 */
95 @Before
96 public void setup() {
97 createProject();
98 SWTBotPreferences.TIMEOUT = 20000;
99 }
100
101 /**
102 * cleanup
103 */
104 @AfterClass
105 public static void destroy() {
106 fLogger.removeAllAppenders();
107 }
108
109 /**
110 * Tear down the test
111 */
112 @After
113 public void tearDown() {
114 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
115 }
116
117 private void createProject() {
118 fBot = new SWTWorkbenchBot();
119 /* Close welcome view */
120 SWTBotUtils.closeView("Welcome", fBot);
121 SWTBotUtils.switchToTracingPerspective();
122
123 SWTBotUtils.createProject(PROJECT_NAME);
124 }
125
126 /**
127 * Import a gzip trace
128 */
129 @Test
130 public void testGzipImport() {
131 final String traceType = "Test trace : TMF Tests";
132 final String tracesNode = "Traces [1]";
133
134 /*
135 * Actual importing
136 */
137 openImportWizard();
138 selectImportFromArchive(fGzipTrace.getAbsolutePath());
139 selectFolder(ROOT_FOLDER);
140 SWTBotCheckBox checkBox = fBot.checkBox(Messages.ImportTraceWizard_CreateLinksInWorkspace);
141 assertFalse(checkBox.isEnabled());
142 SWTBotCombo comboBox = fBot.comboBoxWithLabel(Messages.ImportTraceWizard_TraceType);
143 comboBox.setSelection(traceType);
144 importFinish();
145 /*
146 * Remove .gz extension
147 */
148 assertNotNull(fGzipTrace);
149 String name = fGzipTrace.getName();
150 assertNotNull(name);
151 assertTrue(name.length() > 3);
152 String traceName = name.substring(0, name.length() - 3);
153 assertNotNull(traceName);
154 assertFalse(traceName.isEmpty());
155
156 /*
157 * Open trace
158 */
159 SWTBotView projectExplorer = fBot.viewById(IPageLayout.ID_PROJECT_EXPLORER);
160 projectExplorer.setFocus();
161 final SWTBotTree tree = projectExplorer.bot().tree();
162 /*
163 * This appears to be problematic due to the length of the file name and
164 * the resolution in our CI.
165 */
166 SWTBotTreeItem treeItem = SWTBotUtils.getTreeItem(projectExplorer.bot(), tree, PROJECT_NAME, tracesNode, traceName);
167 treeItem.doubleClick();
168 SWTBotUtils.waitForJobs();
169 /*
170 * Check results
171 */
172 SWTBot editorBot = SWTBotUtils.activeEventsEditor(fBot).bot();
173 SWTBotTable editorTable = editorBot.table();
174 final String expectedContent1 = "Type-1";
175 final String expectedContent2 = "";
176 editorBot.waitUntil(ConditionHelpers.isTableCellFilled(editorTable, expectedContent1, 2, 2));
177 editorBot.waitUntil(ConditionHelpers.isTableCellFilled(editorTable, expectedContent2, 1, 0));
178 String c22 = editorTable.cell(2, 2);
179 String c10 = editorTable.cell(1, 0);
180 assertEquals(expectedContent1, c22);
181 assertEquals(expectedContent2, c10);
182 }
183
184 private static void zipTrace() {
185 try {
186 fGzipTrace = File.createTempFile("trace", ".gz");
187 byte[] buffer = new byte[1024];
188
189 try (GZIPOutputStream gzos = new GZIPOutputStream(new FileOutputStream(fGzipTrace));) {
190
191 try (FileInputStream in = new FileInputStream(TmfTestTrace.A_TEST_10K2.getFullPath());) {
192
193 int len;
194 while ((len = in.read(buffer)) > 0) {
195 gzos.write(buffer, 0, len);
196 }
197 }
198 gzos.finish();
199 }
200 } catch (IOException e) {
201 fail(e.getMessage());
202 }
203 }
204
205 private void selectImportFromArchive(String archivePath) {
206 SWTBotRadio button = fBot.radio("Select &archive file:");
207 button.click();
208
209 SWTBotCombo sourceCombo = fBot.comboBox(1);
210
211 sourceCombo.setText(new File(archivePath).getAbsolutePath());
212
213 SWTBotText text = fBot.text();
214 text.setFocus();
215 }
216
217 private void openImportWizard() {
218 fWizard = new ImportTraceWizard();
219
220 UIThreadRunnable.asyncExec(new VoidResult() {
221 @Override
222 public void run() {
223 final IWorkbench workbench = PlatformUI.getWorkbench();
224 // Fire the Import Trace Wizard
225 if (workbench != null) {
226 final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
227 Shell shell = activeWorkbenchWindow.getShell();
228 assertNotNull(shell);
229 ((ImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
230 WizardDialog dialog = new WizardDialog(shell, fWizard);
231 dialog.open();
232 }
233 }
234 });
235
236 fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
237 }
238
239 private void selectFolder(String... treePath) {
240 SWTBotTree tree = fBot.tree();
241 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
242 SWTBotTreeItem folderNode = SWTBotUtils.getTreeItem(fBot, tree, treePath);
243 folderNode.check();
244 }
245
246 private void importFinish() {
247 SWTBotShell shell = fBot.activeShell();
248 final SWTBotButton finishButton = fBot.button("Finish");
249 finishButton.click();
250 fBot.waitUntil(Conditions.shellCloses(shell));
251 SWTBotUtils.waitForJobs();
252 }
253 }
This page took 0.037598 seconds and 4 git commands to generate.