1 /*******************************************************************************
2 * Copyright (c) 2015 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
10 * Patrick Tasse - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.viewers
.events
;
15 import static org
.junit
.Assert
.assertArrayEquals
;
16 import static org
.junit
.Assert
.fail
;
17 import static org
.junit
.Assume
.assumeTrue
;
20 import java
.io
.IOException
;
22 import java
.net
.URISyntaxException
;
24 import java
.util
.ArrayList
;
25 import java
.util
.List
;
27 import org
.apache
.log4j
.ConsoleAppender
;
28 import org
.apache
.log4j
.Logger
;
29 import org
.apache
.log4j
.SimpleLayout
;
30 import org
.eclipse
.core
.runtime
.FileLocator
;
31 import org
.eclipse
.core
.runtime
.Path
;
32 import org
.eclipse
.swt
.widgets
.Table
;
33 import org
.eclipse
.swt
.widgets
.TableColumn
;
34 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
35 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotEditor
;
36 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
37 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
38 import org
.eclipse
.swtbot
.swt
.finder
.results
.ArrayResult
;
39 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
40 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
41 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTableColumn
;
42 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.TmfCoreTestPlugin
;
43 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
44 import org
.junit
.After
;
45 import org
.junit
.AfterClass
;
46 import org
.junit
.Before
;
47 import org
.junit
.BeforeClass
;
48 import org
.junit
.Test
;
49 import org
.junit
.runner
.RunWith
;
52 * SWTBot test for event table column header menu.
54 @RunWith(SWTBotJunit4ClassRunner
.class)
55 public class ColumnHeaderMenuTest
{
57 private static final String TRACE_PROJECT_NAME
= "test";
58 private static final String COLUMN_TRACE
= "syslog_collapse";
59 private static final String COLUMN_TRACE_PATH
= "testfiles/" + COLUMN_TRACE
;
60 private static final String COLUMN_TRACE_TYPE
= "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
62 private static File fTestFile
= null;
64 private static SWTWorkbenchBot fBot
;
65 private SWTBotEditor fEditorBot
;
67 /** The Log4j logger instance. */
68 private static final Logger fLogger
= Logger
.getRootLogger();
74 public static void beforeClass() {
75 SWTBotUtils
.initialize();
77 /* set up test trace */
78 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH
), null);
81 uri
= FileLocator
.toFileURL(location
).toURI();
82 fTestFile
= new File(uri
);
83 } catch (URISyntaxException
| IOException e
) {
87 assumeTrue(fTestFile
.exists());
89 /* Set up for swtbot */
90 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
91 fLogger
.removeAllAppenders();
92 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
93 fBot
= new SWTWorkbenchBot();
95 /* Close welcome view */
96 SWTBotUtils
.closeView("Welcome", fBot
);
98 /* Switch perspectives */
99 SWTBotUtils
.switchToTracingPerspective();
101 /* Finish waiting for eclipse to load */
102 SWTBotUtils
.waitForJobs();
104 SWTBotUtils
.createProject(TRACE_PROJECT_NAME
);
108 * Test class tear down method.
111 public static void afterClass() {
112 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);
113 fLogger
.removeAllAppenders();
120 public void before() {
121 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, fTestFile
.getAbsolutePath(), COLUMN_TRACE_TYPE
);
122 fEditorBot
= SWTBotUtils
.activateEditor(fBot
, fTestFile
.getName());
129 public void after() {
130 fBot
.closeAllEditors();
131 SWTBotUtils
.closeSecondaryShells(fBot
);
135 * Test the check menu items to toggle column visibility
138 public void testToggleColumns() {
139 final SWTBotTable tableBot
= fEditorBot
.bot().table();
140 SWTBotTableColumn headerBot
= tableBot
.header("");
141 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File", "Line", "Message" });
143 headerBot
.contextMenu("Message").click();
144 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File", "Line" });
146 headerBot
.contextMenu("Line").click();
147 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File" });
149 headerBot
.contextMenu("File").click();
150 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger" });
152 headerBot
.contextMenu("Logger").click();
153 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host" });
155 headerBot
.contextMenu("Host").click();
156 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp" });
158 headerBot
.contextMenu("Timestamp").click();
159 assertVisibleColumns(tableBot
.widget
, new String
[] {});
161 headerBot
.contextMenu("Message").click();
162 assertVisibleColumns(tableBot
.widget
, new String
[] { "Message" });
164 headerBot
.contextMenu("Timestamp").click();
165 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Message" });
167 headerBot
.contextMenu("Line").click();
168 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Line", "Message" });
170 headerBot
.contextMenu("Host").click();
171 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Line", "Message" });
173 headerBot
.contextMenu("File").click();
174 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "File", "Line", "Message" });
176 headerBot
.contextMenu("Logger").click();
177 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File", "Line", "Message" });
181 * Test the Show All menu item
184 public void testPersistHiding() {
185 SWTBotTable tableBot
= fEditorBot
.bot().table();
186 SWTBotTableColumn headerBot
= tableBot
.header("");
187 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File", "Line", "Message" });
189 headerBot
.contextMenu("Timestamp").click();
190 headerBot
.contextMenu("Host").click();
191 headerBot
.contextMenu("Logger").click();
192 headerBot
.contextMenu("File").click();
193 headerBot
.contextMenu("Message").click();
194 assertVisibleColumns(tableBot
.widget
, new String
[] { "Line" });
198 tableBot
= fEditorBot
.bot().table();
199 assertVisibleColumns(tableBot
.widget
, new String
[] { "Line" });
200 headerBot
= tableBot
.header("");
201 headerBot
.contextMenu("Show All").click();
202 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File", "Line", "Message" });
206 * Test the Show All menu item
209 public void testShowAll() {
210 final SWTBotTable tableBot
= fEditorBot
.bot().table();
211 SWTBotTableColumn headerBot
= tableBot
.header("");
212 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File", "Line", "Message" });
214 headerBot
.contextMenu("Timestamp").click();
215 headerBot
.contextMenu("Host").click();
216 headerBot
.contextMenu("Logger").click();
217 headerBot
.contextMenu("File").click();
218 headerBot
.contextMenu("Line").click();
219 headerBot
.contextMenu("Message").click();
220 assertVisibleColumns(tableBot
.widget
, new String
[] {});
222 headerBot
.contextMenu("Show All").click();
223 assertVisibleColumns(tableBot
.widget
, new String
[] { "Timestamp", "Host", "Logger", "File", "Line", "Message" });
226 private static void assertVisibleColumns(final Table table
, String
[] expected
) {
227 String
[] actual
= UIThreadRunnable
.syncExec(new ArrayResult
<String
>() {
229 public String
[] run() {
230 List
<String
> visible
= new ArrayList
<>();
231 for (int i
: table
.getColumnOrder()) {
232 TableColumn column
= table
.getColumns()[i
];
233 if (column
.getResizable() && column
.getWidth() > 0) {
234 visible
.add(column
.getText());
237 return visible
.toArray(new String
[0]);
240 assertArrayEquals(expected
, actual
);