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
CommitLineData
41a0d150 1/*******************************************************************************
ed902a2b 2 * Copyright (c) 2014, 2015 Ericsson
41a0d150
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 13package org.eclipse.tracecompass.tmf.ui.swtbot.tests.parsers.custom;
41a0d150
MK
14
15import static org.junit.Assert.assertEquals;
16import static org.junit.Assert.assertNotNull;
17
18import java.io.File;
19import java.io.FileNotFoundException;
20import java.io.IOException;
21
22import org.eclipse.core.resources.ResourcesPlugin;
23import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
24import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
4284e0e1 25import org.eclipse.swtbot.swt.finder.waits.Conditions;
41a0d150 26import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
fa24d78b 27import org.eclipse.tracecompass.tmf.ui.swtbot.tests.shared.SWTBotUtils;
41a0d150
MK
28import org.junit.Test;
29import 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
41a0d150
MK
37 */
38@RunWith(SWTBotJunit4ClassRunner.class)
39public 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";
4284e0e1 45 private static final String CUSTOM_XML_PARSER_SHELL_TITLE = "Custom XML Parser";
41a0d150
MK
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" +
f5cc6ed1 53 "<InputData action=\"0\" name=\"Ignore\" tag=\"IGNORE\"/>\n" +
41a0d150 54 "<Attribute name=\"msg\">\n" +
f5cc6ed1 55 "<InputData action=\"0\" name=\"msg\" tag=\"OTHER\"/>\n" +
41a0d150
MK
56 "</Attribute>\n" +
57 "<Attribute name=\"time\">\n" +
f5cc6ed1 58 "<InputData action=\"0\" name=\"time\" tag=\"OTHER\"/>\n" +
41a0d150
MK
59 "</Attribute>\n" +
60 "</InputElement>\n" +
61 "</InputElement>\n" +
f5cc6ed1
PT
62 "<OutputColumn name=\"msg\" tag=\"OTHER\"/>\n" +
63 "<OutputColumn name=\"time\" tag=\"OTHER\"/>\n";
41a0d150
MK
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 {
c77a695a 75 File xmlFile = ResourcesPlugin.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.tracecompass.tmf.core/custom_xml_parsers.xml").toFile();
fa24d78b 76 SWTBotUtils.createProject(PROJECT_NAME);
41a0d150
MK
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();
4284e0e1 92 fBot.waitUntil(Conditions.shellIsActive(MANAGE_CUSTOM_PARSERS_SHELL_TITLE));
41a0d150
MK
93 fBot.shell(MANAGE_CUSTOM_PARSERS_SHELL_TITLE).setFocus();
94 fBot.radio("XML").click();
95 fBot.button("New...").click();
4284e0e1 96 fBot.waitUntil(Conditions.shellIsActive(CUSTOM_XML_PARSER_SHELL_TITLE));
41a0d150
MK
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
dcd374bb 109 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, EXPECTED_TEST_DEFINITION));
41a0d150
MK
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();
dcd374bb 116 fBot.waitUntil(new CustomDefinitionHasContent(xmlFile, CATEGORY_NAME, TRACETYPE_NAME, ""));
41a0d150
MK
117 xmlPart = extractTestXml(xmlFile, CATEGORY_NAME, TRACETYPE_NAME);
118 assertEquals("", xmlPart);
119
fa24d78b 120 SWTBotUtils.deleteProject(PROJECT_NAME, fBot);
41a0d150
MK
121 }
122
123}
This page took 0.071343 seconds and 5 git commands to generate.