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