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