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