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