tmf: Add waitUntil / condition to tmf.ui.tests
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / MovableColumnEventsEditorTest.java
1 /*******************************************************************************
2 * Copyright (c) 2015 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 * Contributors:
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
14
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;
19
20 import java.io.File;
21 import java.io.IOException;
22 import java.net.URI;
23 import java.net.URISyntaxException;
24 import java.net.URL;
25
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.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils;
43 import org.junit.AfterClass;
44 import org.junit.BeforeClass;
45 import org.junit.Test;
46 import org.junit.runner.RunWith;
47
48 /**
49 * SWTBot test for testing movable column feature.
50 */
51 @RunWith(SWTBotJunit4ClassRunner.class)
52 public class MovableColumnEventsEditorTest {
53
54 private static final String TRACE_PROJECT_NAME = "test";
55 private static final String COLUMN_TRACE = "syslog_collapse";
56 private static final String COLUMN_TRACE_PATH = "testfiles/" + COLUMN_TRACE;
57 private static final String COLUMN_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
58 private static final String[] BEFORE_COLS = new String[] { "", "Timestamp", "Host", "Logger", "File", "Line", "Message" };
59 private static final String[] AFTER_COLS = new String[] { "", "Timestamp", "Logger", "Host", "File", "Line", "Message" };
60
61 private static File fTestFile = null;
62
63 private static SWTWorkbenchBot fBot;
64
65 /** The Log4j logger instance. */
66 private static final Logger fLogger = Logger.getRootLogger();
67
68 /**
69 * Test Class setup
70 */
71 @BeforeClass
72 public static void init() {
73 SWTBotUtils.initialize();
74
75 /* set up test trace */
76 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLUMN_TRACE_PATH), null);
77 URI uri;
78 try {
79 uri = FileLocator.toFileURL(location).toURI();
80 fTestFile = new File(uri);
81 } catch (URISyntaxException | IOException e) {
82 fail(e.getMessage());
83 }
84
85 assumeTrue(fTestFile.exists());
86
87 /* Set up for swtbot */
88 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
89 fLogger.removeAllAppenders();
90 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
91 fBot = new SWTWorkbenchBot();
92
93 /* Close welcome view */
94 SWTBotUtils.closeView("Welcome", fBot);
95
96 /* Switch perspectives */
97 SWTBotUtils.switchToTracingPerspective();
98
99 /* Finish waiting for eclipse to load */
100 WaitUtils.waitForJobs();
101 }
102
103 /**
104 * Test class tear down method.
105 */
106 @AfterClass
107 public static void tearDown() {
108 fLogger.removeAllAppenders();
109 }
110
111 /**
112 * Main test case, open a trace, reorder columns, check that they are
113 * reordered, reopen it, check that its still reordered, close it, reset,
114 * reopen check that its in the original order.
115 */
116 @Test
117 public void testReorder() {
118 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
119
120 // Open the actual trace
121 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
122 SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
123
124 SWTBotTable tableBot = editorBot.bot().table();
125
126 // Maximize editor area
127 SWTBotUtils.maximizeTable(tableBot);
128
129 // Verify that source code was actually opened
130 assertArrayEquals("Before reorder", BEFORE_COLS, tableBot.columns().toArray());
131 final Table table = tableBot.widget;
132 // simulate column drag
133 final int[] newColOrder = { 0, 1, 3, 2, 4, 5, 6 };
134 UIThreadRunnable.syncExec(new VoidResult() {
135 @Override
136 public void run() {
137 table.setColumnOrder(newColOrder);
138 }
139 });
140
141 // close and re-open
142 editorBot.close();
143 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
144 editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
145 tableBot = editorBot.bot().table();
146 // Maximize editor area
147 SWTBotUtils.maximizeTable(tableBot);
148 assertArrayEquals("After reorder", AFTER_COLS, tableBot.columns().toArray());
149 // close and re-open
150 editorBot.close();
151 TmfTraceColumnManager.clearColumnOrder(COLUMN_TRACE_TYPE);
152 assertNull("After clear", TmfTraceColumnManager.loadColumnOrder(COLUMN_TRACE_TYPE));
153 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLUMN_TRACE_TYPE);
154 editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
155 tableBot = editorBot.bot().table();
156 // Maximize editor area
157 SWTBotUtils.maximizeTable(tableBot);
158 assertNull("After reset", TmfTraceColumnManager.loadColumnOrder(COLUMN_TRACE_TYPE));
159 assertArrayEquals("After reset", BEFORE_COLS, tableBot.columns().toArray());
160 fBot.closeAllEditors();
161 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
162 }
163 }
This page took 0.035227 seconds and 5 git commands to generate.