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