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; |
0ae97cfb | 28 | import org.junit.Test; |
cbbd323f | 29 | import org.junit.runner.RunWith; |
0ae97cfb MK |
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 | |
0ae97cfb | 63 | */ |
cbbd323f | 64 | @RunWith(SWTBotJunit4ClassRunner.class) |
41a0d150 | 65 | public class TestCustomTxtWizard extends AbstractCustomParserWizard { |
0ae97cfb | 66 | |
d3d0f69a | 67 | private static final String MANAGE_CUSTOM_PARSERS_SHELL_TITLE = "Manage Custom Parsers"; |
4284e0e1 | 68 | private static final String CUSTOM_TEXT_PARSER_SHELL_TITLE = "Custom Text Parser"; |
41a0d150 | 69 | private static final String PROJECT_NAME = "TestText"; |
c22ca172 PT |
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" + | |
0ae97cfb MK |
73 | "<TimeStampOutputFormat>ss</TimeStampOutputFormat>\n" + |
74 | "<InputLine>\n" + | |
75 | "<Cardinality max=\"2147483647\" min=\"0\"/>\n" + | |
76 | "<RegEx>\\s*(\\d\\d)\\s(.*\\S)</RegEx>\n" + | |
f5cc6ed1 PT |
77 | "<InputData action=\"0\" format=\"ss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" + |
78 | "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" + | |
0ae97cfb MK |
79 | "</InputLine>\n" + |
80 | "<InputLine>\n" + | |
81 | "<Cardinality max=\"2147483647\" min=\"0\"/>\n" + | |
82 | "<RegEx>([^0-9]*)</RegEx>\n" + | |
f5cc6ed1 | 83 | "<InputData action=\"2\" name=\"Message\" tag=\"MESSAGE\"/>\n" + |
0ae97cfb | 84 | "</InputLine>\n" + |
f5cc6ed1 PT |
85 | "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" + |
86 | "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n"; | |
0ae97cfb | 87 | |
0ae97cfb MK |
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 { | |
c77a695a | 98 | File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_txt_parsers.xml").toFile(); |
53f17e49 | 99 | // Open the custom parsers dialog |
fa24d78b | 100 | SWTBotUtils.createProject(PROJECT_NAME); |
0ae97cfb | 101 | |
9bfd623f | 102 | SWTBotTreeItem treeNode = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME); |
0ae97cfb | 103 | treeNode.contextMenu("Manage Custom Parsers...").click(); |
4284e0e1 | 104 | fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE)); |
8af624a8 | 105 | fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus(); |
fca952c3 | 106 | |
53f17e49 | 107 | // Open the new custom txt parser dialog |
0ae97cfb | 108 | fBot.button("New...").click(); |
4284e0e1 | 109 | fBot.waitUntil(Conditions.shellIsActive(CUSTOM_TEXT_PARSER_SHELL_TITLE)); |
0ae97cfb | 110 | |
53f17e49 | 111 | // Setting header |
c22ca172 PT |
112 | fBot.textWithLabel("Category:").setText(CATEGORY_NAME); |
113 | fBot.textWithLabel("Trace type:").setText(TRACETYPE_NAME); | |
0ae97cfb | 114 | fBot.textWithLabel("Time Stamp format:").setText("ss"); |
53f17e49 GB |
115 | |
116 | // Fill Group 1 as time stamp | |
f5cc6ed1 | 117 | fBot.comboBox(1).setSelection("Timestamp"); |
0ae97cfb | 118 | fBot.textWithLabel("format:").setText("ss"); |
53f17e49 | 119 | // Click on the New group button |
0ae97cfb | 120 | fBot.button(8).click(); |
53f17e49 | 121 | // Add next line |
0ae97cfb MK |
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]); | |
53f17e49 | 136 | // Set the regular expression for each event line |
0ae97cfb MK |
137 | fBot.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world"); |
138 | eventLine[0].select(); | |
fa24d78b | 139 | SWTBotUtils.waitForJobs(); |
0ae97cfb MK |
140 | fBot.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)"); |
141 | eventLine[1].select(); | |
142 | fBot.textWithLabel("Regular expression:").setText("([^0-9]*)"); | |
53f17e49 | 143 | // Click on the new group of root line 2 |
0ae97cfb MK |
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(); | |
dcd374bb | 149 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION)); |
c22ca172 | 150 | String xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 151 | assertEquals(EXPECTED_TEST_DEFINITION, xmlPart); |
c22ca172 | 152 | fBot.list().select(CATEGORY_NAME + " : " + TRACETYPE_NAME); |
0ae97cfb MK |
153 | fBot.button("Delete").click(); |
154 | fBot.button("Yes").click(); | |
155 | fBot.button("Close").click(); | |
dcd374bb | 156 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, "")); |
c22ca172 | 157 | xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 158 | assertEquals("", xmlPart); |
93c91230 | 159 | |
fa24d78b | 160 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); |
0ae97cfb MK |
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 { | |
c77a695a | 173 | File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_txt_parsers.xml").toFile(); |
0ae97cfb MK |
174 | try (FileWriter fw = new FileWriter(xmlFile)) { |
175 | String xmlContent = "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" + | |
176 | "<CustomTxtTraceDefinitionList>\n" + | |
c22ca172 | 177 | "<Definition category=\"Demo Category\" name=\"Demo trace\">\n" + |
0ae97cfb MK |
178 | "<TimeStampOutputFormat>sss</TimeStampOutputFormat>\n" + |
179 | "<InputLine>\n" + | |
180 | "<Cardinality max=\"2147483647\" min=\"0\"/>\n" + | |
181 | "<RegEx>\\s*(\\d*)\\s(.*)</RegEx>\n" + | |
f5cc6ed1 PT |
182 | "<InputData action=\"0\" format=\"sss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" + |
183 | "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" + | |
0ae97cfb | 184 | "</InputLine>\n" + |
f5cc6ed1 PT |
185 | "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" + |
186 | "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" + | |
0ae97cfb MK |
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" + | |
f5cc6ed1 PT |
193 | "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" + |
194 | "<InputData action=\"0\" name=\"Message\" tag=\"MESSAGE\"/>\n" + | |
0ae97cfb | 195 | "</InputLine>\n" + |
f5cc6ed1 PT |
196 | "<OutputColumn name=\"Timestamp\" tag=\"TIMESTAMP\"/>\n" + |
197 | "<OutputColumn name=\"Message\" tag=\"MESSAGE\"/>\n" + | |
0ae97cfb MK |
198 | "</Definition>\n" + |
199 | "</CustomTxtTraceDefinitionList>"; | |
200 | fw.write(xmlContent); | |
201 | fw.flush(); | |
202 | } | |
53f17e49 | 203 | // Open the custom parsers dialog |
fa24d78b | 204 | SWTBotUtils.createProject(PROJECT_NAME); |
9bfd623f | 205 | SWTBotTreeItem treeNode = SWTBotUtils.selectTracesFolder(fBot, PROJECT_NAME); |
0ae97cfb | 206 | treeNode.contextMenu("Manage Custom Parsers...").click(); |
4284e0e1 | 207 | fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE)); |
53f17e49 | 208 | // Open the edition dialog for txt parser |
8af624a8 | 209 | fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus(); |
c22ca172 | 210 | fBot.list().select("Demo Category : Demo trace"); |
0ae97cfb | 211 | fBot.button("Edit...").click(); |
4284e0e1 | 212 | fBot.waitUntil(Conditions.shellIsActive(CUSTOM_TEXT_PARSER_SHELL_TITLE)); |
0ae97cfb | 213 | |
53f17e49 | 214 | // update parser's data |
c22ca172 PT |
215 | fBot.textWithLabel("Category:").setText(CATEGORY_NAME); |
216 | fBot.textWithLabel("Trace type:").setText(TRACETYPE_NAME); | |
0ae97cfb | 217 | fBot.textWithLabel("Time Stamp format:").setText("ss"); |
53f17e49 GB |
218 | |
219 | // update time stamp format | |
f5cc6ed1 | 220 | fBot.comboBox(1).setSelection("Timestamp"); |
0ae97cfb MK |
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(); | |
fa24d78b | 238 | SWTBotUtils.waitForJobs(); |
0ae97cfb MK |
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(); | |
dcd374bb | 247 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION)); |
c22ca172 | 248 | String xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 249 | assertEquals(EXPECTED_TEST_DEFINITION, xmlPart); |
c22ca172 | 250 | fBot.list().select(CATEGORY_NAME + " : " + TRACETYPE_NAME); |
0ae97cfb MK |
251 | fBot.button("Delete").click(); |
252 | fBot.button("Yes").click(); | |
253 | fBot.button("Close").click(); | |
dcd374bb | 254 | fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, "")); |
c22ca172 | 255 | xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME); |
0ae97cfb | 256 | assertEquals("", xmlPart); |
93c91230 | 257 | |
fa24d78b | 258 | SWTBotUtils.deleteProject(PROJECT_NAME, fBot); |
0ae97cfb | 259 | } |
0ae97cfb | 260 | } |