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