Commit | Line | Data |
---|---|---|
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 | 13 | package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events; |
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; | |
693ec829 BH |
32 | import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; |
33 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotEditor; | |
34 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; | |
35 | import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences; | |
36 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotMenu; | |
37 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable; | |
328e5fe4 MK |
38 | import org.eclipse.tracecompass.internal.tmf.core.Activator; |
39 | import org.eclipse.tracecompass.tmf.core.tests.TmfCoreTestPlugin; | |
40 | import org.eclipse.tracecompass.tmf.core.timestamp.ITmfTimePreferencesConstants; | |
41 | import org.eclipse.tracecompass.tmf.core.timestamp.TmfTimestampFormat; | |
42 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.ConditionHelpers; | |
43 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; | |
f0beeb4a | 44 | import org.eclipse.tracecompass.tmf.ui.tests.shared.WaitUtils; |
693ec829 BH |
45 | import org.junit.AfterClass; |
46 | import org.junit.BeforeClass; | |
47 | import org.junit.Test; | |
48 | import org.junit.runner.RunWith; | |
49 | ||
50 | /** | |
51 | * SWTBot test for testing collapsing feature. | |
52 | * | |
53 | * @author Bernd Hufmann | |
54 | */ | |
693ec829 BH |
55 | @RunWith(SWTBotJunit4ClassRunner.class) |
56 | public class CollapseEventsInTableTest { | |
57 | ||
58 | private static final String TRACE_PROJECT_NAME = "test"; | |
59 | private static final String COLLAPSE_TRACE_NAME = "syslog_collapse"; | |
60 | private static final String COLLAPSE_TRACE_PATH = "testfiles/" + COLLAPSE_TRACE_NAME; | |
61 | private static final String COLLAPSE_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog"; | |
62 | ||
63 | private static File fTestFile = null; | |
64 | ||
65 | private static SWTWorkbenchBot fBot; | |
66 | ||
67 | /** The Log4j logger instance. */ | |
68 | private static final Logger fLogger = Logger.getRootLogger(); | |
69 | ||
70 | /** | |
71 | * Test Class setup | |
72 | */ | |
73 | @BeforeClass | |
74 | public static void init() { | |
5785ab49 | 75 | SWTBotUtils.initialize(); |
693ec829 BH |
76 | |
77 | /* set up test trace*/ | |
78 | URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(COLLAPSE_TRACE_PATH), null); | |
79 | URI uri; | |
80 | try { | |
81 | uri = FileLocator.toFileURL(location).toURI(); | |
82 | fTestFile = new File(uri); | |
83 | } catch (URISyntaxException | IOException e) { | |
84 | e.printStackTrace(); | |
85 | fail(); | |
86 | } | |
87 | ||
88 | assumeTrue(fTestFile.exists()); | |
89 | ||
90 | IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID); | |
91 | defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "MMM d HH:mm:ss"); | |
92 | defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NO_FMT); | |
93 | TmfTimestampFormat.updateDefaultFormats(); | |
94 | ||
95 | /* Set up for swtbot */ | |
96 | SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */ | |
f10c30a0 | 97 | fLogger.removeAllAppenders(); |
693ec829 BH |
98 | fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT)); |
99 | fBot = new SWTWorkbenchBot(); | |
100 | ||
101 | /* Close welcome view */ | |
fa24d78b | 102 | SWTBotUtils.closeView("Welcome", fBot); |
693ec829 BH |
103 | |
104 | /* Switch perspectives */ | |
fa24d78b | 105 | SWTBotUtils.switchToTracingPerspective(); |
693ec829 BH |
106 | |
107 | /* Finish waiting for eclipse to load */ | |
f0beeb4a | 108 | WaitUtils.waitForJobs(); |
693ec829 BH |
109 | } |
110 | ||
111 | /** | |
112 | * Test class tear down method. | |
113 | */ | |
114 | @AfterClass | |
115 | public static void tearDown() { | |
f10c30a0 | 116 | fLogger.removeAllAppenders(); |
693ec829 BH |
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() { | |
fa24d78b AM |
129 | SWTBotUtils.createProject(TRACE_PROJECT_NAME); |
130 | SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), COLLAPSE_TRACE_TYPE); | |
131 | SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName()); | |
693ec829 BH |
132 | |
133 | SWTBotTable tableBot = editorBot.bot().table(); | |
134 | ||
135 | /* Maximize editor area */ | |
328e5fe4 | 136 | SWTBotUtils.maximizeTable(tableBot); |
693ec829 BH |
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 | ||
5b12450f PT |
144 | String cell = tableBot.cell(1, 1); |
145 | assertEquals("filterString", "7/22", cell); | |
146 | ||
147 | /* Verify first collapsed event */ | |
148 | cell = tableBot.cell(7, 0); | |
149 | assertEquals("1st repeatCount", "+14", cell); | |
150 | cell = tableBot.cell(7, 1); | |
151 | assertEquals("1st Timestamp", "Jan 1 06:06:06", cell); | |
152 | cell = tableBot.cell(7, 2); | |
153 | assertEquals("1st Host", "HostF", cell); | |
154 | cell = tableBot.cell(7, 3); | |
155 | assertEquals("1st Logger", "LoggerF", cell); | |
156 | cell = tableBot.cell(7, 4); | |
157 | assertEquals("1st File", "SourceFile", cell); | |
158 | cell = tableBot.cell(7, 5); | |
159 | assertEquals("1st Line", "9", cell); | |
160 | cell = tableBot.cell(7, 6); | |
161 | assertEquals("1st Message", "Message F", cell); | |
162 | ||
163 | /* Verify second collapsed event */ | |
164 | cell = tableBot.cell(8, 0); | |
165 | assertEquals("2nd repeatCount", "+1", cell); | |
166 | cell = tableBot.cell(8, 1); | |
167 | assertEquals("2nd Timestamp", "Jan 1 06:06:21", cell); | |
168 | cell = tableBot.cell(8, 2); | |
169 | assertEquals("2nd Host", "HostF", cell); | |
170 | cell = tableBot.cell(8, 3); | |
171 | assertEquals("2nd Logger", "LoggerF", cell); | |
172 | cell = tableBot.cell(8, 4); | |
173 | assertEquals("2nd File", "SourceFile", cell); | |
174 | cell = tableBot.cell(8, 5); | |
175 | assertEquals("2nd Line", "10", cell); | |
176 | cell = tableBot.cell(8, 6); | |
177 | assertEquals("2nd Message", "Message D", cell); | |
693ec829 BH |
178 | |
179 | /* Clear Filter */ | |
180 | menuBot = tableBot.contextMenu("Clear Filters"); | |
181 | menuBot.click(); | |
182 | fBot.waitUntil(ConditionHelpers.isTableCellFilled(tableBot, "Jan 1 01:01:01", 1, 1)); | |
5b12450f | 183 | assertEquals("Timestamp", "Jan 1 01:01:01", tableBot.cell(1, 1)); |
693ec829 | 184 | |
328e5fe4 | 185 | SWTBotUtils.maximizeTable(tableBot); |
693ec829 BH |
186 | |
187 | fBot.closeAllEditors(); | |
fa24d78b | 188 | SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot); |
693ec829 | 189 | } |
693ec829 | 190 | } |