tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / lttng / org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests / src / org / eclipse / tracecompass / lttng2 / control / ui / swtbot / tests / ControlViewExcludeEventsTest.java
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
10 package org.eclipse.tracecompass.lttng2.control.ui.swtbot.tests;
11
12 import static org.junit.Assert.assertEquals;
13 import static org.junit.Assert.assertNotNull;
14 import static org.junit.Assert.assertTrue;
15
16 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
17 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
18 import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
19 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
20 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
21 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
22 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
23 import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState;
24 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView;
25 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.ITraceControlComponent;
26 import org.eclipse.tracecompass.internal.lttng2.control.ui.views.model.impl.TraceEventComponent;
27 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
28 import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
29 import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
30 import org.junit.Test;
31 import org.junit.runner.RunWith;
32
33 /**
34 * Test for the Control view in Trace Compass. This will test the exclude events feature.
35 *
36 * @author Bruno Roy
37 */
38 @RunWith(SWTBotJunit4ClassRunner.class)
39 public class ControlViewExcludeEventsTest extends ControlViewTest {
40
41 // ------------------------------------------------------------------------
42 // Constants
43 // ------------------------------------------------------------------------
44 private static final String TEST_STREAM = "CreateSessionTestLTTng2_8.cfg";
45
46 private static final String CREATE_SESSION_UST_EXCLUDE_SCENARIO_NAME = "ExcludeEvent";
47
48 private static final String SESSION_NAME = "mysession";
49 private static final String EXCLUDE_EXPRESSION = "foo";
50 private static final String PROPERTIES_VIEW = "Properties";
51 private static final String EXCLUDE_TREE_ITEM = "Exclude";
52
53 @Override
54 protected String getTestStream() {
55 return TEST_STREAM;
56 }
57
58 @Override
59 protected String getSessionName() {
60 return SESSION_NAME;
61 }
62
63 /**
64 * Testing the trace session tree.
65 */
66 @Override
67 @Test
68 public void testTraceSessionTree() {
69
70 fProxy.setTestFile(fTestFile);
71 fProxy.setScenario(INIT_SCENARIO_NAME);
72 testConnectToNode();
73
74 // Enable all UST events with one excluded event
75 fProxy.setScenario(CREATE_SESSION_UST_EXCLUDE_SCENARIO_NAME);
76 testCreateSession();
77 testEnableUstEventExclude();
78 testStartStopTracing(TraceSessionState.ACTIVE);
79 testStartStopTracing(TraceSessionState.INACTIVE);
80 // Verify that the Properties view shows to right excluded event
81 testPropertiesEventExclude();
82 // Clean session
83 testDestroySession();
84 testDisconnectFromNode();
85 }
86
87 /**
88 * Enable all UST events with one excluded event.
89 */
90 protected void testEnableUstEventExclude() {
91 // Getting the 'Sessions' tree
92 SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree,
93 getNodeName(),
94 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
95 getSessionName());
96 sessionItem.select();
97
98 // Clicking on the 'Enable Event (default channel)...'
99 SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM);
100 menuBot.click();
101
102 SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate();
103
104 // Switching to the UST domain
105 shell.bot().radioInGroup(ControlViewSwtBotUtil.UST_GROUP_NAME, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click();
106
107 // Selecting all UST events
108 SWTBotTree tracepointsTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.TRACEPOINTS_GROUP_NAME);
109 SWTBotTreeItem treeItem = tracepointsTree.getTreeItem(ControlViewSwtBotUtil.ALL_TREE_NODE);
110 treeItem.check();
111
112 // Click the checkbox for the Exclude event
113 shell.bot().checkBoxInGroup(ControlViewSwtBotUtil.GROUP_SELECT_NAME, ControlViewSwtBotUtil.EXCLUDE_EVENT_LABEL).click();
114
115 // Enter the event to exclude in the text field
116 SWTBotText excludeText = shell.bot().textInGroup(ControlViewSwtBotUtil.EXCLUDE_EVENT_LABEL);
117 excludeText.setText(EXCLUDE_EXPRESSION);
118
119 // Click the Ok at the bottom of the dialog window
120 shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click();
121 WaitUtils.waitForJobs();
122
123 fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(ControlViewSwtBotUtil.UST_DOMAIN_NAME, sessionItem));
124
125 // Assert that the domain is UST global
126 SWTBotTreeItem ustGlobalDomainItem = SWTBotUtils.getTreeItem(fBot, fTree,
127 getNodeName(),
128 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
129 getSessionName(),
130 ControlViewSwtBotUtil.UST_DOMAIN_NAME);
131 assertEquals(ControlViewSwtBotUtil.UST_DOMAIN_NAME, ustGlobalDomainItem.getText());
132
133 // Assert that the new channel name is channel0 (which is the default name)
134 SWTBotTreeItem channelItem = SWTBotUtils.getTreeItem(fBot, fTree,
135 getNodeName(),
136 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
137 getSessionName(),
138 ControlViewSwtBotUtil.UST_DOMAIN_NAME,
139 ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME);
140 assertEquals(ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME, channelItem.getText());
141
142 // Assert that the event type in the channel node are correct (all events = *)
143 SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree,
144 getNodeName(),
145 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
146 getSessionName(),
147 ControlViewSwtBotUtil.UST_DOMAIN_NAME,
148 ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME,
149 ControlViewSwtBotUtil.ALL_EVENTS_NAME);
150 assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, eventItem.getText());
151
152 // Assert that the excluded event is the correct one
153 ITraceControlComponent comp = ControlViewSwtBotUtil.getComponent(fNode,
154 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
155 getSessionName(),
156 ControlViewSwtBotUtil.UST_DOMAIN_NAME,
157 ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME,
158 ControlViewSwtBotUtil.ALL_EVENTS_NAME);
159 assertNotNull(comp);
160 assertTrue(comp instanceof TraceEventComponent);
161 TraceEventComponent event = (TraceEventComponent) comp;
162 assertEquals(EXCLUDE_EXPRESSION, event.getExcludedEvents());
163 }
164
165 /**
166 * Test that the Properties view has been update and shows the the right
167 * information.
168 */
169 protected void testPropertiesEventExclude() {
170 // Open the properties view (by id)
171 SWTBotUtils.openView("org.eclipse.ui.views.PropertySheet");
172
173 // Select the event in the Control view
174 fBot.viewById(ControlView.ID).show();
175 SWTBotTreeItem eventItem = SWTBotUtils.getTreeItem(fBot, fTree,
176 getNodeName(),
177 ControlViewSwtBotUtil.SESSION_GROUP_NAME,
178 getSessionName(),
179 ControlViewSwtBotUtil.UST_DOMAIN_NAME,
180 ControlViewSwtBotUtil.DEFAULT_CHANNEL_NAME,
181 ControlViewSwtBotUtil.ALL_EVENTS_NAME);
182 eventItem.select();
183
184 // Get a bot and open the Properties view
185 SWTBotView propertiesViewBot = fBot.viewByTitle(PROPERTIES_VIEW);
186 propertiesViewBot.show();
187
188 // Get the Exclude field in the tree
189 SWTBotTree propertiesViewTree = propertiesViewBot.bot().tree();
190 SWTBotTreeItem excludeTreeItem = propertiesViewTree.getTreeItem(EXCLUDE_TREE_ITEM);
191 // We want the VALUE of the 'Exclude' row so the cell index is 1
192 String excludeExpression = excludeTreeItem.cell(1);
193
194 // Assert that the expression in the Properties view is the same as
195 // the one we entered
196 assertEquals(EXCLUDE_EXPRESSION, excludeExpression);
197
198 // Close the Properties view
199 SWTBotUtils.closeView(PROPERTIES_VIEW, fBot);
200 }
201
202 }
This page took 0.035231 seconds and 5 git commands to generate.