swtbot: Introducing ImageHelper
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / CollapseEventsInTableTest.java
CommitLineData
693ec829 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2013, 2015 Ericsson
693ec829
BH
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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
fa24d78b 13package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
693ec829
BH
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.fail;
17import static org.junit.Assume.assumeTrue;
18
19import java.io.File;
20import java.io.IOException;
21import java.net.URI;
22import java.net.URISyntaxException;
23import java.net.URL;
24
25import org.apache.log4j.ConsoleAppender;
26import org.apache.log4j.Logger;
27import org.apache.log4j.SimpleLayout;
28import org.eclipse.core.runtime.FileLocator;
29import org.eclipse.core.runtime.Path;
30import org.eclipse.core.runtime.preferences.IEclipsePreferences;
31import org.eclipse.core.runtime.preferences.InstanceScope;
32import org.eclipse.jface.bindings.keys.IKeyLookup;
33import org.eclipse.jface.bindings.keys.KeyStroke;
34import org.eclipse.jface.bindings.keys.ParseException;
2bdf0193
AM
35import org.eclipse.tracecompass.internal.tmf.core.Activator;
36import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin;
37import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants;
38import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat;
fa24d78b
AM
39import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers;
40import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
693ec829
BH
41import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
42import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor;
43import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
44import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
45import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu;
46import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
47import org.junit.AfterClass;
48import org.junit.BeforeClass;
49import org.junit.Test;
50import org.junit.runner.RunWith;
51
52/**
53 * SWTBot test for testing collapsing feature.
54 *
55 * @author Bernd Hufmann
56 */
693ec829
BH
57@RunWith(SWTBotJunit4ClassRunner.class)
58public class CollapseEventsInTableTest {
59
60 private static final String TRACE_PROJECT_NAME = "test";
61 private static final String COLLAPSE_TRACE_NAME = "syslog_collapse";
62 private static final String COLLAPSE_TRACE_PATH = "testfiles/" + COLLAPSE_TRACE_NAME;
63 private static final String COLLAPSE_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
64
65 private static File fTestFile = null;
66
67 private static SWTWorkbenchBot fBot;
68
69 /** The Log4j logger instance. */
70 private static final Logger fLogger = Logger.getRootLogger();
71
72 /**
73 * Test Class setup
74 */
75 @BeforeClass
76 public static void init() {
fa24d78b 77 SWTBotUtils.failIfUIThread();
693ec829
BH
78
79 /* set up test trace*/
80 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLLAPSE_TRACE_PATH), null);
81 URI uri;
82 try {
83 uri = FileLocator.toFileURL(location).toURI();
84 fTestFile = new File(uri);
85 } catch (URISyntaxException | IOException e) {
86 e.printStackTrace();
87 fail();
88 }
89
90 assumeTrue(fTestFile.exists());
91
92 IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
93 defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "MMM d HH:mm:ss");
94 defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NO_FMT);
95 TmfTimestampFormat.updateDefaultFormats();
96
97 /* Set up for swtbot */
98 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
f10c30a0 99 fLogger.removeAllAppenders();
693ec829
BH
100 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
101 fBot = new SWTWorkbenchBot();
102
103 /* Close welcome view */
fa24d78b 104 SWTBotUtils.closeView("Welcome", fBot);
693ec829
BH
105
106 /* Switch perspectives */
fa24d78b 107 SWTBotUtils.switchToTracingPerspective();
693ec829
BH
108
109 /* Finish waiting for eclipse to load */
fa24d78b 110 SWTBotUtils.waitForJobs();
693ec829
BH
111 }
112
113 /**
114 * Test class tear down method.
115 */
116 @AfterClass
117 public static void tearDown() {
f10c30a0 118 fLogger.removeAllAppenders();
693ec829
BH
119 /* Set timestamp defaults */
120 IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
121 defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, ITmfTimePreferencesConstants.TIME_HOUR_FMT);
122 defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NANO_FMT);
123 TmfTimestampFormat.updateDefaultFormats();
124 }
125
126 /**
127 * Main test case
128 */
129 @Test
130 public void test() {
fa24d78b
AM
131 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
132 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLLAPSE_TRACE_TYPE);
133 SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
693ec829
BH
134
135 SWTBotTable tableBot = editorBot.bot().table();
136
137 /* Maximize editor area */
138 maximizeTable(tableBot);
139 tableBot.click(1, 0);
140
141 /* Collapse Events */
142 SWTBotMenu menuBot = tableBot.contextMenu("Collapse Events");
143 menuBot.click();
144 fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "7/22", 1, 1));
145
5b12450f
PT
146 String cell = tableBot.cell(1, 1);
147 assertEquals("filterString", "7/22", cell);
148
149 /* Verify first collapsed event */
150 cell = tableBot.cell(7, 0);
151 assertEquals("1st repeatCount", "+14", cell);
152 cell = tableBot.cell(7, 1);
153 assertEquals("1st Timestamp", "Jan 1 06:06:06", cell);
154 cell = tableBot.cell(7, 2);
155 assertEquals("1st Host", "HostF", cell);
156 cell = tableBot.cell(7, 3);
157 assertEquals("1st Logger", "LoggerF", cell);
158 cell = tableBot.cell(7, 4);
159 assertEquals("1st File", "SourceFile", cell);
160 cell = tableBot.cell(7, 5);
161 assertEquals("1st Line", "9", cell);
162 cell = tableBot.cell(7, 6);
163 assertEquals("1st Message", "Message F", cell);
164
165 /* Verify second collapsed event */
166 cell = tableBot.cell(8, 0);
167 assertEquals("2nd repeatCount", "+1", cell);
168 cell = tableBot.cell(8, 1);
169 assertEquals("2nd Timestamp", "Jan 1 06:06:21", cell);
170 cell = tableBot.cell(8, 2);
171 assertEquals("2nd Host", "HostF", cell);
172 cell = tableBot.cell(8, 3);
173 assertEquals("2nd Logger", "LoggerF", cell);
174 cell = tableBot.cell(8, 4);
175 assertEquals("2nd File", "SourceFile", cell);
176 cell = tableBot.cell(8, 5);
177 assertEquals("2nd Line", "10", cell);
178 cell = tableBot.cell(8, 6);
179 assertEquals("2nd Message", "Message D", cell);
693ec829
BH
180
181 /* Clear Filter */
182 menuBot = tableBot.contextMenu("Clear Filters");
183 menuBot.click();
184 fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "Jan 1 01:01:01", 1, 1));
5b12450f 185 assertEquals("Timestamp", "Jan 1 01:01:01", tableBot.cell(1, 1));
693ec829
BH
186
187 maximizeTable(tableBot);
188
189 fBot.closeAllEditors();
fa24d78b 190 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
693ec829
BH
191 }
192
193 private static void maximizeTable(SWTBotTable tableBot) {
194 try {
195 tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
196 } catch (ParseException e) {
197 fail();
198 }
199 }
200
201}
This page took 0.048233 seconds and 5 git commands to generate.