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