Commit | Line | Data |
---|---|---|
693ec829 BH |
1 | /******************************************************************************* |
2 | * Copyright (c) 2013, 2014 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 | * Bernd Hufmann - Initial API and implementation | |
11 | *******************************************************************************/ | |
12 | ||
2bdf0193 | 13 | package org.eclipse.tracecompass.tmf.ui.swtbot.tests.table; |
693ec829 BH |
14 | |
15 | import static org.junit.Assert.assertEquals; | |
16 | import static org.junit.Assert.fail; | |
17 | import static org.junit.Assume.assumeTrue; | |
18 | ||
19 | import java.io.File; | |
20 | import java.io.IOException; | |
21 | import java.net.URI; | |
22 | import java.net.URISyntaxException; | |
23 | import java.net.URL; | |
24 | ||
25 | import org.apache.log4j.ConsoleAppender; | |
26 | import org.apache.log4j.Logger; | |
27 | import org.apache.log4j.SimpleLayout; | |
28 | import org.eclipse.core.runtime.FileLocator; | |
29 | import org.eclipse.core.runtime.Path; | |
30 | import org.eclipse.core.runtime.preferences.IEclipsePreferences; | |
31 | import org.eclipse.core.runtime.preferences.InstanceScope; | |
32 | import org.eclipse.jface.bindings.keys.IKeyLookup; | |
33 | import org.eclipse.jface.bindings.keys.KeyStroke; | |
34 | import org.eclipse.jface.bindings.keys.ParseException; | |
2bdf0193 AM |
35 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
36 | import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin; | |
37 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants; | |
38 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat; | |
39 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.SWTBotUtil; | |
40 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.conditions.ConditionHelpers; | |
693ec829 BH |
41 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
42 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; | |
43 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
44 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
45 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; | |
46 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; | |
47 | import org.junit.AfterClass; | |
48 | import org.junit.BeforeClass; | |
49 | import org.junit.Test; | |
50 | import 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) |
58 | public 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() { | |
77 | SWTBotUtil.failIfUIThread(); | |
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 */ | |
99 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); | |
100 | fBot = new SWTWorkbenchBot(); | |
101 | ||
102 | /* Close welcome view */ | |
103 | SWTBotUtil.closeView("Welcome", fBot); | |
104 | ||
105 | /* Switch perspectives */ | |
106 | SWTBotUtil.switchToTracingPerspective(); | |
107 | ||
108 | /* Finish waiting for eclipse to load */ | |
109 | SWTBotUtil.waitForJobs(); | |
110 | } | |
111 | ||
112 | /** | |
113 | * Test class tear down method. | |
114 | */ | |
115 | @AfterClass | |
116 | public static void tearDown() { | |
117 | /* Set timestamp defaults */ | |
118 | IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); | |
119 | defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, ITmfTimePreferencesConstants.TIME_HOUR_FMT); | |
120 | defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NANO_FMT); | |
121 | TmfTimestampFormat.updateDefaultFormats(); | |
122 | } | |
123 | ||
124 | /** | |
125 | * Main test case | |
126 | */ | |
127 | @Test | |
128 | public void test() { | |
129 | SWTBotUtil.createProject(TRACE_PROJECT_NAME); | |
130 | SWTBotUtil.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLLAPSE_TRACE_TYPE); | |
131 | SWTBotEditor editorBot = SWTBotUtil.openEditor(fBot, fTestFile.getName()); | |
132 | ||
133 | SWTBotTable tableBot = editorBot.bot().table(); | |
134 | ||
135 | /* Maximize editor area */ | |
136 | maximizeTable(tableBot); | |
137 | tableBot.click(1, 0); | |
138 | ||
139 | /* Collapse Events */ | |
140 | SWTBotMenu menuBot = tableBot.contextMenu("Collapse Events"); | |
141 | menuBot.click(); | |
142 | fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "7/22", 1, 1)); | |
143 | ||
144 | String filterString = tableBot.cell(1, 1); | |
145 | assertEquals("filterString", "7/22", filterString); | |
146 | ||
147 | /* Verify collapsed event */ | |
148 | filterString = tableBot.cell(7, 0); | |
149 | assertEquals("repeatCount", "+14", filterString); | |
150 | ||
151 | filterString = tableBot.cell(7, 1); | |
152 | assertEquals("first timestamp", "Jan 1 06:06:06", filterString); | |
153 | ||
154 | filterString = tableBot.cell(7, 2); | |
155 | assertEquals("source", "", filterString); | |
156 | ||
157 | filterString = tableBot.cell(7, 3); | |
158 | assertEquals("type", "Syslog", filterString); | |
159 | ||
160 | filterString = tableBot.cell(7, 4); | |
161 | assertEquals("file", "", filterString); | |
162 | ||
163 | filterString = tableBot.cell(7, 5); | |
164 | assertEquals("content", "Timestamp=Jan 1 06:06:06, Host=HostF, Logger=LoggerF, Message=Message F", filterString); | |
165 | ||
166 | filterString = tableBot.cell(8, 0); | |
167 | assertEquals("repeatCount", "+1", filterString); | |
168 | ||
169 | filterString = tableBot.cell(8, 1); | |
170 | assertEquals("first timestamp (2nd collapse)", "Jan 1 06:06:21", filterString); | |
171 | ||
172 | filterString = tableBot.cell(8, 5); | |
173 | assertEquals("content", "Timestamp=Jan 1 06:06:21, Host=HostF, Logger=LoggerF, Message=Message D", filterString); | |
174 | ||
175 | /* Clear Filter */ | |
176 | menuBot = tableBot.contextMenu("Clear Filters"); | |
177 | menuBot.click(); | |
178 | fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "Jan 1 01:01:01", 1, 1)); | |
179 | assertEquals("timestamp", "Jan 1 01:01:01", tableBot.cell(1, 1)); | |
180 | ||
181 | maximizeTable(tableBot); | |
182 | ||
183 | fBot.closeAllEditors(); | |
184 | SWTBotUtil.deleteProject(TRACE_PROJECT_NAME, fBot); | |
185 | } | |
186 | ||
187 | private static void maximizeTable(SWTBotTable tableBot) { | |
188 | try { | |
189 | tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M")); | |
190 | } catch (ParseException e) { | |
191 | fail(); | |
192 | } | |
193 | } | |
194 | ||
195 | } |