1 /*******************************************************************************
2 * Copyright (c) 2016 Ericsson
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 *******************************************************************************/
10 package org
.eclipse
.tracecompass
.lttng2
.control
.ui
.swtbot
.tests
;
12 import static org
.junit
.Assert
.assertEquals
;
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
;
19 import org
.eclipse
.tracecompass
.internal
.lttng2
.control
.core
.model
.TraceDomainType
;
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
.eclipse
.tracecompass
.tmf
.ui
.tests
.shared
.WaitUtils
;
25 import org
.junit
.Test
;
28 * Test for the Control view in Trace Compass. This will test the different logger domain.
32 public class ControlViewLoggerTest
extends ControlViewTest
{
34 // ------------------------------------------------------------------------
36 // ------------------------------------------------------------------------
37 private static final String TEST_STREAM
= "CreateSessionTestLTTng2_8.cfg";
38 private static final String CREATE_SESSION_JUL_SCENARIO_NAME
= "JulLogger";
39 private static final String CREATE_SESSION_LOG4J_SCENARIO_NAME
= "Log4jLogger";
40 private static final String CREATE_SESSION_PYTHON_SCENARIO_NAME
= "PythonLogger";
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";
47 protected String
getTestStream() {
52 protected String
getSessionName() {
57 * Testing the trace session tree.
61 public void testTraceSessionTree() {
63 fProxy
.setTestFile(fTestFile
);
64 fProxy
.setScenario(INIT_SCENARIO_NAME
);
68 fProxy
.setScenario(CREATE_SESSION_JUL_SCENARIO_NAME
);
70 testEnableLoggers(TraceDomainType
.JUL
);
71 testStartStopTracing(TraceSessionState
.ACTIVE
);
72 testStartStopTracing(TraceSessionState
.INACTIVE
);
73 // Verify that the Properties view shows to right logger log level
74 testLoggerProperties(TraceDomainType
.JUL
);
76 // Enable LOG4J loggers
77 fProxy
.setScenario(CREATE_SESSION_LOG4J_SCENARIO_NAME
);
78 testEnableLoggers(TraceDomainType
.LOG4J
);
79 testStartStopTracing(TraceSessionState
.ACTIVE
);
80 testStartStopTracing(TraceSessionState
.INACTIVE
);
81 // Verify that the Properties view shows to right logger log level
82 testLoggerProperties(TraceDomainType
.LOG4J
);
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
);
94 testDisconnectFromNode();
98 * Enable loggers with different log level and log level type
101 * the logger domain to test
103 protected void testEnableLoggers(TraceDomainType domain
) {
104 String domainName
= new String();
105 String logLevel
= new String();
108 domainName
= ControlViewSwtBotUtil
.JUL_DOMAIN_NAME
;
109 logLevel
= "Warning";
112 domainName
= ControlViewSwtBotUtil
.LOG4J_DOMAIN_NAME
;
116 domainName
= ControlViewSwtBotUtil
.PYTHON_DOMAIN_NAME
;
117 logLevel
= "Critical";
123 // Case 1: Enabling all loggers
124 // Getting the 'Sessions' tree
125 SWTBotTreeItem sessionItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
127 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
129 sessionItem
.select();
131 // Clicking on the 'Enable Event (default channel)...'
132 SWTBotMenu menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
135 SWTBotShell shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
137 // Switching to the logger domain
138 shell
.bot().radioInGroup(domainName
, ControlViewSwtBotUtil
.DOMAIN_GROUP_NAME
).click();
140 // Selecting all loggers
141 SWTBotTree loggersTree
= shell
.bot().treeInGroup(ControlViewSwtBotUtil
.LOGGERS_GROUP_NAME
);
142 SWTBotTreeItem treeItem
= loggersTree
.getTreeItem(ControlViewSwtBotUtil
.ALL_TREE_NODE
);
145 // Click the Ok at the bottom of the dialog window
146 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
147 WaitUtils
.waitForJobs();
148 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(domainName
, sessionItem
));
150 // Assert that the domain is correct
151 SWTBotTreeItem domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
153 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
156 assertEquals(domainName
, domainItem
.getText());
158 // Assert that the logger type in the domain node are correct (all events = *)
159 SWTBotTreeItem loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
161 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
164 ControlViewSwtBotUtil
.ALL_EVENTS_NAME
);
165 assertEquals(ControlViewSwtBotUtil
.ALL_EVENTS_NAME
, loggerItem
.getText());
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
);
171 shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
172 shell
.bot().radioInGroup(domainName
, ControlViewSwtBotUtil
.DOMAIN_GROUP_NAME
).click();
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
);
177 allItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, ControlViewSwtBotUtil
.LOGGER_APPLICATION_NAME
);
179 treeItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
,
180 ControlViewSwtBotUtil
.ALL_TREE_NODE
,
181 ControlViewSwtBotUtil
.LOGGER_APPLICATION_NAME
,
182 ControlViewSwtBotUtil
.LOGGER_NAME
);
185 // Click the Ok at the bottom of the dialog window
186 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
187 WaitUtils
.waitForJobs();
188 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(domainName
, sessionItem
));
190 // Assert that the domain is correct
191 domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
193 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
196 assertEquals(domainName
, domainItem
.getText());
198 // Assert that the logger type in the domain node are correct (all events = *)
199 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
201 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
204 ControlViewSwtBotUtil
.LOGGER_NAME
);
205 assertEquals(ControlViewSwtBotUtil
.LOGGER_NAME
, loggerItem
.getText());
207 // Case 3: Enabling a specific logger with a log level
208 sessionItem
.select();
209 menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
211 shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
212 shell
.bot().radioInGroup(domainName
, ControlViewSwtBotUtil
.DOMAIN_GROUP_NAME
).click();
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
);
217 allItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, "All - ./client_bin/challenger [PID=14237] (With logger)");
219 treeItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, "All - ./client_bin/challenger [PID=14237] (With logger)", ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
);
221 // Select a log level
222 shell
.bot().checkBoxInGroup(LOGLEVEL_PROPERTY_NAME
).select();
223 shell
.bot().ccomboBoxInGroup(LOGLEVEL_PROPERTY_NAME
).setSelection(logLevel
);
224 // Click the Ok at the bottom of the dialog window
225 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
226 WaitUtils
.waitForJobs();
227 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(domainName
, sessionItem
));
229 // Assert that the domain is correct
230 domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
232 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
235 assertEquals(domainName
, domainItem
.getText());
237 // Assert that the logger type in the domain node are correct (all events = *)
238 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
240 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
243 ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
);
244 assertEquals(ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
, loggerItem
.getText());
246 // Case 4: Enabling a logger by specifying the name
247 sessionItem
.select();
248 menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
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();
257 WaitUtils
.waitForJobs();
258 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(domainName
, sessionItem
));
260 // Assert that the domain is correct
261 domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
263 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
266 assertEquals(domainName
, domainItem
.getText());
268 // Assert that the logger type in the domain node are correct (all events = *)
269 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
271 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
274 ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME1
);
275 assertEquals(ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME1
, loggerItem
.getText());
277 // Assert that the logger type in the domain node are correct (all events = *)
278 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
280 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
283 ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME2
);
284 assertEquals(ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME2
, loggerItem
.getText());
288 * Test that the Properties view has been update and shows the the right
292 * the logger domain to test
294 protected void testLoggerProperties(TraceDomainType domain
) {
295 String domainName
= new String();
296 String logLevel
= new String();
299 domainName
= ControlViewSwtBotUtil
.JUL_DOMAIN_NAME
;
300 logLevel
= "<= Warning";
303 domainName
= ControlViewSwtBotUtil
.LOG4J_DOMAIN_NAME
;
304 logLevel
= "<= Fatal";
307 domainName
= ControlViewSwtBotUtil
.PYTHON_DOMAIN_NAME
;
308 logLevel
= "<= Critical";
315 // Open the properties view (by id)
316 SWTBotUtils
.openView("org.eclipse.ui.views.PropertySheet");
318 // Case 1: Select the "logger" logger in the Control view
319 fBot
.viewById(ControlView
.ID
).show();
320 SWTBotTreeItem loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
322 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
325 ControlViewSwtBotUtil
.LOGGER_NAME
);
328 // Get a bot and open the Properties view
329 SWTBotView propertiesViewBot
= fBot
.viewByTitle(PROPERTIES_VIEW
);
330 propertiesViewBot
.show();
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);
338 // Assert that the expression in the Properties view is the same as
339 // the one we entered
340 assertEquals("All", loglevelExpression
);
342 // Case 2: Select the "anotherLogger" logger in the Control view
343 fBot
.viewById(ControlView
.ID
).show();
344 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
346 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
349 ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
);
352 // Get a bot and open the Properties view
353 propertiesViewBot
= fBot
.viewByTitle(PROPERTIES_VIEW
);
354 propertiesViewBot
.show();
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);
362 // Assert that the expression in the Properties view is the same as
363 // the one we entered
364 assertEquals(logLevel
, loglevelExpression
);
366 // Close the Properties view
367 SWTBotUtils
.closeView(PROPERTIES_VIEW
, fBot
);