tmf: Bug 497038: Custom parser field names conflict with built-in tags
[deliverable/tracecompass.git] / tmf / org.eclipse.tracecompass.tmf.ui.swtbot.tests / src / org / eclipse / tracecompass / tmf / ui / swtbot / tests / parsers / custom / TestCustomXmlWizard.java
1 /*******************************************************************************
2 * Copyright (c) 2014, 2015 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.IOException;
21
22 import org.eclipse.core.resources.ResourcesPlugin;
23 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
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 XML wizard tests
33 *
34 * This test will help validate the CustomXmlParserInputWizardPage
35 *
36 * @author Matthew Khouzam
37 */
38 @RunWith(SWTBotJunit4ClassRunner.class)
39 public class TestCustomXmlWizard extends AbstractCustomParserWizard {
40
41 private static final String EVENT = "event";
42 private static final String TRACE = "trace";
43 private static final String XML_TRACE1 = "<trace>\n\t<event time=\"100\" msg=\"hello\"/>\n\t<event time=\"200\" msg=\"world\"/></trace>";
44 private static final String MANAGE_CUSTOM_PARSERS_SHELL_TITLE = "Manage Custom Parsers";
45 private static final String CUSTOM_XML_PARSER_SHELL_TITLE = "Custom XML Parser";
46 private static final String PROJECT_NAME = "TestXML";
47 private static final String CATEGORY_NAME = "Test Category";
48 private static final String TRACETYPE_NAME = "Test Trace";
49 private static final String EXPECTED_TEST_DEFINITION = "<Definition category=\"Test Category\" name=\"" + TRACETYPE_NAME + "\">\n" +
50 "<TimeStampOutputFormat>ss</TimeStampOutputFormat>\n" +
51 "<InputElement name=\"trace\">\n" +
52 "<InputElement logentry=\"true\" name=\"event\">\n" +
53 "<InputData action=\"0\" name=\"Ignore\" tag=\"IGNORE\"/>\n" +
54 "<Attribute name=\"msg\">\n" +
55 "<InputData action=\"0\" name=\"msg\" tag=\"OTHER\"/>\n" +
56 "</Attribute>\n" +
57 "<Attribute name=\"time\">\n" +
58 "<InputData action=\"0\" name=\"time\" tag=\"OTHER\"/>\n" +
59 "</Attribute>\n" +
60 "</InputElement>\n" +
61 "</InputElement>\n" +
62 "<OutputColumn name=\"msg\" tag=\"OTHER\"/>\n" +
63 "<OutputColumn name=\"time\" tag=\"OTHER\"/>\n";
64
65 /**
66 * Test to create a custom XML trace and compare the XML generated
67 *
68 * @throws IOException
69 * the xml file is not accessible, this is bad
70 * @throws FileNotFoundException
71 * the xml file wasn't written, this is bad
72 */
73 @Test
74 public void testNew() throws FileNotFoundException, IOException {
75 File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_xml_parsers.xml").toFile();
76 SWTBotUtils.createProject(PROJECT_NAME);
77 SWTBotView proejctExplorerBot = fBot.viewByTitle("Project Explorer");
78 proejctExplorerBot.show();
79 SWTBotTreeItem treeItem = proejctExplorerBot.bot().tree().getTreeItem(PROJECT_NAME);
80 treeItem.select();
81 treeItem.expand();
82 SWTBotTreeItem treeNode = null;
83 for (String node : treeItem.getNodes()) {
84 if (node.startsWith("Trace")) {
85 treeNode = treeItem.getNode(node);
86 break;
87 }
88
89 }
90 assertNotNull(treeNode);
91 treeNode.contextMenu("Manage Custom Parsers...").click();
92 fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE));
93 fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus();
94 fBot.radio("XML").click();
95 fBot.button("New...").click();
96 fBot.waitUntil(Conditions.shellIsActive(CUSTOM_XML_PARSER_SHELL_TITLE));
97 fBot.textWithLabel("Category:").setText(CATEGORY_NAME);
98 fBot.textWithLabel("Trace type:").setText(TRACETYPE_NAME);
99 fBot.textWithLabel("Time Stamp format:").setText("ss");
100
101 fBot.styledText().setText(XML_TRACE1);
102 fBot.buttonWithTooltip("Feeling lucky").click();
103
104 fBot.tree().getTreeItem(TRACE).getNode(EVENT).select();
105 fBot.checkBox("Log Entry").click();
106 fBot.button("Next >").click();
107 fBot.button("Finish").click();
108
109 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION));
110 String xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME);
111 assertEquals(EXPECTED_TEST_DEFINITION, xmlPart);
112 fBot.list().select(CATEGORY_NAME + " : " + TRACETYPE_NAME);
113 fBot.button("Delete").click();
114 fBot.button("Yes").click();
115 fBot.button("Close").click();
116 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, ""));
117 xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME);
118 assertEquals("", xmlPart);
119
120 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
121 }
122
123 }
This page took 0.046482 seconds and 5 git commands to generate.