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 * Matthew Khouzam - 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
.assertNull
;
17 import static org
.junit
.Assert
.fail
;
18 import static org
.junit
.Assume
.assumeTrue
;
21 import java
.io
.IOException
;
23 import java
.net
.URISyntaxException
;
26 import org
.apache
.log4j
.ConsoleAppender
;
27 import org
.apache
.log4j
.Logger
;
28 import org
.apache
.log4j
.SimpleLayout
;
29 import org
.eclipse
.core
.runtime
.FileLocator
;
30 import org
.eclipse
.core
.runtime
.Path
;
31 import org
.eclipse
.swt
.widgets
.Table
;
32 import org
.eclipse
.swtbot
.eclipse
.finder
.SWTWorkbenchBot
;
33 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotEditor
;
34 import org
.eclipse
.swtbot
.swt
.finder
.finders
.UIThreadRunnable
;
35 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
36 import org
.eclipse
.swtbot
.swt
.finder
.results
.VoidResult
;
37 import org
.eclipse
.swtbot
.swt
.finder
.utils
.SWTBotPreferences
;
38 import org
.eclipse
.swtbot
.swt
.finder
.widgets
.SWTBotTable
;
39 import org
.eclipse
.tracecompass
.tmf
.core
.tests
.TmfCoreTestPlugin
;
40 import org
.eclipse
.tracecompass
.tmf
.ui
.editors
.TmfTraceColumnManager
;
41 import org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.shared
.SWTBotUtils
;
42 import org
.junit
.AfterClass
;
43 import org
.junit
.BeforeClass
;
44 import org
.junit
.Test
;
45 import org
.junit
.runner
.RunWith
;
48 * SWTBot test for testing movable column feature.
50 @RunWith(SWTBotJunit4ClassRunner
.class)
51 public class MovableColumnEventsEditorTest
{
53 private static final String TRACE_PROJECT_NAME
= "test";
54 private static final String COLUMN_TRACE
= "syslog_collapse";
55 private static final String COLUMN_TRACE_PATH
= "testfiles/" + COLUMN_TRACE
;
56 private static final String COLUMN_TRACE_TYPE
= "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
57 private static final String
[] BEFORE_COLS
= new String
[] { "", "Timestamp", "Host", "Logger", "File", "Line", "Message" };
58 private static final String
[] AFTER_COLS
= new String
[] { "", "Timestamp", "Logger", "Host", "File", "Line", "Message" };
60 private static File fTestFile
= null;
62 private static SWTWorkbenchBot fBot
;
64 /** The Log4j logger instance. */
65 private static final Logger fLogger
= Logger
.getRootLogger();
71 public static void init() {
72 SWTBotUtils
.initialize();
74 /* set up test trace */
75 URL location
= FileLocator
.find(TmfCoreTestPlugin
.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH
), null);
78 uri
= FileLocator
.toFileURL(location
).toURI();
79 fTestFile
= new File(uri
);
80 } catch (URISyntaxException
| IOException e
) {
84 assumeTrue(fTestFile
.exists());
86 /* Set up for swtbot */
87 SWTBotPreferences
.TIMEOUT
= 20000; /* 20 second timeout */
88 fLogger
.removeAllAppenders();
89 fLogger
.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender
.SYSTEM_OUT
));
90 fBot
= new SWTWorkbenchBot();
92 /* Close welcome view */
93 SWTBotUtils
.closeView("Welcome", fBot
);
95 /* Switch perspectives */
96 SWTBotUtils
.switchToTracingPerspective();
98 /* Finish waiting for eclipse to load */
99 SWTBotUtils
.waitForJobs();
103 * Test class tear down method.
106 public static void tearDown() {
107 fLogger
.removeAllAppenders();
111 * Main test case, open a trace, reorder columns, check that they are
112 * reordered, reopen it, check that its still reordered, close it, reset,
113 * reopen check that its in the original order.
116 public void testReorder() {
117 SWTBotUtils
.createProject(TRACE_PROJECT_NAME
);
119 // Open the actual trace
120 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, fTestFile
.getAbsolutePath(), COLUMN_TRACE_TYPE
);
121 SWTBotEditor editorBot
= SWTBotUtils
.activateEditor(fBot
, fTestFile
.getName());
123 SWTBotTable tableBot
= editorBot
.bot().table();
125 // Maximize editor area
126 SWTBotUtils
.maximizeTable(tableBot
);
128 // Verify that source code was actually opened
129 assertArrayEquals("Before reorder", BEFORE_COLS
, tableBot
.columns().toArray());
130 final Table table
= tableBot
.widget
;
131 // simulate column drag
132 final int[] newColOrder
= { 0, 1, 3, 2, 4, 5, 6 };
133 UIThreadRunnable
.syncExec(new VoidResult() {
136 table
.setColumnOrder(newColOrder
);
142 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, fTestFile
.getAbsolutePath(), COLUMN_TRACE_TYPE
);
143 editorBot
= SWTBotUtils
.activateEditor(fBot
, fTestFile
.getName());
144 tableBot
= editorBot
.bot().table();
145 // Maximize editor area
146 SWTBotUtils
.maximizeTable(tableBot
);
147 assertArrayEquals("After reorder", AFTER_COLS
, tableBot
.columns().toArray());
150 TmfTraceColumnManager
.clearColumnOrder(COLUMN_TRACE_TYPE
);
151 assertNull("After clear", TmfTraceColumnManager
.loadColumnOrder(COLUMN_TRACE_TYPE
));
152 SWTBotUtils
.openTrace(TRACE_PROJECT_NAME
, fTestFile
.getAbsolutePath(), COLUMN_TRACE_TYPE
);
153 editorBot
= SWTBotUtils
.activateEditor(fBot
, fTestFile
.getName());
154 tableBot
= editorBot
.bot().table();
155 // Maximize editor area
156 SWTBotUtils
.maximizeTable(tableBot
);
157 assertNull("After reset", TmfTraceColumnManager
.loadColumnOrder(COLUMN_TRACE_TYPE
));
158 assertArrayEquals("After reset", BEFORE_COLS
, tableBot
.columns().toArray());
159 fBot
.closeAllEditors();
160 SWTBotUtils
.deleteProject(TRACE_PROJECT_NAME
, fBot
);