doc: Mention that all LTTng-Analyses are now supported
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / parsers / custom / TestCustomTxtWizard.java
CommitLineData
0ae97cfb 1/*******************************************************************************
f5cc6ed1 2 * Copyright (c) 2014, 2016 Ericsson
0ae97cfb
MK
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
fa24d78b 13package org.eclipse.tracecompass.tmf.ui.swtbot.tests.parsers.custom;
0ae97cfb
MK
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;
0ae97cfb 22
0ae97cfb 23import org.eclipse.core.resources.ResourcesPlugin;
0ae97cfb 24import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
cbbd323f 25import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
4284e0e1 26import org.eclipse.swtbot.swt.finder.waits.Conditions;
0ae97cfb 27import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
fa24d78b 28import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
0ae97cfb 29import org.junit.Test;
cbbd323f 30import org.junit.runner.RunWith;
0ae97cfb
MK
31
32/**
33 * Custom text wizard tests
34 *
35 * Some reminders to help making tests (javadoc to keep formatting)
36 *
37 * Button reminder
38 *
39 * <pre>
40 * 0 Time Stamp Format Help
41 * 1 Remove line
42 * 2 Add next line
43 * 3 Add child line
44 * 4 Move up
45 * 5 Move down
46 * 6 Regular Expression Help
47 * 7 Remove group (group 1 toggle)
48 * 8 Remove group (group 2 toggle)
49 * 9 Add group (group 3 toggle ...)
50 * 10 Show parsing result
51 * 11 Preview Legend
52 * </pre>
53 *
54 * Combo box reminder
55 *
56 * <pre>
57 * 0 cardinality
58 * 1 event type (message, timestamp...)
59 * 2 how to handle the data (set, append...)
60 * repeat
61 * </pre>
62 *
63 * @author Matthew Khouzam
0ae97cfb 64 */
cbbd323f 65@RunWith(SWTBotJunit4ClassRunner.class)
41a0d150 66public class TestCustomTxtWizard extends AbstractCustomParserWizard {
0ae97cfb 67
d3d0f69a 68 private static final String MANAGE_CUSTOM_PARSERS_SHELL_TITLE = "Manage Custom Parsers";
4284e0e1 69 private static final String CUSTOM_TEXT_PARSER_SHELL_TITLE = "Custom Text Parser";
41a0d150 70 private static final String PROJECT_NAME = "TestText";
c22ca172
PT
71 private static final String CATEGORY_NAME = "Test Category";
72 private static final String TRACETYPE_NAME = "Test Trace";
73 private static final String EXPECTED_TEST_DEFINITION = "<Definition category=\"Test Category\" name=\"Test Trace\">\n" +
0ae97cfb
MK
74 "<TimeStampOutputFormat>ss</TimeStampOutputFormat>\n" +
75 "<InputLine>\n" +
76 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
77 "<RegEx>\\s*(\\d\\d)\\s(.*\\S)</RegEx>\n" +
f5cc6ed1
PT
78 "<InputData action=\"0\" format=\"ss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
79 "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
0ae97cfb
MK
80 "</InputLine>\n" +
81 "<InputLine>\n" +
82 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
83 "<RegEx>([^0-9]*)</RegEx>\n" +
f5cc6ed1 84 "<InputData action=\"2\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
0ae97cfb 85 "</InputLine>\n" +
f5cc6ed1
PT
86 "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
87 "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n";
0ae97cfb 88
0ae97cfb
MK
89 /**
90 * Test to create a custom txt trace and compare the xml
91 *
92 * @throws IOException
93 * the xml file is not accessible, this is bad
94 * @throws FileNotFoundException
95 * the xml file wasn't written, this is bad
96 */
97 @Test
98 public void testNew() throws FileNotFoundException, IOException {
c77a695a 99 File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_txt_parsers.xml").toFile();
53f17e49 100 // Open the custom parsers dialog
fa24d78b 101 SWTBotUtils.createProject(PROJECT_NAME);
53f17e49
GB
102 SWTBotView projectExplorerBot = fBot.viewByTitle("Project Explorer");
103 projectExplorerBot.show();
104 SWTBotTreeItem treeItem = projectExplorerBot.bot().tree().getTreeItem(PROJECT_NAME);
0ae97cfb
MK
105 treeItem.select();
106 treeItem.expand();
107 SWTBotTreeItem treeNode = null;
108 for (String node : treeItem.getNodes()) {
109 if (node.startsWith("Trace")) {
110 treeNode = treeItem.getNode(node);
111 break;
112 }
113
114 }
115 assertNotNull(treeNode);
116 treeNode.contextMenu("Manage Custom Parsers...").click();
4284e0e1 117 fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE));
8af624a8 118 fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus();
fca952c3 119
53f17e49 120 // Open the new custom txt parser dialog
0ae97cfb 121 fBot.button("New...").click();
4284e0e1 122 fBot.waitUntil(Conditions.shellIsActive(CUSTOM_TEXT_PARSER_SHELL_TITLE));
0ae97cfb 123
53f17e49 124 // Setting header
c22ca172
PT
125 fBot.textWithLabel("Category:").setText(CATEGORY_NAME);
126 fBot.textWithLabel("Trace type:").setText(TRACETYPE_NAME);
0ae97cfb 127 fBot.textWithLabel("Time Stamp format:").setText("ss");
53f17e49
GB
128
129 // Fill Group 1 as time stamp
f5cc6ed1 130 fBot.comboBox(1).setSelection("Timestamp");
0ae97cfb 131 fBot.textWithLabel("format:").setText("ss");
53f17e49 132 // Click on the New group button
0ae97cfb 133 fBot.button(8).click();
53f17e49 134 // Add next line
0ae97cfb
MK
135 fBot.button(2).click();
136 SWTBotTreeItem[] treeItems = fBot.tree().getAllItems();
137 SWTBotTreeItem eventLine[] = new SWTBotTreeItem[2];
138 treeItems = fBot.tree().getAllItems();
139 for (SWTBotTreeItem item : treeItems) {
140 if (item.getText().startsWith("Root Line 1")) {
141 eventLine[0] = item;
142 }
143 if (item.getText().startsWith("Root Line 2")) {
144 eventLine[1] = item;
145 }
146 }
147 assertNotNull(eventLine[0]);
148 assertNotNull(eventLine[1]);
53f17e49 149 // Set the regular expression for each event line
0ae97cfb
MK
150 fBot.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world");
151 eventLine[0].select();
fa24d78b 152 SWTBotUtils.waitForJobs();
0ae97cfb
MK
153 fBot.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)");
154 eventLine[1].select();
155 fBot.textWithLabel("Regular expression:").setText("([^0-9]*)");
53f17e49 156 // Click on the new group of root line 2
0ae97cfb
MK
157 fBot.button(7).click();
158 fBot.comboBox("Set").setSelection("Append with |");
159 fBot.button("Highlight All").click();
160 fBot.button("Next >").click();
161 fBot.button("Finish").click();
dcd374bb 162 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION));
c22ca172 163 String xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME);
0ae97cfb 164 assertEquals(EXPECTED_TEST_DEFINITION, xmlPart);
c22ca172 165 fBot.list().select(CATEGORY_NAME + " : " + TRACETYPE_NAME);
0ae97cfb
MK
166 fBot.button("Delete").click();
167 fBot.button("Yes").click();
168 fBot.button("Close").click();
dcd374bb 169 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, ""));
c22ca172 170 xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME);
0ae97cfb 171 assertEquals("", xmlPart);
93c91230 172
fa24d78b 173 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
0ae97cfb
MK
174 }
175
176 /**
177 * Test to edit a custom txt trace and compare the xml
178 *
179 * @throws IOException
180 * the xml file is not accessible, this is bad
181 * @throws FileNotFoundException
182 * the xml file wasn't written, this is bad
183 */
184 @Test
185 public void testEdit() throws FileNotFoundException, IOException {
c77a695a 186 File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_txt_parsers.xml").toFile();
0ae97cfb
MK
187 try (FileWriter fw = new FileWriter(xmlFile)) {
188 String xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
189 "<CustomTxtTraceDefinitionList>\n" +
c22ca172 190 "<Definition category=\"Demo Category\" name=\"Demo trace\">\n" +
0ae97cfb
MK
191 "<TimeStampOutputFormat>sss</TimeStampOutputFormat>\n" +
192 "<InputLine>\n" +
193 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
194 "<RegEx>\\s*(\\d*)\\s(.*)</RegEx>\n" +
f5cc6ed1
PT
195 "<InputData action=\"0\" format=\"sss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
196 "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
0ae97cfb 197 "</InputLine>\n" +
f5cc6ed1
PT
198 "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
199 "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" +
0ae97cfb
MK
200 "</Definition>\n" +
201 "<Definition name=\"dmesg\">\n" +
202 "<TimeStampOutputFormat>sssssss.ssssss</TimeStampOutputFormat>\n" +
203 "<InputLine>\n" +
204 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
205 "<RegEx>^[([0-9]*\\.[0.9]*)]\\s(.*)</RegEx>\n" +
f5cc6ed1
PT
206 "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
207 "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" +
0ae97cfb 208 "</InputLine>\n" +
f5cc6ed1
PT
209 "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" +
210 "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" +
0ae97cfb
MK
211 "</Definition>\n" +
212 "</CustomTxtTraceDefinitionList>";
213 fw.write(xmlContent);
214 fw.flush();
215 }
53f17e49 216 // Open the custom parsers dialog
fa24d78b 217 SWTBotUtils.createProject(PROJECT_NAME);
0ae97cfb
MK
218 SWTBotView proejctExplorerBot = fBot.viewByTitle("Project Explorer");
219 proejctExplorerBot.show();
220 SWTBotTreeItem treeItem = proejctExplorerBot.bot().tree().getTreeItem(PROJECT_NAME);
221 treeItem.select();
222 treeItem.expand();
223 SWTBotTreeItem treeNode = null;
224 for (String node : treeItem.getNodes()) {
225 if (node.startsWith("Trace")) {
226 treeNode = treeItem.getNode(node);
227 break;
228 }
229
230 }
231 assertNotNull(treeNode);
232 treeNode.contextMenu("Manage Custom Parsers...").click();
4284e0e1 233 fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE));
53f17e49 234 // Open the edition dialog for txt parser
8af624a8 235 fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus();
c22ca172 236 fBot.list().select("Demo Category : Demo trace");
0ae97cfb 237 fBot.button("Edit...").click();
4284e0e1 238 fBot.waitUntil(Conditions.shellIsActive(CUSTOM_TEXT_PARSER_SHELL_TITLE));
0ae97cfb 239
53f17e49 240 // update parser's data
c22ca172
PT
241 fBot.textWithLabel("Category:").setText(CATEGORY_NAME);
242 fBot.textWithLabel("Trace type:").setText(TRACETYPE_NAME);
0ae97cfb 243 fBot.textWithLabel("Time Stamp format:").setText("ss");
53f17e49
GB
244
245 // update time stamp format
f5cc6ed1 246 fBot.comboBox(1).setSelection("Timestamp");
0ae97cfb
MK
247 fBot.textWithLabel("format:").setText("ss");
248 fBot.button(2).click();
249 SWTBotTreeItem[] treeItems = fBot.tree().getAllItems();
250 SWTBotTreeItem eventLine[] = new SWTBotTreeItem[2];
251 for (SWTBotTreeItem item : treeItems) {
252 if (item.getText().startsWith("Root Line 1")) {
253 eventLine[0] = item;
254 }
255 if (item.getText().startsWith("Root Line 2")) {
256 eventLine[1] = item;
257 }
258 }
259 treeItems = fBot.tree().getAllItems();
260 assertNotNull(eventLine[0]);
261 assertNotNull(eventLine[1]);
262 fBot.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world");
263 eventLine[0].select();
fa24d78b 264 SWTBotUtils.waitForJobs();
0ae97cfb
MK
265 fBot.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)");
266 eventLine[1].select();
267 fBot.textWithLabel("Regular expression:").setText("([^0-9]*)");
268 fBot.button(7).click();
269 fBot.comboBox("Set").setSelection("Append with |");
270 fBot.button("Highlight All").click();
271 fBot.button("Next >").click();
272 fBot.button("Finish").click();
dcd374bb 273 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION));
c22ca172 274 String xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME);
0ae97cfb 275 assertEquals(EXPECTED_TEST_DEFINITION, xmlPart);
c22ca172 276 fBot.list().select(CATEGORY_NAME + " : " + TRACETYPE_NAME);
0ae97cfb
MK
277 fBot.button("Delete").click();
278 fBot.button("Yes").click();
279 fBot.button("Close").click();
dcd374bb 280 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, ""));
c22ca172 281 xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME);
0ae97cfb 282 assertEquals("", xmlPart);
93c91230 283
fa24d78b 284 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
0ae97cfb 285 }
0ae97cfb 286}
This page took 0.084392 seconds and 5 git commands to generate.