lttng: Relayd connector needs to send VIEWER_CLIENT_COMMAND as payload to be able...
[deliverable/tracecompass.git] / org.eclipse.linuxtools.tmf.ui.swtbot.tests / src / org / eclipse / linuxtools / tmf / ui / swtbot / tests / TestCustomTxtWizard.java
CommitLineData
0ae97cfb
MK
1/*******************************************************************************
2 * Copyright (c) 2014 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 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
12
13package org.eclipse.linuxtools.tmf.ui.swtbot.tests;
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNotNull;
17
18import java.io.File;
19import java.io.FileNotFoundException;
20import java.io.FileWriter;
21import java.io.IOException;
22import java.io.RandomAccessFile;
23
fca952c3 24import org.apache.log4j.ConsoleAppender;
0ae97cfb 25import org.apache.log4j.Logger;
fca952c3 26import org.apache.log4j.SimpleLayout;
0ae97cfb
MK
27import org.eclipse.core.resources.ResourcesPlugin;
28import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
29import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
cbbd323f 30import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
0ae97cfb 31import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
d3d0f69a 32import org.eclipse.swtbot.swt.finder.waits.Conditions;
0ae97cfb
MK
33import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
34import org.junit.BeforeClass;
35import org.junit.Test;
cbbd323f 36import org.junit.runner.RunWith;
0ae97cfb
MK
37
38/**
39 * Custom text wizard tests
40 *
41 * Some reminders to help making tests (javadoc to keep formatting)
42 *
43 * Button reminder
44 *
45 * <pre>
46 * 0 Time Stamp Format Help
47 * 1 Remove line
48 * 2 Add next line
49 * 3 Add child line
50 * 4 Move up
51 * 5 Move down
52 * 6 Regular Expression Help
53 * 7 Remove group (group 1 toggle)
54 * 8 Remove group (group 2 toggle)
55 * 9 Add group (group 3 toggle ...)
56 * 10 Show parsing result
57 * 11 Preview Legend
58 * </pre>
59 *
60 * Combo box reminder
61 *
62 * <pre>
63 * 0 cardinality
64 * 1 event type (message, timestamp...)
65 * 2 how to handle the data (set, append...)
66 * repeat
67 * </pre>
68 *
69 * @author Matthew Khouzam
70 *
71 */
cbbd323f 72@RunWith(SWTBotJunit4ClassRunner.class)
0ae97cfb
MK
73public class TestCustomTxtWizard {
74
d3d0f69a 75 private static final String MANAGE_CUSTOM_PARSERS_SHELL_TITLE = "Manage Custom Parsers";
0ae97cfb
MK
76 private static final String PROJECT_NAME = "Test";
77 private static final String EXPECTED_TEST_DEFINITION = "<Definition name=\"Test\">\n" +
78 "<TimeStampOutputFormat>ss</TimeStampOutputFormat>\n" +
79 "<InputLine>\n" +
80 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
81 "<RegEx>\\s*(\\d\\d)\\s(.*\\S)</RegEx>\n" +
82 "<InputData action=\"0\" format=\"ss\" name=\"Time Stamp\"/>\n" +
83 "<InputData action=\"0\" name=\"Message\"/>\n" +
84 "</InputLine>\n" +
85 "<InputLine>\n" +
86 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
87 "<RegEx>([^0-9]*)</RegEx>\n" +
88 "<InputData action=\"2\" name=\"Message\"/>\n" +
89 "</InputLine>\n" +
90 "<OutputColumn name=\"Time Stamp\"/>\n" +
91 "<OutputColumn name=\"Message\"/>\n";
92
93 /** The Log4j logger instance. */
94 private static final Logger fLogger = Logger.getRootLogger();
95 private static SWTWorkbenchBot fBot;
96
97 /** Test Class setup */
98 @BeforeClass
99 public static void init() {
100 SWTBotUtil.failIfUIThread();
101 Thread.currentThread().setName("SWTBot Thread"); // for the debugger
102 /* set up for swtbot */
103 SWTBotPreferences.TIMEOUT = 20000; /* 20 second timeout */
fca952c3 104 fLogger.addAppender(new ConsoleAppender(new SimpleLayout()));
0ae97cfb
MK
105 fBot = new SWTWorkbenchBot();
106
107 SWTBotUtil.closeView("welcome", fBot);
108
109 SWTBotUtil.switchToTracingPerspective();
110 /* finish waiting for eclipse to load */
111 SWTBotUtil.waitForJobs();
112
113 }
114
115 /**
116 * Test to create a custom txt trace and compare the xml
117 *
118 * @throws IOException
119 * the xml file is not accessible, this is bad
120 * @throws FileNotFoundException
121 * the xml file wasn't written, this is bad
122 */
123 @Test
124 public void testNew() throws FileNotFoundException, IOException {
125 File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.linuxtools.tmf.core/custom_txt_parsers.xml").toFile();
126 SWTBotUtil.createProject(PROJECT_NAME);
127 SWTBotView proejctExplorerBot = fBot.viewByTitle("Project Explorer");
128 proejctExplorerBot.show();
129 SWTBotTreeItem treeItem = proejctExplorerBot.bot().tree().getTreeItem(PROJECT_NAME);
130 treeItem.select();
131 treeItem.expand();
132 SWTBotTreeItem treeNode = null;
133 for (String node : treeItem.getNodes()) {
134 if (node.startsWith("Trace")) {
135 treeNode = treeItem.getNode(node);
136 break;
137 }
138
139 }
140 assertNotNull(treeNode);
141 treeNode.contextMenu("Manage Custom Parsers...").click();
d3d0f69a 142 fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE));
fca952c3 143
0ae97cfb
MK
144 fBot.button("New...").click();
145
146 fBot.textWithLabel("Log type:").setText(PROJECT_NAME);
147 fBot.textWithLabel("Time Stamp format:").setText("ss");
148 fBot.comboBox(1).setSelection("Time Stamp");
149 fBot.textWithLabel("format:").setText("ss");
150 fBot.button(8).click();
151 fBot.button(2).click();
152 SWTBotTreeItem[] treeItems = fBot.tree().getAllItems();
153 SWTBotTreeItem eventLine[] = new SWTBotTreeItem[2];
154 treeItems = fBot.tree().getAllItems();
155 for (SWTBotTreeItem item : treeItems) {
156 if (item.getText().startsWith("Root Line 1")) {
157 eventLine[0] = item;
158 }
159 if (item.getText().startsWith("Root Line 2")) {
160 eventLine[1] = item;
161 }
162 }
163 assertNotNull(eventLine[0]);
164 assertNotNull(eventLine[1]);
165 fBot.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world");
166 eventLine[0].select();
167 SWTBotUtil.waitForJobs();
168 fBot.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)");
169 eventLine[1].select();
170 fBot.textWithLabel("Regular expression:").setText("([^0-9]*)");
171 fBot.button(7).click();
172 fBot.comboBox("Set").setSelection("Append with |");
173 fBot.button("Highlight All").click();
174 fBot.button("Next >").click();
175 fBot.button("Finish").click();
176 fBot.list().select(PROJECT_NAME);
177 String xmlPart = extractTestXml(xmlFile, PROJECT_NAME);
178 assertEquals(EXPECTED_TEST_DEFINITION, xmlPart);
179 fBot.button("Delete").click();
180 fBot.button("Yes").click();
181 fBot.button("Close").click();
182 xmlPart = extractTestXml(xmlFile, PROJECT_NAME);
183 assertEquals("", xmlPart);
184 }
185
186 /**
187 * Test to edit a custom txt trace and compare the xml
188 *
189 * @throws IOException
190 * the xml file is not accessible, this is bad
191 * @throws FileNotFoundException
192 * the xml file wasn't written, this is bad
193 */
194 @Test
195 public void testEdit() throws FileNotFoundException, IOException {
196 File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.linuxtools.tmf.core/custom_txt_parsers.xml").toFile();
197 try (FileWriter fw = new FileWriter(xmlFile)) {
198 String xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
199 "<CustomTxtTraceDefinitionList>\n" +
200 "<Definition name=\"Demo trace\">\n" +
201 "<TimeStampOutputFormat>sss</TimeStampOutputFormat>\n" +
202 "<InputLine>\n" +
203 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
204 "<RegEx>\\s*(\\d*)\\s(.*)</RegEx>\n" +
205 "<InputData action=\"0\" format=\"sss\" name=\"Time Stamp\"/>\n" +
206 "<InputData action=\"0\" name=\"Message\"/>\n" +
207 "</InputLine>\n" +
208 "<OutputColumn name=\"Time Stamp\"/>\n" +
209 "<OutputColumn name=\"Message\"/>\n" +
210 "</Definition>\n" +
211 "<Definition name=\"dmesg\">\n" +
212 "<TimeStampOutputFormat>sssssss.ssssss</TimeStampOutputFormat>\n" +
213 "<InputLine>\n" +
214 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
215 "<RegEx>^[([0-9]*\\.[0.9]*)]\\s(.*)</RegEx>\n" +
216 "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Time Stamp\"/>\n" +
217 "<InputData action=\"0\" name=\"Message\"/>\n" +
218 "</InputLine>\n" +
219 "<OutputColumn name=\"Time Stamp\"/>\n" +
220 "<OutputColumn name=\"Message\"/>\n" +
221 "</Definition>\n" +
222 "</CustomTxtTraceDefinitionList>";
223 fw.write(xmlContent);
224 fw.flush();
225 }
226 SWTBotUtil.createProject(PROJECT_NAME);
227 SWTBotView proejctExplorerBot = fBot.viewByTitle("Project Explorer");
228 proejctExplorerBot.show();
229 SWTBotTreeItem treeItem = proejctExplorerBot.bot().tree().getTreeItem(PROJECT_NAME);
230 treeItem.select();
231 treeItem.expand();
232 SWTBotTreeItem treeNode = null;
233 for (String node : treeItem.getNodes()) {
234 if (node.startsWith("Trace")) {
235 treeNode = treeItem.getNode(node);
236 break;
237 }
238
239 }
240 assertNotNull(treeNode);
241 treeNode.contextMenu("Manage Custom Parsers...").click();
d3d0f69a 242 fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE));
0ae97cfb
MK
243 fBot.list().select(fBot.list().getItems()[0]);
244 fBot.button("Edit...").click();
245
246 fBot.textWithLabel("Log type:").setText(PROJECT_NAME);
247 fBot.textWithLabel("Time Stamp format:").setText("ss");
248 fBot.comboBox(1).setSelection("Time Stamp");
249 fBot.textWithLabel("format:").setText("ss");
250 fBot.button(2).click();
251 SWTBotTreeItem[] treeItems = fBot.tree().getAllItems();
252 SWTBotTreeItem eventLine[] = new SWTBotTreeItem[2];
253 for (SWTBotTreeItem item : treeItems) {
254 if (item.getText().startsWith("Root Line 1")) {
255 eventLine[0] = item;
256 }
257 if (item.getText().startsWith("Root Line 2")) {
258 eventLine[1] = item;
259 }
260 }
261 treeItems = fBot.tree().getAllItems();
262 assertNotNull(eventLine[0]);
263 assertNotNull(eventLine[1]);
264 fBot.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world");
265 eventLine[0].select();
266 SWTBotUtil.waitForJobs();
267 fBot.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)");
268 eventLine[1].select();
269 fBot.textWithLabel("Regular expression:").setText("([^0-9]*)");
270 fBot.button(7).click();
271 fBot.comboBox("Set").setSelection("Append with |");
272 fBot.button("Highlight All").click();
273 fBot.button("Next >").click();
274 fBot.button("Finish").click();
275 fBot.list().select(PROJECT_NAME);
276 String xmlPart = extractTestXml(xmlFile, PROJECT_NAME);
277 assertEquals(EXPECTED_TEST_DEFINITION, xmlPart);
278 fBot.button("Delete").click();
279 fBot.button("Yes").click();
280 fBot.button("Close").click();
281 xmlPart = extractTestXml(xmlFile, PROJECT_NAME);
282 assertEquals("", xmlPart);
283 }
284
285 private static String extractTestXml(File xmlFile, String definitionName) throws IOException, FileNotFoundException {
286 StringBuilder xmlPart = new StringBuilder();
287 boolean started = false;
288 try (RandomAccessFile raf = new RandomAccessFile(xmlFile, "r");) {
289 String s = raf.readLine();
290 while (s != null) {
291 if (s.equals("<Definition name=\"" + definitionName + "\">")) {
292 started = true;
293 }
294 if (started) {
295 if (s.equals("</Definition>")) {
296 break;
297 }
298 xmlPart.append(s);
299 xmlPart.append('\n');
300 }
301 s = raf.readLine();
302 }
303 }
304 return xmlPart.toString();
305 }
306}
This page took 0.041348 seconds and 5 git commands to generate.