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
.junit
.Test
;
27 * Test for the Control view in Trace Compass. This will test the different logger domain.
31 public class ControlViewLoggerTest
extends ControlViewTest
{
33 // ------------------------------------------------------------------------
35 // ------------------------------------------------------------------------
36 private static final String TEST_STREAM
= "CreateSessionTestLTTng2_8.cfg";
37 private static final String CREATE_SESSION_JUL_SCENARIO_NAME
= "JulLogger";
38 private static final String CREATE_SESSION_LOG4J_SCENARIO_NAME
= "Log4jLogger";
39 private static final String CREATE_SESSION_PYTHON_SCENARIO_NAME
= "PythonLogger";
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";
46 protected String
getTestStream() {
51 protected String
getSessionName() {
56 * Testing the trace session tree.
60 public void testTraceSessionTree() {
62 fProxy
.setTestFile(fTestFile
);
63 fProxy
.setScenario(INIT_SCENARIO_NAME
);
67 fProxy
.setScenario(CREATE_SESSION_JUL_SCENARIO_NAME
);
69 testEnableLoggers(TraceDomainType
.JUL
);
70 testStartStopTracing(TraceSessionState
.ACTIVE
);
71 testStartStopTracing(TraceSessionState
.INACTIVE
);
72 // Verify that the Properties view shows to right logger log level
73 testLoggerProperties(TraceDomainType
.JUL
);
75 // Enable LOG4J loggers
76 fProxy
.setScenario(CREATE_SESSION_LOG4J_SCENARIO_NAME
);
77 testEnableLoggers(TraceDomainType
.LOG4J
);
78 testStartStopTracing(TraceSessionState
.ACTIVE
);
79 testStartStopTracing(TraceSessionState
.INACTIVE
);
80 // Verify that the Properties view shows to right logger log level
81 testLoggerProperties(TraceDomainType
.LOG4J
);
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
);
93 testDisconnectFromNode();
97 * Enable loggers with different log level and log level type
100 * the logger domain to test
102 protected void testEnableLoggers(TraceDomainType domain
) {
103 String domainName
= new String();
104 String logLevel
= new String();
107 domainName
= ControlViewSwtBotUtil
.JUL_DOMAIN_NAME
;
108 logLevel
= "Warning";
111 domainName
= ControlViewSwtBotUtil
.LOG4J_DOMAIN_NAME
;
115 domainName
= ControlViewSwtBotUtil
.PYTHON_DOMAIN_NAME
;
116 logLevel
= "Critical";
122 // Case 1: Enabling all loggers
123 // Getting the 'Sessions' tree
124 SWTBotTreeItem sessionItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
126 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
128 sessionItem
.select();
130 // Clicking on the 'Enable Event (default channel)...'
131 SWTBotMenu menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
134 SWTBotShell shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
136 // Switching to the logger domain
137 shell
.bot().radioInGroup(domainName
, ControlViewSwtBotUtil
.DOMAIN_GROUP_NAME
).click();
139 // Selecting all loggers
140 SWTBotTree loggersTree
= shell
.bot().treeInGroup(ControlViewSwtBotUtil
.LOGGERS_GROUP_NAME
);
141 SWTBotTreeItem treeItem
= loggersTree
.getTreeItem(ControlViewSwtBotUtil
.ALL_TREE_NODE
);
144 // Click the Ok at the bottom of the dialog window
145 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
146 SWTBotUtils
.waitForJobs();
147 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(domainName
, sessionItem
));
149 // Assert that the domain is correct
150 SWTBotTreeItem domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
152 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
155 assertEquals(domainName
, domainItem
.getText());
157 // Assert that the logger type in the domain node are correct (all events = *)
158 SWTBotTreeItem loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
160 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
163 ControlViewSwtBotUtil
.ALL_EVENTS_NAME
);
164 assertEquals(ControlViewSwtBotUtil
.ALL_EVENTS_NAME
, loggerItem
.getText());
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
);
170 shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
171 shell
.bot().radioInGroup(domainName
, ControlViewSwtBotUtil
.DOMAIN_GROUP_NAME
).click();
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
);
176 allItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, ControlViewSwtBotUtil
.LOGGER_APPLICATION_NAME
);
178 treeItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
,
179 ControlViewSwtBotUtil
.ALL_TREE_NODE
,
180 ControlViewSwtBotUtil
.LOGGER_APPLICATION_NAME
,
181 ControlViewSwtBotUtil
.LOGGER_NAME
);
184 // Click the Ok at the bottom of the dialog window
185 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
186 SWTBotUtils
.waitForJobs();
187 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(domainName
, sessionItem
));
189 // Assert that the domain is correct
190 domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
192 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
195 assertEquals(domainName
, domainItem
.getText());
197 // Assert that the logger type in the domain node are correct (all events = *)
198 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
200 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
203 ControlViewSwtBotUtil
.LOGGER_NAME
);
204 assertEquals(ControlViewSwtBotUtil
.LOGGER_NAME
, loggerItem
.getText());
206 // Case 3: Enabling a specific logger with a log level
207 sessionItem
.select();
208 menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
210 shell
= fBot
.shell(ControlViewSwtBotUtil
.ENABLE_EVENT_DIALOG_TITLE
).activate();
211 shell
.bot().radioInGroup(domainName
, ControlViewSwtBotUtil
.DOMAIN_GROUP_NAME
).click();
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
);
216 allItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, "All - ./client_bin/challenger [PID=14237] (With logger)");
218 treeItem
= SWTBotUtils
.getTreeItem(fBot
, loggersTree
, ControlViewSwtBotUtil
.ALL_TREE_NODE
, "All - ./client_bin/challenger [PID=14237] (With logger)", ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
);
220 // Select a log level
221 shell
.bot().checkBoxInGroup(LOGLEVEL_PROPERTY_NAME
).select();
222 shell
.bot().ccomboBoxInGroup(LOGLEVEL_PROPERTY_NAME
).setSelection(logLevel
);
223 // Click the Ok at the bottom of the dialog window
224 shell
.bot().button(ControlViewSwtBotUtil
.DIALOG_OK_BUTTON
).click();
225 SWTBotUtils
.waitForJobs();
226 fBot
.waitUntil(ConditionHelpers
.IsTreeChildNodeAvailable(domainName
, sessionItem
));
228 // Assert that the domain is correct
229 domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
231 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
234 assertEquals(domainName
, domainItem
.getText());
236 // Assert that the logger type in the domain node are correct (all events = *)
237 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
239 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
242 ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
);
243 assertEquals(ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
, loggerItem
.getText());
245 // Case 4: Enabling a logger by specifying the name
246 sessionItem
.select();
247 menuBot
= sessionItem
.contextMenu(ControlViewSwtBotUtil
.ENABLE_EVENT_DEFAULT_CHANNEL_MENU_ITEM
);
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
));
259 // Assert that the domain is correct
260 domainItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
262 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
265 assertEquals(domainName
, domainItem
.getText());
267 // Assert that the logger type in the domain node are correct (all events = *)
268 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
270 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
273 ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME1
);
274 assertEquals(ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME1
, loggerItem
.getText());
276 // Assert that the logger type in the domain node are correct (all events = *)
277 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
279 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
282 ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME2
);
283 assertEquals(ControlViewSwtBotUtil
.SPECIFIC_LOGGER_NAME2
, loggerItem
.getText());
287 * Test that the Properties view has been update and shows the the right
291 * the logger domain to test
293 protected void testLoggerProperties(TraceDomainType domain
) {
294 String domainName
= new String();
295 String logLevel1
= new String();
296 String logLevel2
= new String();
299 domainName
= ControlViewSwtBotUtil
.JUL_DOMAIN_NAME
;
301 logLevel2
= "<= Warning";
304 domainName
= ControlViewSwtBotUtil
.LOG4J_DOMAIN_NAME
;
306 logLevel2
= "<= Fatal";
309 domainName
= ControlViewSwtBotUtil
.PYTHON_DOMAIN_NAME
;
311 logLevel2
= "<= Critical";
318 // Open the properties view (by id)
319 SWTBotUtils
.openView("org.eclipse.ui.views.PropertySheet");
321 // Case 1: Select the "logger" logger in the Control view
322 fBot
.viewById(ControlView
.ID
).show();
323 SWTBotTreeItem loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
325 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
328 ControlViewSwtBotUtil
.LOGGER_NAME
);
331 // Get a bot and open the Properties view
332 SWTBotView propertiesViewBot
= fBot
.viewByTitle(PROPERTIES_VIEW
);
333 propertiesViewBot
.show();
335 // Get the Log Level field in the tree
336 SWTBotTree propertiesViewTree
= propertiesViewBot
.bot().tree();
337 SWTBotTreeItem loglevelTreeItem
= propertiesViewTree
.getTreeItem(LOGLEVEL_PROPERTY_NAME
);
338 // We want the VALUE of the 'Log Level' row so the cell index is 1
339 String loglevelExpression
= loglevelTreeItem
.cell(1);
341 // Assert that the expression in the Properties view is the same as
342 // the one we entered
343 assertEquals(logLevel1
, loglevelExpression
);
345 // Case 2: Select the "anotherLogger" logger in the Control view
346 fBot
.viewById(ControlView
.ID
).show();
347 loggerItem
= SWTBotUtils
.getTreeItem(fBot
, fTree
,
349 ControlViewSwtBotUtil
.SESSION_GROUP_NAME
,
352 ControlViewSwtBotUtil
.ANOTHER_LOGGER_NAME
);
355 // Get a bot and open the Properties view
356 propertiesViewBot
= fBot
.viewByTitle(PROPERTIES_VIEW
);
357 propertiesViewBot
.show();
359 // Get the Log Level field in the tree
360 propertiesViewTree
= propertiesViewBot
.bot().tree();
361 loglevelTreeItem
= propertiesViewTree
.getTreeItem(LOGLEVEL_PROPERTY_NAME
);
362 // We want the VALUE of the 'Log Level' row so the cell index is 1
363 loglevelExpression
= loglevelTreeItem
.cell(1);
365 // Assert that the expression in the Properties view is the same as
366 // the one we entered
367 assertEquals(logLevel2
, loglevelExpression
);
369 // Close the Properties view
370 SWTBotUtils
.closeView(PROPERTIES_VIEW
, fBot
);