1 /*******************************************************************************
2 * Copyright (c) 2014 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
.linuxtools
.tmf
.ui
.swtbot
.tests
;
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
.widgets
.SWTBotTreeItem
;
26 import org
.junit
.Test
;
27 import org
.junit
.runner
.RunWith
;
30 * Custom XML wizard tests
32 * This test will help validate the CustomXmlParserInputWizardPage
34 * @author Matthew Khouzam
37 @RunWith(SWTBotJunit4ClassRunner
.class)
38 public class TestCustomXmlWizard
extends AbstractCustomParserWizard
{
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" +
55 "<Attribute name=\"time\">\n" +
56 "<InputData action=\"0\" name=\"time\"/>\n" +
60 "<OutputColumn name=\"msg\"/>\n" +
61 "<OutputColumn name=\"time\"/>\n";
64 * Test to create a custom XML trace and compare the XML generated
67 * the xml file is not accessible, this is bad
68 * @throws FileNotFoundException
69 * the xml file wasn't written, this is bad
72 public void testNew() throws FileNotFoundException
, IOException
{
73 File xmlFile
= ResourcesPlugin
.getWorkspace().getRoot().getLocation().append(".metadata/.plugins/org.eclipse.linuxtools.tmf.core/custom_xml_parsers.xml").toFile();
74 SWTBotUtil
.createProject(PROJECT_NAME
);
75 SWTBotView proejctExplorerBot
= fBot
.viewByTitle("Project Explorer");
76 proejctExplorerBot
.show();
77 SWTBotTreeItem treeItem
= proejctExplorerBot
.bot().tree().getTreeItem(PROJECT_NAME
);
80 SWTBotTreeItem treeNode
= null;
81 for (String node
: treeItem
.getNodes()) {
82 if (node
.startsWith("Trace")) {
83 treeNode
= treeItem
.getNode(node
);
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");
97 fBot
.styledText().setText(XML_TRACE1
);
98 fBot
.buttonWithTooltip("Feeling lucky").click();
100 fBot
.tree().getTreeItem(TRACE
).getNode(EVENT
).select();
101 fBot
.checkBox("Log Entry").click();
102 fBot
.button("Next >").click();
103 fBot
.button("Finish").click();
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
);
114 SWTBotUtil
.deleteProject(PROJECT_NAME
, fBot
);