Commit | Line | Data |
---|---|---|
0ae97cfb | 1 | /******************************************************************************* |
ed902a2b | 2 | * Copyright (c) 2014, 2015 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 | 13 | package org.eclipse.tracecompass.tmf.ui.swtbot.tests.parsers.custom; |
0ae97cfb MK |
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; | |
0ae97cfb | 22 | |
0ae97cfb | 23 | import org.eclipse.core.resources.ResourcesPlugin; |
0ae97cfb | 24 | import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView; |
cbbd323f | 25 | import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; |
4284e0e1 | 26 | import org.eclipse.swtbot.swt.finder.waits.Conditions; |
0ae97cfb | 27 | import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem; |
fa24d78b | 28 | import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils; |
0ae97cfb | 29 | import org.junit.Test; |
cbbd323f | 30 | import 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 | 66 | public 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" + | |
78 | "<InputData action=\"0\" format=\"ss\" name=\"Time Stamp\"/>\n" + | |
79 | "<InputData action=\"0\" name=\"Message\"/>\n" + | |
80 | "</InputLine>\n" + | |
81 | "<InputLine>\n" + | |
82 | "<Cardinality max=\"2147483647\" min=\"0\"/>\n" + | |
83 | "<RegEx>([^0-9]*)</RegEx>\n" + | |
84 | "<InputData action=\"2\" name=\"Message\"/>\n" + | |
85 | "</InputLine>\n" + | |
86 | "<OutputColumn name=\"Time Stamp\"/>\n" + | |
87 | "<OutputColumn name=\"Message\"/>\n"; | |
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(); |
fa24d78b | 100 | SWTBotUtils.createProject(PROJECT_NAME); |
0ae97cfb MK |
101 | SWTBotView proejctExplorerBot = fBot.viewByTitle("Project Explorer"); |
102 | proejctExplorerBot.show(); | |
103 | SWTBotTreeItem treeItem = proejctExplorerBot.bot().tree().getTreeItem(PROJECT_NAME); | |
104 | treeItem.select(); | |
105 | treeItem.expand(); | |
106 | SWTBotTreeItem treeNode = null; | |
107 | for (String node : treeItem.getNodes()) { | |
108 | if (node.startsWith("Trace")) { | |
109 | treeNode = treeItem.getNode(node); | |
110 | break; | |
111 | } | |
112 | ||
113 | } | |
114 | assertNotNull(treeNode); | |
115 | treeNode.contextMenu("Manage Custom Parsers...").click(); | |
4284e0e1 | 116 | fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE)); |
8af624a8 | 117 | fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus(); |
fca952c3 | 118 | |
0ae97cfb | 119 | fBot.button("New...").click(); |
4284e0e1 | 120 | fBot.waitUntil(Conditions.shellIsActive(CUSTOM_TEXT_PARSER_SHELL_TITLE)); |
0ae97cfb | 121 | |
c22ca172 PT |
122 | fBot.textWithLabel("Category:").setText(CATEGORY_NAME); |
123 | fBot.textWithLabel("Trace type:").setText(TRACETYPE_NAME); | |
0ae97cfb MK |
124 | fBot.textWithLabel("Time Stamp format:").setText("ss"); |
125 | fBot.comboBox(1).setSelection("Time Stamp"); | |
126 | fBot.textWithLabel("format:").setText("ss"); | |
127 | fBot.button(8).click(); | |
128 | fBot.button(2).click(); | |
129 | SWTBotTreeItem[] treeItems = fBot.tree().getAllItems(); | |
130 | SWTBotTreeItem eventLine[] = new SWTBotTreeItem[2]; | |
131 | treeItems = fBot.tree().getAllItems(); | |
132 | for (SWTBotTreeItem item : treeItems) { | |
133 | if (item.getText().startsWith("Root Line 1")) { | |
134 | eventLine[0] = item; | |
135 | } | |
136 | if (item.getText().startsWith("Root Line 2")) { | |
137 | eventLine[1] = item; | |
138 | } | |
139 | } | |
140 | assertNotNull(eventLine[0]); | |
141 | assertNotNull(eventLine[1]); | |
142 | fBot.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world"); | |
143 | eventLine[0].select(); | |
fa24d78b | 144 | SWTBotUtils.waitForJobs(); |
0ae97cfb MK |
145 | fBot.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)"); |
146 | eventLine[1].select(); | |
147 | fBot.textWithLabel("Regular expression:").setText("([^0-9]*)"); | |
148 | fBot.button(7).click(); | |
149 | fBot.comboBox("Set").setSelection("Append with |"); | |
150 | fBot.button("Highlight All").click(); | |
151 | fBot.button("Next >").click(); | |
152 | fBot.button("Finish").click(); | |
dcd374bb | 153 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION)); |
c22ca172 | 154 | String xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 155 | assertEquals(EXPECTED_TEST_DEFINITION, xmlPart); |
c22ca172 | 156 | fBot.list().select(CATEGORY_NAME + " : " + TRACETYPE_NAME); |
0ae97cfb MK |
157 | fBot.button("Delete").click(); |
158 | fBot.button("Yes").click(); | |
159 | fBot.button("Close").click(); | |
dcd374bb | 160 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, "")); |
c22ca172 | 161 | xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 162 | assertEquals("", xmlPart); |
93c91230 | 163 | |
fa24d78b | 164 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); |
0ae97cfb MK |
165 | } |
166 | ||
167 | /** | |
168 | * Test to edit a custom txt trace and compare the xml | |
169 | * | |
170 | * @throws IOException | |
171 | * the xml file is not accessible, this is bad | |
172 | * @throws FileNotFoundException | |
173 | * the xml file wasn't written, this is bad | |
174 | */ | |
175 | @Test | |
176 | public void testEdit() throws FileNotFoundException, IOException { | |
c77a695a | 177 | File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_txt_parsers.xml").toFile(); |
0ae97cfb MK |
178 | try (FileWriter fw = new FileWriter(xmlFile)) { |
179 | String xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + | |
180 | "<CustomTxtTraceDefinitionList>\n" + | |
c22ca172 | 181 | "<Definition category=\"Demo Category\" name=\"Demo trace\">\n" + |
0ae97cfb MK |
182 | "<TimeStampOutputFormat>sss</TimeStampOutputFormat>\n" + |
183 | "<InputLine>\n" + | |
184 | "<Cardinality max=\"2147483647\" min=\"0\"/>\n" + | |
185 | "<RegEx>\\s*(\\d*)\\s(.*)</RegEx>\n" + | |
186 | "<InputData action=\"0\" format=\"sss\" name=\"Time Stamp\"/>\n" + | |
187 | "<InputData action=\"0\" name=\"Message\"/>\n" + | |
188 | "</InputLine>\n" + | |
189 | "<OutputColumn name=\"Time Stamp\"/>\n" + | |
190 | "<OutputColumn name=\"Message\"/>\n" + | |
191 | "</Definition>\n" + | |
192 | "<Definition name=\"dmesg\">\n" + | |
193 | "<TimeStampOutputFormat>sssssss.ssssss</TimeStampOutputFormat>\n" + | |
194 | "<InputLine>\n" + | |
195 | "<Cardinality max=\"2147483647\" min=\"0\"/>\n" + | |
196 | "<RegEx>^[([0-9]*\\.[0.9]*)]\\s(.*)</RegEx>\n" + | |
197 | "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Time Stamp\"/>\n" + | |
198 | "<InputData action=\"0\" name=\"Message\"/>\n" + | |
199 | "</InputLine>\n" + | |
200 | "<OutputColumn name=\"Time Stamp\"/>\n" + | |
201 | "<OutputColumn name=\"Message\"/>\n" + | |
202 | "</Definition>\n" + | |
203 | "</CustomTxtTraceDefinitionList>"; | |
204 | fw.write(xmlContent); | |
205 | fw.flush(); | |
206 | } | |
fa24d78b | 207 | SWTBotUtils.createProject(PROJECT_NAME); |
0ae97cfb MK |
208 | SWTBotView proejctExplorerBot = fBot.viewByTitle("Project Explorer"); |
209 | proejctExplorerBot.show(); | |
210 | SWTBotTreeItem treeItem = proejctExplorerBot.bot().tree().getTreeItem(PROJECT_NAME); | |
211 | treeItem.select(); | |
212 | treeItem.expand(); | |
213 | SWTBotTreeItem treeNode = null; | |
214 | for (String node : treeItem.getNodes()) { | |
215 | if (node.startsWith("Trace")) { | |
216 | treeNode = treeItem.getNode(node); | |
217 | break; | |
218 | } | |
219 | ||
220 | } | |
221 | assertNotNull(treeNode); | |
222 | treeNode.contextMenu("Manage Custom Parsers...").click(); | |
4284e0e1 | 223 | fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE)); |
8af624a8 | 224 | fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus(); |
c22ca172 | 225 | fBot.list().select("Demo Category : Demo trace"); |
0ae97cfb | 226 | fBot.button("Edit...").click(); |
4284e0e1 | 227 | fBot.waitUntil(Conditions.shellIsActive(CUSTOM_TEXT_PARSER_SHELL_TITLE)); |
0ae97cfb | 228 | |
c22ca172 PT |
229 | fBot.textWithLabel("Category:").setText(CATEGORY_NAME); |
230 | fBot.textWithLabel("Trace type:").setText(TRACETYPE_NAME); | |
0ae97cfb MK |
231 | fBot.textWithLabel("Time Stamp format:").setText("ss"); |
232 | fBot.comboBox(1).setSelection("Time Stamp"); | |
233 | fBot.textWithLabel("format:").setText("ss"); | |
234 | fBot.button(2).click(); | |
235 | SWTBotTreeItem[] treeItems = fBot.tree().getAllItems(); | |
236 | SWTBotTreeItem eventLine[] = new SWTBotTreeItem[2]; | |
237 | for (SWTBotTreeItem item : treeItems) { | |
238 | if (item.getText().startsWith("Root Line 1")) { | |
239 | eventLine[0] = item; | |
240 | } | |
241 | if (item.getText().startsWith("Root Line 2")) { | |
242 | eventLine[1] = item; | |
243 | } | |
244 | } | |
245 | treeItems = fBot.tree().getAllItems(); | |
246 | assertNotNull(eventLine[0]); | |
247 | assertNotNull(eventLine[1]); | |
248 | fBot.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world"); | |
249 | eventLine[0].select(); | |
fa24d78b | 250 | SWTBotUtils.waitForJobs(); |
0ae97cfb MK |
251 | fBot.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)"); |
252 | eventLine[1].select(); | |
253 | fBot.textWithLabel("Regular expression:").setText("([^0-9]*)"); | |
254 | fBot.button(7).click(); | |
255 | fBot.comboBox("Set").setSelection("Append with |"); | |
256 | fBot.button("Highlight All").click(); | |
257 | fBot.button("Next >").click(); | |
258 | fBot.button("Finish").click(); | |
dcd374bb | 259 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION)); |
c22ca172 | 260 | String xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 261 | assertEquals(EXPECTED_TEST_DEFINITION, xmlPart); |
c22ca172 | 262 | fBot.list().select(CATEGORY_NAME + " : " + TRACETYPE_NAME); |
0ae97cfb MK |
263 | fBot.button("Delete").click(); |
264 | fBot.button("Yes").click(); | |
265 | fBot.button("Close").click(); | |
dcd374bb | 266 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, "")); |
c22ca172 | 267 | xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 268 | assertEquals("", xmlPart); |
93c91230 | 269 | |
fa24d78b | 270 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); |
0ae97cfb | 271 | } |
0ae97cfb | 272 | } |