1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 Ericsson
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
10 * Matthew Khouzam - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.tmf
.ui
.swtbot
.tests
.parsers
.custom
;
15 import static org
.junit
.Assert
.assertEquals
;
16 import static org
.junit
.Assert
.assertNotNull
;
19 import java
.io
.FileNotFoundException
;
20 import java
.io
.FileWriter
;
21 import java
.io
.IOException
;
23 import org
.eclipse
.core
.resources
.ResourcesPlugin
;
24 import org
.eclipse
.swtbot
.eclipse
.finder
.widgets
.SWTBotView
;
25 import org
.eclipse
.swtbot
.swt
.finder
.junit
.SWTBotJunit4ClassRunner
;
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
;
32 * Custom text wizard tests
34 * Some reminders to help making tests (javadoc to keep formatting)
39 * 0 Time Stamp Format Help
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
57 * 1 event type (message, timestamp...)
58 * 2 how to handle the data (set, append...)
62 * @author Matthew Khouzam
64 @RunWith(SWTBotJunit4ClassRunner
.class)
65 public class TestCustomTxtWizard
extends AbstractCustomParserWizard
{
67 private static final String MANAGE_CUSTOM_PARSERS_SHELL_TITLE
= "Manage Custom Parsers";
68 private static final String PROJECT_NAME
= "TestText";
69 private static final String CATEGORY_NAME
= "Test Category";
70 private static final String TRACETYPE_NAME
= "Test Trace";
71 private static final String EXPECTED_TEST_DEFINITION
= "<Definition category=\"Test Category\" name=\"Test Trace\">\n" +
72 "<TimeStampOutputFormat>ss</TimeStampOutputFormat>\n" +
74 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
75 "<RegEx>\\s*(\\d\\d)\\s(.*\\S)</RegEx>\n" +
76 "<InputData action=\"0\" format=\"ss\" name=\"Time Stamp\"/>\n" +
77 "<InputData action=\"0\" name=\"Message\"/>\n" +
80 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
81 "<RegEx>([^0-9]*)</RegEx>\n" +
82 "<InputData action=\"2\" name=\"Message\"/>\n" +
84 "<OutputColumn name=\"Time Stamp\"/>\n" +
85 "<OutputColumn name=\"Message\"/>\n";
88 * Test to create a custom txt trace and compare the xml
91 * the xml file is not accessible, this is bad
92 * @throws FileNotFoundException
93 * the xml file wasn't written, this is bad
96 public void testNew() throws FileNotFoundException
, IOException
{
97 File xmlFile
= ResourcesPlugin
.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_txt_parsers.xml").toFile();
98 SWTBotUtils
.createProject(PROJECT_NAME
);
99 SWTBotView proejctExplorerBot
= fBot
.viewByTitle("Project Explorer");
100 proejctExplorerBot
.show();
101 SWTBotTreeItem treeItem
= proejctExplorerBot
.bot().tree().getTreeItem(PROJECT_NAME
);
104 SWTBotTreeItem treeNode
= null;
105 for (String node
: treeItem
.getNodes()) {
106 if (node
.startsWith("Trace")) {
107 treeNode
= treeItem
.getNode(node
);
112 assertNotNull(treeNode
);
113 treeNode
.contextMenu("Manage Custom Parsers...").click();
114 fBot
.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE
).setFocus();
116 fBot
.button("New...").click();
118 fBot
.textWithLabel("Category:").setText(CATEGORY_NAME
);
119 fBot
.textWithLabel("Trace type:").setText(TRACETYPE_NAME
);
120 fBot
.textWithLabel("Time Stamp format:").setText("ss");
121 fBot
.comboBox(1).setSelection("Time Stamp");
122 fBot
.textWithLabel("format:").setText("ss");
123 fBot
.button(8).click();
124 fBot
.button(2).click();
125 SWTBotTreeItem
[] treeItems
= fBot
.tree().getAllItems();
126 SWTBotTreeItem eventLine
[] = new SWTBotTreeItem
[2];
127 treeItems
= fBot
.tree().getAllItems();
128 for (SWTBotTreeItem item
: treeItems
) {
129 if (item
.getText().startsWith("Root Line 1")) {
132 if (item
.getText().startsWith("Root Line 2")) {
136 assertNotNull(eventLine
[0]);
137 assertNotNull(eventLine
[1]);
138 fBot
.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world");
139 eventLine
[0].select();
140 SWTBotUtils
.waitForJobs();
141 fBot
.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)");
142 eventLine
[1].select();
143 fBot
.textWithLabel("Regular expression:").setText("([^0-9]*)");
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 String xmlPart
= extractTestXml(xmlFile
, CATEGORY_NAME
, TRACETYPE_NAME
);
150 assertEquals(EXPECTED_TEST_DEFINITION
, xmlPart
);
151 fBot
.list().select(CATEGORY_NAME
+ " : " + TRACETYPE_NAME
);
152 fBot
.button("Delete").click();
153 fBot
.button("Yes").click();
154 fBot
.button("Close").click();
155 xmlPart
= extractTestXml(xmlFile
, CATEGORY_NAME
, TRACETYPE_NAME
);
156 assertEquals("", xmlPart
);
158 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);
162 * Test to edit a custom txt trace and compare the xml
164 * @throws IOException
165 * the xml file is not accessible, this is bad
166 * @throws FileNotFoundException
167 * the xml file wasn't written, this is bad
170 public void testEdit() throws FileNotFoundException
, IOException
{
171 File xmlFile
= ResourcesPlugin
.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_txt_parsers.xml").toFile();
172 try (FileWriter fw
= new FileWriter(xmlFile
)) {
173 String xmlContent
= "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n" +
174 "<CustomTxtTraceDefinitionList>\n" +
175 "<Definition category=\"Demo Category\" name=\"Demo trace\">\n" +
176 "<TimeStampOutputFormat>sss</TimeStampOutputFormat>\n" +
178 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
179 "<RegEx>\\s*(\\d*)\\s(.*)</RegEx>\n" +
180 "<InputData action=\"0\" format=\"sss\" name=\"Time Stamp\"/>\n" +
181 "<InputData action=\"0\" name=\"Message\"/>\n" +
183 "<OutputColumn name=\"Time Stamp\"/>\n" +
184 "<OutputColumn name=\"Message\"/>\n" +
186 "<Definition name=\"dmesg\">\n" +
187 "<TimeStampOutputFormat>sssssss.ssssss</TimeStampOutputFormat>\n" +
189 "<Cardinality max=\"2147483647\" min=\"0\"/>\n" +
190 "<RegEx>^[([0-9]*\\.[0.9]*)]\\s(.*)</RegEx>\n" +
191 "<InputData action=\"0\" format=\"sssss.sssss\" name=\"Time Stamp\"/>\n" +
192 "<InputData action=\"0\" name=\"Message\"/>\n" +
194 "<OutputColumn name=\"Time Stamp\"/>\n" +
195 "<OutputColumn name=\"Message\"/>\n" +
197 "</CustomTxtTraceDefinitionList>";
198 fw
.write(xmlContent
);
201 SWTBotUtils
.createProject(PROJECT_NAME
);
202 SWTBotView proejctExplorerBot
= fBot
.viewByTitle("Project Explorer");
203 proejctExplorerBot
.show();
204 SWTBotTreeItem treeItem
= proejctExplorerBot
.bot().tree().getTreeItem(PROJECT_NAME
);
207 SWTBotTreeItem treeNode
= null;
208 for (String node
: treeItem
.getNodes()) {
209 if (node
.startsWith("Trace")) {
210 treeNode
= treeItem
.getNode(node
);
215 assertNotNull(treeNode
);
216 treeNode
.contextMenu("Manage Custom Parsers...").click();
217 fBot
.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE
).setFocus();
218 fBot
.list().select("Demo Category : Demo trace");
219 fBot
.button("Edit...").click();
221 fBot
.textWithLabel("Category:").setText(CATEGORY_NAME
);
222 fBot
.textWithLabel("Trace type:").setText(TRACETYPE_NAME
);
223 fBot
.textWithLabel("Time Stamp format:").setText("ss");
224 fBot
.comboBox(1).setSelection("Time Stamp");
225 fBot
.textWithLabel("format:").setText("ss");
226 fBot
.button(2).click();
227 SWTBotTreeItem
[] treeItems
= fBot
.tree().getAllItems();
228 SWTBotTreeItem eventLine
[] = new SWTBotTreeItem
[2];
229 for (SWTBotTreeItem item
: treeItems
) {
230 if (item
.getText().startsWith("Root Line 1")) {
233 if (item
.getText().startsWith("Root Line 2")) {
237 treeItems
= fBot
.tree().getAllItems();
238 assertNotNull(eventLine
[0]);
239 assertNotNull(eventLine
[1]);
240 fBot
.styledText().setText("12 Hello\nWorld\n23 Goodbye\ncruel world");
241 eventLine
[0].select();
242 SWTBotUtils
.waitForJobs();
243 fBot
.textWithLabel("Regular expression:").setText("\\s*(\\d\\d)\\s(.*\\S)");
244 eventLine
[1].select();
245 fBot
.textWithLabel("Regular expression:").setText("([^0-9]*)");
246 fBot
.button(7).click();
247 fBot
.comboBox("Set").setSelection("Append with |");
248 fBot
.button("Highlight All").click();
249 fBot
.button("Next >").click();
250 fBot
.button("Finish").click();
251 String xmlPart
= extractTestXml(xmlFile
, CATEGORY_NAME
, TRACETYPE_NAME
);
252 assertEquals(EXPECTED_TEST_DEFINITION
, xmlPart
);
253 fBot
.list().select(CATEGORY_NAME
+ " : " + TRACETYPE_NAME
);
254 fBot
.button("Delete").click();
255 fBot
.button("Yes").click();
256 fBot
.button("Close").click();
257 xmlPart
= extractTestXml(xmlFile
, CATEGORY_NAME
, TRACETYPE_NAME
);
258 assertEquals("", xmlPart
);
260 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);