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