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
.IOException
;
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
;
32 * Custom XML wizard tests
34 * This test will help validate the CustomXmlParserInputWizardPage
36 * @author Matthew Khouzam
38 @RunWith(SWTBotJunit4ClassRunner
.class)
39 public class TestCustomXmlWizard
extends AbstractCustomParserWizard
{
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\" format=\"\" name=\"Ignore\"/>\n" +
54 "<Attribute name=\"msg\">\n" +
55 "<InputData action=\"0\" name=\"msg\"/>\n" +
57 "<Attribute name=\"time\">\n" +
58 "<InputData action=\"0\" name=\"time\"/>\n" +
62 "<OutputColumn name=\"msg\"/>\n" +
63 "<OutputColumn name=\"time\"/>\n";
66 * Test to create a custom XML trace and compare the XML generated
69 * the xml file is not accessible, this is bad
70 * @throws FileNotFoundException
71 * the xml file wasn't written, this is bad
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
);
82 SWTBotTreeItem treeNode
= null;
83 for (String node
: treeItem
.getNodes()) {
84 if (node
.startsWith("Trace")) {
85 treeNode
= treeItem
.getNode(node
);
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");
101 fBot
.styledText().setText(XML_TRACE1
);
102 fBot
.buttonWithTooltip("Feeling lucky").click();
104 fBot
.tree().getTreeItem(TRACE
).getNode(EVENT
).select();
105 fBot
.checkBox("Log Entry").click();
106 fBot
.button("Next >").click();
107 fBot
.button("Finish").click();
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
);
120 SWTBotUtils
.deleteProject(PROJECT_NAME
, fBot
);