Commit | Line | Data |
---|---|---|
0a004264 BR |
1 | /******************************************************************************* |
2 | * Copyright (c) 2016 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 | ||
14 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; | |
15 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; | |
16 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; | |
17 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree; | |
18 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; | |
4a9365ef | 19 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceDomainType; |
0a004264 BR |
20 | import org.eclipse.tracecompass.internal.lttng2.control.core.model.TraceSessionState; |
21 | import org.eclipse.tracecompass.internal.lttng2.control.ui.views.ControlView; | |
22 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; | |
23 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
f0beeb4a | 24 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; |
0a004264 BR |
25 | import org.junit.Test; |
26 | ||
27 | /** | |
4a9365ef | 28 | * Test for the Control view in Trace Compass. This will test the different logger domain. |
0a004264 BR |
29 | * |
30 | * @author Bruno Roy | |
31 | */ | |
4a9365ef | 32 | public class ControlViewLoggerTest extends ControlViewTest { |
0a004264 BR |
33 | |
34 | // ------------------------------------------------------------------------ | |
35 | // Constants | |
36 | // ------------------------------------------------------------------------ | |
37 | private static final String TEST_STREAM = "CreateSessionTestLTTng2_8.cfg"; | |
38 | private static final String CREATE_SESSION_JUL_SCENARIO_NAME = "JulLogger"; | |
4a9365ef | 39 | private static final String CREATE_SESSION_LOG4J_SCENARIO_NAME = "Log4jLogger"; |
8a9a09a3 | 40 | private static final String CREATE_SESSION_PYTHON_SCENARIO_NAME = "PythonLogger"; |
0a004264 BR |
41 | |
42 | private static final String SESSION_NAME = "mysession"; | |
43 | private static final String PROPERTIES_VIEW = "Properties"; | |
44 | private static final String LOGLEVEL_PROPERTY_NAME = "Log Level"; | |
45 | ||
46 | @Override | |
47 | protected String getTestStream() { | |
48 | return TEST_STREAM; | |
49 | } | |
50 | ||
51 | @Override | |
52 | protected String getSessionName() { | |
53 | return SESSION_NAME; | |
54 | } | |
55 | ||
56 | /** | |
57 | * Testing the trace session tree. | |
58 | */ | |
59 | @Override | |
60 | @Test | |
61 | public void testTraceSessionTree() { | |
62 | ||
63 | fProxy.setTestFile(fTestFile); | |
64 | fProxy.setScenario(INIT_SCENARIO_NAME); | |
65 | testConnectToNode(); | |
66 | ||
4a9365ef | 67 | // Enable JUL loggers |
0a004264 BR |
68 | fProxy.setScenario(CREATE_SESSION_JUL_SCENARIO_NAME); |
69 | testCreateSession(); | |
4a9365ef | 70 | testEnableLoggers(TraceDomainType.JUL); |
0a004264 BR |
71 | testStartStopTracing(TraceSessionState.ACTIVE); |
72 | testStartStopTracing(TraceSessionState.INACTIVE); | |
4a9365ef BR |
73 | // Verify that the Properties view shows to right logger log level |
74 | testLoggerProperties(TraceDomainType.JUL); | |
0a004264 | 75 | |
4a9365ef BR |
76 | // Enable LOG4J loggers |
77 | fProxy.setScenario(CREATE_SESSION_LOG4J_SCENARIO_NAME); | |
78 | testEnableLoggers(TraceDomainType.LOG4J); | |
79 | testStartStopTracing(TraceSessionState.ACTIVE); | |
80 | testStartStopTracing(TraceSessionState.INACTIVE); | |
0a004264 | 81 | // Verify that the Properties view shows to right logger log level |
4a9365ef | 82 | testLoggerProperties(TraceDomainType.LOG4J); |
0a004264 | 83 | |
8a9a09a3 BR |
84 | // Enable Python loggers |
85 | fProxy.setScenario(CREATE_SESSION_PYTHON_SCENARIO_NAME); | |
86 | testEnableLoggers(TraceDomainType.PYTHON); | |
87 | testStartStopTracing(TraceSessionState.ACTIVE); | |
88 | testStartStopTracing(TraceSessionState.INACTIVE); | |
89 | // Verify that the Properties view shows to right logger log level | |
90 | testLoggerProperties(TraceDomainType.PYTHON); | |
91 | ||
0a004264 BR |
92 | // Clean session |
93 | testDestroySession(); | |
94 | testDisconnectFromNode(); | |
95 | } | |
96 | ||
97 | /** | |
4a9365ef BR |
98 | * Enable loggers with different log level and log level type |
99 | * | |
100 | * @param domain | |
101 | * the logger domain to test | |
0a004264 | 102 | */ |
4a9365ef BR |
103 | protected void testEnableLoggers(TraceDomainType domain) { |
104 | String domainName = new String(); | |
105 | String logLevel = new String(); | |
106 | switch (domain) { | |
107 | case JUL: | |
108 | domainName = ControlViewSwtBotUtil.JUL_DOMAIN_NAME; | |
109 | logLevel = "Warning"; | |
110 | break; | |
111 | case LOG4J: | |
112 | domainName = ControlViewSwtBotUtil.LOG4J_DOMAIN_NAME; | |
113 | logLevel = "Fatal"; | |
114 | break; | |
8a9a09a3 BR |
115 | case PYTHON: |
116 | domainName = ControlViewSwtBotUtil.PYTHON_DOMAIN_NAME; | |
117 | logLevel = "Critical"; | |
118 | break; | |
4a9365ef BR |
119 | //$CASES-OMITTED$ |
120 | default: | |
121 | break; | |
122 | } | |
0a004264 BR |
123 | // Case 1: Enabling all loggers |
124 | // Getting the 'Sessions' tree | |
125 | SWTBotTreeItem sessionItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
126 | getNodeName(), | |
127 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
128 | getSessionName()); | |
129 | sessionItem.select(); | |
130 | ||
131 | // Clicking on the 'Enable Event (default channel)...' | |
132 | SWTBotMenu menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
133 | menuBot.click(); | |
134 | ||
135 | SWTBotShell shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
136 | ||
4a9365ef BR |
137 | // Switching to the logger domain |
138 | shell.bot().radioInGroup(domainName, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); | |
0a004264 | 139 | |
4a9365ef | 140 | // Selecting all loggers |
0a004264 BR |
141 | SWTBotTree loggersTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.LOGGERS_GROUP_NAME); |
142 | SWTBotTreeItem treeItem = loggersTree.getTreeItem(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
143 | treeItem.check(); | |
144 | ||
145 | // Click the Ok at the bottom of the dialog window | |
146 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 147 | WaitUtils.waitForJobs(); |
4a9365ef | 148 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(domainName, sessionItem)); |
0a004264 | 149 | |
4a9365ef BR |
150 | // Assert that the domain is correct |
151 | SWTBotTreeItem domainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
0a004264 BR |
152 | getNodeName(), |
153 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
154 | getSessionName(), | |
4a9365ef BR |
155 | domainName); |
156 | assertEquals(domainName, domainItem.getText()); | |
0a004264 BR |
157 | |
158 | // Assert that the logger type in the domain node are correct (all events = *) | |
159 | SWTBotTreeItem loggerItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
160 | getNodeName(), | |
161 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
162 | getSessionName(), | |
4a9365ef | 163 | domainName, |
0a004264 BR |
164 | ControlViewSwtBotUtil.ALL_EVENTS_NAME); |
165 | assertEquals(ControlViewSwtBotUtil.ALL_EVENTS_NAME, loggerItem.getText()); | |
166 | ||
167 | // Case 2: Enabling a specific logger with no particular log level | |
168 | sessionItem.select(); | |
169 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
170 | menuBot.click(); | |
171 | shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
4a9365ef | 172 | shell.bot().radioInGroup(domainName, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); |
0a004264 BR |
173 | loggersTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.LOGGERS_GROUP_NAME); |
174 | // Expand the "All" and "All - application name" node | |
175 | SWTBotTreeItem allItem = loggersTree.getTreeItem(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
176 | allItem.expand(); | |
8a9a09a3 | 177 | allItem = SWTBotUtils.getTreeItem(fBot, loggersTree, ControlViewSwtBotUtil.ALL_TREE_NODE, ControlViewSwtBotUtil.LOGGER_APPLICATION_NAME); |
0a004264 BR |
178 | allItem.expand(); |
179 | treeItem = SWTBotUtils.getTreeItem(fBot, loggersTree, | |
180 | ControlViewSwtBotUtil.ALL_TREE_NODE, | |
8a9a09a3 | 181 | ControlViewSwtBotUtil.LOGGER_APPLICATION_NAME, |
0a004264 BR |
182 | ControlViewSwtBotUtil.LOGGER_NAME); |
183 | treeItem.check(); | |
184 | ||
185 | // Click the Ok at the bottom of the dialog window | |
186 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 187 | WaitUtils.waitForJobs(); |
4a9365ef | 188 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(domainName, sessionItem)); |
0a004264 | 189 | |
4a9365ef BR |
190 | // Assert that the domain is correct |
191 | domainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
0a004264 BR |
192 | getNodeName(), |
193 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
194 | getSessionName(), | |
4a9365ef BR |
195 | domainName); |
196 | assertEquals(domainName, domainItem.getText()); | |
0a004264 BR |
197 | |
198 | // Assert that the logger type in the domain node are correct (all events = *) | |
199 | loggerItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
200 | getNodeName(), | |
201 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
202 | getSessionName(), | |
4a9365ef | 203 | domainName, |
0a004264 BR |
204 | ControlViewSwtBotUtil.LOGGER_NAME); |
205 | assertEquals(ControlViewSwtBotUtil.LOGGER_NAME, loggerItem.getText()); | |
206 | ||
4a9365ef | 207 | // Case 3: Enabling a specific logger with a log level |
0a004264 BR |
208 | sessionItem.select(); |
209 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
210 | menuBot.click(); | |
211 | shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
4a9365ef | 212 | shell.bot().radioInGroup(domainName, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); |
0a004264 BR |
213 | loggersTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.LOGGERS_GROUP_NAME); |
214 | // Expand the "All" and "All - application name" node | |
215 | allItem = loggersTree.getTreeItem(ControlViewSwtBotUtil.ALL_TREE_NODE); | |
216 | allItem.expand(); | |
217 | allItem = SWTBotUtils.getTreeItem(fBot, loggersTree, ControlViewSwtBotUtil.ALL_TREE_NODE, "All - ./client_bin/challenger [PID=14237] (With logger)"); | |
218 | allItem.expand(); | |
219 | treeItem = SWTBotUtils.getTreeItem(fBot, loggersTree, ControlViewSwtBotUtil.ALL_TREE_NODE, "All - ./client_bin/challenger [PID=14237] (With logger)", ControlViewSwtBotUtil.ANOTHER_LOGGER_NAME); | |
220 | treeItem.check(); | |
221 | // Select a log level | |
222 | shell.bot().checkBoxInGroup(LOGLEVEL_PROPERTY_NAME).select(); | |
4a9365ef | 223 | shell.bot().ccomboBoxInGroup(LOGLEVEL_PROPERTY_NAME).setSelection(logLevel); |
0a004264 BR |
224 | // Click the Ok at the bottom of the dialog window |
225 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 226 | WaitUtils.waitForJobs(); |
4a9365ef | 227 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(domainName, sessionItem)); |
0a004264 | 228 | |
4a9365ef BR |
229 | // Assert that the domain is correct |
230 | domainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
0a004264 BR |
231 | getNodeName(), |
232 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
233 | getSessionName(), | |
4a9365ef BR |
234 | domainName); |
235 | assertEquals(domainName, domainItem.getText()); | |
0a004264 BR |
236 | |
237 | // Assert that the logger type in the domain node are correct (all events = *) | |
238 | loggerItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
239 | getNodeName(), | |
240 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
241 | getSessionName(), | |
4a9365ef | 242 | domainName, |
0a004264 BR |
243 | ControlViewSwtBotUtil.ANOTHER_LOGGER_NAME); |
244 | assertEquals(ControlViewSwtBotUtil.ANOTHER_LOGGER_NAME, loggerItem.getText()); | |
a7cfc952 BR |
245 | |
246 | // Case 4: Enabling a logger by specifying the name | |
247 | sessionItem.select(); | |
248 | menuBot = sessionItem.contextMenu(ControlViewSwtBotUtil.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM); | |
249 | menuBot.click(); | |
250 | shell = fBot.shell(ControlViewSwtBotUtil.ENABLE_EVENT_DIALOG_TITLE).activate(); | |
251 | shell.bot().radioInGroup(domainName, ControlViewSwtBotUtil.DOMAIN_GROUP_NAME).click(); | |
252 | loggersTree = shell.bot().treeInGroup(ControlViewSwtBotUtil.LOGGERS_GROUP_NAME); | |
253 | // Write a logger name in the Specific logger text field | |
254 | shell.bot().textInGroup("Specific logger").setText(ControlViewSwtBotUtil.SPECIFIC_LOGGER_NAME1 + "," + ControlViewSwtBotUtil.SPECIFIC_LOGGER_NAME2); | |
255 | // Click the Ok at the bottom of the dialog window | |
256 | shell.bot().button(ControlViewSwtBotUtil.DIALOG_OK_BUTTON).click(); | |
f0beeb4a | 257 | WaitUtils.waitForJobs(); |
a7cfc952 BR |
258 | fBot.waitUntil(ConditionHelpers.IsTreeChildNodeAvailable(domainName, sessionItem)); |
259 | ||
260 | // Assert that the domain is correct | |
261 | domainItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
262 | getNodeName(), | |
263 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
264 | getSessionName(), | |
265 | domainName); | |
266 | assertEquals(domainName, domainItem.getText()); | |
267 | ||
268 | // Assert that the logger type in the domain node are correct (all events = *) | |
269 | loggerItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
270 | getNodeName(), | |
271 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
272 | getSessionName(), | |
273 | domainName, | |
274 | ControlViewSwtBotUtil.SPECIFIC_LOGGER_NAME1); | |
275 | assertEquals(ControlViewSwtBotUtil.SPECIFIC_LOGGER_NAME1, loggerItem.getText()); | |
276 | ||
277 | // Assert that the logger type in the domain node are correct (all events = *) | |
278 | loggerItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
279 | getNodeName(), | |
280 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
281 | getSessionName(), | |
282 | domainName, | |
283 | ControlViewSwtBotUtil.SPECIFIC_LOGGER_NAME2); | |
284 | assertEquals(ControlViewSwtBotUtil.SPECIFIC_LOGGER_NAME2, loggerItem.getText()); | |
0a004264 BR |
285 | } |
286 | ||
287 | /** | |
288 | * Test that the Properties view has been update and shows the the right | |
289 | * information. | |
4a9365ef BR |
290 | * |
291 | * @param domain | |
292 | * the logger domain to test | |
0a004264 | 293 | */ |
4a9365ef BR |
294 | protected void testLoggerProperties(TraceDomainType domain) { |
295 | String domainName = new String(); | |
b5a170e0 | 296 | String logLevel = new String(); |
4a9365ef BR |
297 | switch (domain) { |
298 | case JUL: | |
299 | domainName = ControlViewSwtBotUtil.JUL_DOMAIN_NAME; | |
b5a170e0 | 300 | logLevel = "<= Warning"; |
4a9365ef BR |
301 | break; |
302 | case LOG4J: | |
303 | domainName = ControlViewSwtBotUtil.LOG4J_DOMAIN_NAME; | |
b5a170e0 | 304 | logLevel = "<= Fatal"; |
8a9a09a3 BR |
305 | break; |
306 | case PYTHON: | |
307 | domainName = ControlViewSwtBotUtil.PYTHON_DOMAIN_NAME; | |
b5a170e0 | 308 | logLevel = "<= Critical"; |
4a9365ef BR |
309 | break; |
310 | //$CASES-OMITTED$ | |
311 | default: | |
312 | break; | |
313 | } | |
314 | ||
0a004264 BR |
315 | // Open the properties view (by id) |
316 | SWTBotUtils.openView("org.eclipse.ui.views.PropertySheet"); | |
317 | ||
318 | // Case 1: Select the "logger" logger in the Control view | |
319 | fBot.viewById(ControlView.ID).show(); | |
320 | SWTBotTreeItem loggerItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
321 | getNodeName(), | |
322 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
323 | getSessionName(), | |
4a9365ef | 324 | domainName, |
0a004264 BR |
325 | ControlViewSwtBotUtil.LOGGER_NAME); |
326 | loggerItem.select(); | |
327 | ||
328 | // Get a bot and open the Properties view | |
329 | SWTBotView propertiesViewBot = fBot.viewByTitle(PROPERTIES_VIEW); | |
330 | propertiesViewBot.show(); | |
331 | ||
332 | // Get the Log Level field in the tree | |
333 | SWTBotTree propertiesViewTree = propertiesViewBot.bot().tree(); | |
334 | SWTBotTreeItem loglevelTreeItem = propertiesViewTree.getTreeItem(LOGLEVEL_PROPERTY_NAME); | |
335 | // We want the VALUE of the 'Log Level' row so the cell index is 1 | |
336 | String loglevelExpression = loglevelTreeItem.cell(1); | |
337 | ||
338 | // Assert that the expression in the Properties view is the same as | |
339 | // the one we entered | |
b5a170e0 | 340 | assertEquals("All", loglevelExpression); |
0a004264 BR |
341 | |
342 | // Case 2: Select the "anotherLogger" logger in the Control view | |
343 | fBot.viewById(ControlView.ID).show(); | |
344 | loggerItem = SWTBotUtils.getTreeItem(fBot, fTree, | |
345 | getNodeName(), | |
346 | ControlViewSwtBotUtil.SESSION_GROUP_NAME, | |
347 | getSessionName(), | |
4a9365ef | 348 | domainName, |
0a004264 BR |
349 | ControlViewSwtBotUtil.ANOTHER_LOGGER_NAME); |
350 | loggerItem.select(); | |
351 | ||
352 | // Get a bot and open the Properties view | |
353 | propertiesViewBot = fBot.viewByTitle(PROPERTIES_VIEW); | |
354 | propertiesViewBot.show(); | |
355 | ||
356 | // Get the Log Level field in the tree | |
357 | propertiesViewTree = propertiesViewBot.bot().tree(); | |
358 | loglevelTreeItem = propertiesViewTree.getTreeItem(LOGLEVEL_PROPERTY_NAME); | |
359 | // We want the VALUE of the 'Log Level' row so the cell index is 1 | |
360 | loglevelExpression = loglevelTreeItem.cell(1); | |
361 | ||
362 | // Assert that the expression in the Properties view is the same as | |
363 | // the one we entered | |
b5a170e0 | 364 | assertEquals(logLevel, loglevelExpression); |
0a004264 BR |
365 | |
366 | // Close the Properties view | |
367 | SWTBotUtils.closeView(PROPERTIES_VIEW, fBot); | |
368 | } | |
369 | ||
370 | } |