import test results: unescape xml entities

This commit is contained in:
Anna Kozlova
2015-07-16 18:28:42 +03:00
parent 9c4325140f
commit 7a345971ca
2 changed files with 26 additions and 5 deletions
@@ -43,17 +43,19 @@ public class ImportedTestContentHandler extends DefaultHandler {
@Override
public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException {
if (TestResultsXmlFormatter.ELEM_SUITE.equals(qName)) {
final String suiteName = attributes.getValue(TestResultsXmlFormatter.ATTR_NAME);
myProcessor.onSuiteStarted(new TestSuiteStartedEvent(suiteName, attributes.getValue(TestResultsXmlFormatter.ATTR_LOCATION)));
final String suiteName = StringUtil.unescapeXml(attributes.getValue(TestResultsXmlFormatter.ATTR_NAME));
myProcessor.onSuiteStarted(new TestSuiteStartedEvent(suiteName,
StringUtil.unescapeXml(attributes.getValue(TestResultsXmlFormatter.ATTR_LOCATION))));
mySuites.push(suiteName);
}
else if (TestResultsXmlFormatter.ELEM_TEST.equals(qName)) {
final String name = attributes.getValue(TestResultsXmlFormatter.ATTR_NAME);
final String name = StringUtil.unescapeXml(attributes.getValue(TestResultsXmlFormatter.ATTR_NAME));
myCurrentTest = name;
myDuration = attributes.getValue(TestResultsXmlFormatter.ATTR_DURATION);
myStatus = attributes.getValue(TestResultsXmlFormatter.ATTR_STATUS);
final String isConfig = attributes.getValue(TestResultsXmlFormatter.ATTR_CONFIG);
final TestStartedEvent startedEvent = new TestStartedEvent(name, attributes.getValue(TestResultsXmlFormatter.ATTR_LOCATION));
final TestStartedEvent startedEvent = new TestStartedEvent(name,
StringUtil.unescapeXml(attributes.getValue(TestResultsXmlFormatter.ATTR_LOCATION)));
if (isConfig != null && Boolean.valueOf(isConfig)) {
startedEvent.setConfig(true);
}
@@ -76,7 +78,7 @@ public class ImportedTestContentHandler extends DefaultHandler {
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
final String currentText = currentValue.toString();
final String currentText = StringUtil.unescapeXml(currentValue.toString());
final boolean isTestOutput = myCurrentTest == null || TestResultsXmlFormatter.STATUS_PASSED.equals(myStatus) || !myErrorOutput;
if (isTestOutput) {
currentValue.setLength(0);
@@ -447,4 +447,23 @@ public class GeneralToSMTRunnerEventsConvertorTest extends BaseSMTRunnerTestCase
assertEquals(1, tests.size());
assertEquals("ATest", tests.get(0).getName());
}
public void testEscapedImportTest() throws Exception {
myEventsProcessor.onStartTesting();
ImportedToGeneralTestEventsConverter.parseTestResults(new StringReader("<?xml version=\"1.0\" encoding=\"UTF-8\"?>" +
"<testrun duration=\"592\" footerText=\"Generated by IntelliJ IDEA\" name=\"suite1\">\n" +
" <suite name=\"sui&amp;te1\" status=\"failed\">\n" +
" <test name=\"ATe&amp;st\" status=\"failed\"/>\n" +
" </suite>\n" +
"</testrun>\n"), myEventsProcessor);
myEventsProcessor.onFinishTesting();
final List<? extends SMTestProxy> children = myResultsViewer.getTestsRootNode().getChildren();
assertEquals(1, children.size());
final SMTestProxy suite = children.get(0);
assertEquals("sui&te1", suite.getName());
final List<? extends SMTestProxy> tests = suite.getChildren();
assertEquals(1, tests.size());
assertEquals("ATe&st", tests.get(0).getName());
}
}