1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation.
11 *******************************************************************************/
12 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.wizards
;
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
;
21 import java
.io
.FileInputStream
;
22 import java
.io
.FileOutputStream
;
23 import java
.io
.IOException
;
24 import java
.util
.zip
.GZIPOutputStream
;
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
.finders
.UIThreadRunnable
;
35 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
36 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
37 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
38 import org
.eclipse
.swtbot
.swt
.finder
.waits
.Conditions
;
39 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotButton
;
40 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCheckBox
;
41 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotCombo
;
42 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotRadio
;
43 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotShell
;
44 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
45 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotText
;
46 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTree
;
47 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTreeItem
;
48 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.ImportTraceWizard
;
49 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.importtrace
.Messages
;
50 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.shared
.TmfTestTrace
;
51 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.ConditionHelpers
;
52 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
53 import org
.eclipse
.ui
.IPageLayout
;
54 import org
.eclipse
.ui
.IWorkbench
;
55 import org
.eclipse
.ui
.IWorkbenchWindow
;
56 import org
.eclipse
.ui
.PlatformUI
;
57 import org
.junit
.After
;
58 import org
.junit
.AfterClass
;
59 import org
.junit
.Before
;
60 import org
.junit
.BeforeClass
;
61 import org
.junit
.Test
;
62 import org
.junit
.runner
.RunWith
;
66 * Import operation for gz traces
69 @RunWith(SWTBotJunit4ClassRunner
.class)
70 public class StandardImportGzipTraceTest
{
71 private static final String ROOT_FOLDER
= "/";
72 private static final String PROJECT_NAME
= "Tracing";
73 private static File fGzipTrace
;
74 private Wizard fWizard
;
75 private SWTWorkbenchBot fBot
;
77 /** The Log4j logger instance. */
78 protected static final Logger fLogger
= Logger
.getRootLogger();
84 public static void init() {
85 SWTBotUtils
.failIfUIThread();
87 fLogger
.removeAllAppenders();
88 fLogger
.addAppender(new NullAppender());
97 SWTBotPreferences
.TIMEOUT
= 20000;
104 public static void destroy() {
105 fLogger
.removeAllAppenders();
112 public void tearDown() {
113 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
116 private void createProject() {
117 fBot
= new SWTWorkbenchBot();
118 /* Close welcome view */
119 SWTBotUtils
.closeView("Welcome", fBot
);
121 SWTBotUtils
.createProject(PROJECT_NAME
);
125 * Import a gzip trace
128 public void testGzipImport() {
129 final String traceType
= "Test trace : TMF Tests";
130 final String tracesNode
= "Traces [1]";
136 selectImportFromArchive(fGzipTrace
.getAbsolutePath());
137 selectFolder(ROOT_FOLDER
);
138 SWTBotCheckBox checkBox
= fBot
.checkBox(Messages
.ImportTraceWizard_CreateLinksInWorkspace
);
139 assertFalse(checkBox
.isEnabled());
140 SWTBotCombo comboBox
= fBot
.comboBoxWithLabel(Messages
.ImportTraceWizard_TraceType
);
141 comboBox
.setSelection(traceType
);
144 * Remove .gz extension
146 assertNotNull(fGzipTrace
);
147 String name
= fGzipTrace
.getName();
149 assertTrue(name
.length() > 3);
150 String traceName
= name
.substring(0, name
.length() - 3);
151 assertNotNull(traceName
);
152 assertFalse(traceName
.isEmpty());
157 SWTBotView projectExplorer
= fBot
.viewById(IPageLayout
.ID_PROJECT_EXPLORER
);
158 projectExplorer
.setFocus();
159 final SWTBotTree tree
= projectExplorer
.bot().tree();
161 * This appears to be problematic due to the length of the file name and
162 * the resolution in our CI.
164 tree
.expandNode(PROJECT_NAME
, true);
165 SWTBotTreeItem treeItem
= tree
.getTreeItem(PROJECT_NAME
);
166 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(tracesNode
, treeItem
));
167 treeItem
= treeItem
.getNode(tracesNode
);
168 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(traceName
, treeItem
));
169 treeItem
= treeItem
.getNode(traceName
);
170 treeItem
.doubleClick();
171 SWTBotUtils
.waitForJobs();
175 SWTBotTable editor
= fBot
.activeEditor().bot().table();
176 String c22
= editor
.cell(2, 2);
177 String c10
= editor
.cell(1, 0);
178 assertEquals("Type-1", c22
);
179 assertEquals("", c10
);
182 private static void zipTrace() {
184 fGzipTrace
= File
.createTempFile("trace", ".gz");
185 byte[] buffer
= new byte[1024];
187 try (GZIPOutputStream gzos
= new GZIPOutputStream(new FileOutputStream(fGzipTrace
));) {
189 try (FileInputStream in
= new FileInputStream(TmfTestTrace
.A_TEST_10K2
.getFullPath());) {
192 while ((len
= in
.read(buffer
)) > 0) {
193 gzos
.write(buffer
, 0, len
);
198 } catch (IOException e
) {
199 fail(e
.getMessage());
203 private void selectImportFromArchive(String archivePath
) {
204 SWTBotRadio button
= fBot
.radio("Select &archive file:");
207 SWTBotCombo sourceCombo
= fBot
.comboBox(1);
209 sourceCombo
.setText(new File(archivePath
).getAbsolutePath());
211 SWTBotText text
= fBot
.text();
215 private void openImportWizard() {
216 fWizard
= new ImportTraceWizard();
218 UIThreadRunnable
.asyncExec(new VoidResult() {
221 final IWorkbench workbench
= PlatformUI
.getWorkbench();
222 // Fire the Import Trace Wizard
223 if (workbench
!= null) {
224 final IWorkbenchWindow activeWorkbenchWindow
= workbench
.getActiveWorkbenchWindow();
225 Shell shell
= activeWorkbenchWindow
.getShell();
226 assertNotNull(shell
);
227 ((ImportTraceWizard
) fWizard
).init(PlatformUI
.getWorkbench(), StructuredSelection
.EMPTY
);
228 WizardDialog dialog
= new WizardDialog(shell
, fWizard
);
234 fBot
.waitUntil(ConditionHelpers
.isWizardReady(fWizard
));
237 private void selectFolder(String
... treePath
) {
238 SWTBotTree tree
= fBot
.tree();
239 fBot
.waitUntil(Conditions
.widgetIsEnabled(tree
));
240 SWTBotTreeItem folderNode
= SWTBotUtils
.getTreeItem(fBot
, tree
, treePath
);
244 private void importFinish() {
245 SWTBotShell shell
= fBot
.activeShell();
246 final SWTBotButton finishButton
= fBot
.button("Finish");
247 finishButton
.click();
248 fBot
.waitUntil(Conditions
.shellCloses(shell
));
249 SWTBotUtils
.waitForJobs();