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