Copyright header update, 2015 edition
[deliverable/tracecompass.git] / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / viewers / events / CallsiteEventsInTableTest.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 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 * Bernd Hufmann - Initial API and implementation
11 *******************************************************************************/
12
13 package org.eclipse.tracecompass.tmf.ui.swtbot.tests.viewers.events;
14
15 import static org.junit.Assert.assertTrue;
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;
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.shared.SWTBotUtils;
40 import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
41 import org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory;
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.eclipse.ui.IEditorReference;
48 import org.hamcrest.Matcher;
49 import org.junit.AfterClass;
50 import org.junit.BeforeClass;
51 import org.junit.Test;
52 import org.junit.runner.RunWith;
53
54 /**
55 * SWTBot test for testing callsite feature.
56 *
57 * @author Bernd Hufmann
58 */
59 @RunWith(SWTBotJunit4ClassRunner.class)
60 public class CallsiteEventsInTableTest {
61
62 private static final String TRACE_PROJECT_NAME = "test";
63 private static final String CALLSITE_TRACE_NAME = "syslog_collapse";
64 private static final String CALLSITE_TRACE_PATH = "testfiles/" + CALLSITE_TRACE_NAME;
65 private static final String CALLSITE_TRACE_TYPE = "org.eclipse.linuxtools.tmf.tests.stubs.trace.text.testsyslog";
66 private static final String SOURCE_FILE_NAME = "SourceFile";
67 private static final String SOURCE_FILE_PATH = "testfiles/" + SOURCE_FILE_NAME;
68
69 private static File fTestFile = null;
70 private static File fSourceFile = null;
71
72 private static SWTWorkbenchBot fBot;
73
74 /** The Log4j logger instance. */
75 private static final Logger fLogger = Logger.getRootLogger();
76
77 /**
78 * Test Class setup
79 */
80 @BeforeClass
81 public static void init() {
82 SWTBotUtils.failIfUIThread();
83
84 /* set up test trace*/
85 URL location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(CALLSITE_TRACE_PATH), null);
86 URI uri;
87 try {
88 uri = FileLocator.toFileURL(location).toURI();
89 fTestFile = new File(uri);
90 } catch (URISyntaxException | IOException e) {
91 e.printStackTrace();
92 fail();
93 }
94
95 assumeTrue(fTestFile.exists());
96
97 IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
98 defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, "MMM d HH:mm:ss");
99 defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NO_FMT);
100 TmfTimestampFormat.updateDefaultFormats();
101
102 /* Create source file link */
103 location = FileLocator.find(TmfCoreTestPlugin.getDefault().getBundle(), new Path(SOURCE_FILE_PATH), null);
104 try {
105 uri = FileLocator.toFileURL(location).toURI();
106 fSourceFile = new File(uri);
107 } catch (URISyntaxException | IOException e) {
108 e.printStackTrace();
109 fail();
110 }
111
112 assumeTrue(fSourceFile.exists());
113
114
115
116 /* Set up for swtbot */
117 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
118 fLogger.addAppender(new ConsoleAppender(new SimpleLayout(), ConsoleAppender.SYSTEM_OUT));
119 fBot = new SWTWorkbenchBot();
120
121 /* Close welcome view */
122 SWTBotUtils.closeView("Welcome", fBot);
123
124 /* Switch perspectives */
125 SWTBotUtils.switchToTracingPerspective();
126
127 /* Finish waiting for eclipse to load */
128 SWTBotUtils.waitForJobs();
129 }
130
131 /**
132 * Test class tear down method.
133 */
134 @AfterClass
135 public static void tearDown() {
136 /* Set timestamp defaults */
137 IEclipsePreferences defaultPreferences = InstanceScope.INSTANCE.getNode(Activator.PLUGIN_ID);
138 defaultPreferences.put(ITmfTimePreferencesConstants.DATIME, ITmfTimePreferencesConstants.TIME_HOUR_FMT);
139 defaultPreferences.put(ITmfTimePreferencesConstants.SUBSEC, ITmfTimePreferencesConstants.SUBSEC_NANO_FMT);
140 TmfTimestampFormat.updateDefaultFormats();
141 }
142
143 /**
144 * Main test case
145 */
146 @Test
147 public void test() {
148 SWTBotUtils.createProject(TRACE_PROJECT_NAME);
149
150 // Open source file as a unknown trace
151 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fSourceFile.getAbsolutePath(), null);
152
153 // Open the actual trace
154 SWTBotUtils.openTrace(TRACE_PROJECT_NAME, fTestFile.getAbsolutePath(), CALLSITE_TRACE_TYPE);
155 SWTBotEditor editorBot = SWTBotUtils.activateEditor(fBot, fTestFile.getName());
156
157 SWTBotTable tableBot = editorBot.bot().table();
158
159 // Maximize editor area
160 maximizeTable(tableBot);
161 tableBot.click(1, 0);
162
163 // Open source code location
164 SWTBotMenu menuBot = tableBot.contextMenu("Open Source Code");
165 menuBot.click();
166
167 // Verify that source code was actually opened
168 Matcher<IEditorReference> matcher = WidgetMatcherFactory.withPartName(fSourceFile.getName());
169 final SWTBotEditor sourceEditorBot = fBot.editor(matcher);
170 assertTrue(sourceEditorBot.isActive());
171
172 maximizeTable(tableBot);
173
174 fBot.closeAllEditors();
175 SWTBotUtils.deleteProject(TRACE_PROJECT_NAME, fBot);
176 }
177
178 private static void maximizeTable(SWTBotTable tableBot) {
179 try {
180 tableBot.pressShortcut(KeyStroke.getInstance(IKeyLookup.CTRL_NAME + "+"), KeyStroke.getInstance("M"));
181 } catch (ParseException e) {
182 fail();
183 }
184 }
185
186 }
This page took 0.038046 seconds and 5 git commands to generate.