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