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 / ImportAndReadSmokeTest.java
1 /*******************************************************************************
2 * Copyright (c) 2013, 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 * Matthew Khouzam - Initial API and implementation
11 * Marc-Andre Laperle
12 * Bernd Hufmann - Extracted functionality to class AbstractImportAndReadSmokeTest
13 *******************************************************************************/
14
15 package org.eclipse.linuxtools.tmf.ctf.ui.swtbot.tests;
16
17 import static org.junit.Assert.assertNotNull;
18
19 import org.eclipse.jface.viewers.StructuredSelection;
20 import org.eclipse.jface.wizard.IWizardPage;
21 import org.eclipse.jface.wizard.WizardDialog;
22 import org.eclipse.linuxtools.internal.tmf.ui.project.wizards.importtrace.BatchImportTraceWizard;
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.SWTBotButton;
32 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
33 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
34 import org.eclipse.ui.IWorkbench;
35 import org.eclipse.ui.IWorkbenchWindow;
36 import org.eclipse.ui.PlatformUI;
37 import org.junit.Test;
38 import org.junit.runner.RunWith;
39
40 /**
41 * SWTBot Smoke test. base for other tests
42 *
43 * @author Matthew Khouzam
44 */
45 @RunWith(SWTBotJunit4ClassRunner.class)
46 public class ImportAndReadSmokeTest extends AbstractImportAndReadSmokeTest {
47
48 private static final String TRACE_PROJECT_NAME = "test";
49
50 /**
51 * Main test case
52 */
53 @Test
54 public void test() {
55 createProject();
56
57 batchImportOpenWizard();
58 batchImportSelecTraceType();
59 batchImportAddDirectory();
60 batchImportSelectTrace();
61 importFinish();
62
63 TmfEventsEditor tmfEd = openEditor();
64
65 testHistogramView(getViewPart("Histogram"), tmfEd);
66 testPropertyView(getViewPart("Properties"));
67 testStatisticsView(getViewPart("Statistics"));
68 fBot.closeAllEditors();
69
70 SWTBotUtil.deleteProject(getProjectName(), fBot);
71 }
72
73 private static void batchImportOpenWizard() {
74 fWizard = new BatchImportTraceWizard();
75
76 UIThreadRunnable.asyncExec(new VoidResult() {
77 @Override
78 public void run() {
79 final IWorkbench workbench = PlatformUI.getWorkbench();
80 // Fire the Import Trace Wizard
81 if (workbench != null) {
82 final IWorkbenchWindow activeWorkbenchWindow = workbench.getActiveWorkbenchWindow();
83 Shell shell = activeWorkbenchWindow.getShell();
84 assertNotNull(shell);
85 ((BatchImportTraceWizard) fWizard).init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
86 WizardDialog dialog = new WizardDialog(shell, fWizard);
87 dialog.open();
88 }
89 }
90 });
91
92 fBot.waitUntil(ConditionHelpers.isWizardReady(fWizard));
93 }
94
95 private static void batchImportSelecTraceType() {
96 final SWTBotTree tree = fBot.tree();
97 final String ctfId = "Common Trace Format";
98 fBot.waitUntil(ConditionHelpers.IsTreeNodeAvailable(ctfId, tree));
99 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(TRACE_TYPE_NAME, tree.getTreeItem(ctfId)));
100 tree.getTreeItem(ctfId).getNode(TRACE_TYPE_NAME).check();
101 batchImportClickNext();
102 }
103
104 private static void batchImportAddDirectory() {
105 UIThreadRunnable.syncExec(new VoidResult() {
106 @Override
107 public void run() {
108 ((BatchImportTraceWizard) fWizard).addFileToScan(fTrace.getPath());
109 }
110 });
111 final SWTBotButton removeButton = fBot.button("Remove");
112 fBot.waitUntil(Conditions.widgetIsEnabled(removeButton));
113 removeButton.click();
114 fBot.waitUntil(Conditions.tableHasRows(fBot.table(), 1));
115
116 batchImportClickNext();
117 }
118
119 private static void batchImportSelectTrace() {
120 SWTBotTree tree = fBot.tree();
121 fBot.waitUntil(Conditions.widgetIsEnabled(tree));
122 final SWTBotTreeItem genericCtfTreeItem = tree.getTreeItem(TRACE_TYPE_NAME);
123 fBot.waitUntil(Conditions.widgetIsEnabled(genericCtfTreeItem));
124 genericCtfTreeItem.expand();
125 genericCtfTreeItem.check();
126 batchImportClickNext();
127 }
128
129 private static void batchImportClickNext() {
130 IWizardPage currentPage = fWizard.getContainer().getCurrentPage();
131 IWizardPage desiredPage = fWizard.getNextPage(currentPage);
132 SWTBotButton nextButton = fBot.button("Next >");
133 nextButton.click();
134 fBot.waitUntil(ConditionHelpers.isWizardOnPage(fWizard, desiredPage));
135 }
136
137 @Override
138 protected String getProjectName() {
139 return TRACE_PROJECT_NAME;
140 }
141
142 @Override
143 protected boolean supportsFolderStructure() {
144 return false;
145 }
146 }
This page took 0.03546 seconds and 5 git commands to generate.