1package org.testng.xml;2import static org.testng.reporters.XMLReporterConfig.ATTR_DESC;3import static org.testng.reporters.XMLReporterConfig.ATTR_DURATION_MS;4import static org.testng.reporters.XMLReporterConfig.ATTR_NAME;5import static org.testng.reporters.XMLReporterConfig.ATTR_STATUS;6import static org.testng.reporters.XMLReporterConfig.TAG_CLASS;7import static org.testng.reporters.XMLReporterConfig.TAG_PARAMS;8import static org.testng.reporters.XMLReporterConfig.TAG_SUITE;9import static org.testng.reporters.XMLReporterConfig.TAG_TEST;10import static org.testng.reporters.XMLReporterConfig.TAG_TEST_METHOD;11import org.testng.ITestResult;12import org.testng.collections.Lists;13import org.testng.remote.strprotocol.GenericMessage;14import org.testng.remote.strprotocol.IRemoteSuiteListener;15import org.testng.remote.strprotocol.IRemoteTestListener;16import org.testng.remote.strprotocol.MessageHelper;17import org.testng.remote.strprotocol.SuiteMessage;18import org.testng.remote.strprotocol.TestMessage;19import org.testng.remote.strprotocol.TestResultMessage;20import org.testng.reporters.XMLReporterConfig;21import org.xml.sax.Attributes;22import org.xml.sax.helpers.DefaultHandler;23import java.util.List;24/**25 * Parses testng-result.xml, create TestResultMessages and send them back to the listener26 * as we encounter them.27 *28 * @author Cedric Beust <cedric@beust.com>29 */30public class ResultContentHandler extends DefaultHandler {31 private int m_suiteMethodCount = 0;32 private int m_testMethodCount = 0;33 private SuiteMessage m_currentSuite;34 private TestMessage m_currentTest;35 private String m_className;36 private int m_passed;37 private int m_failed;38 private int m_skipped;39 private int m_invocationCount;40 private int m_currentInvocationCount;41 private TestResultMessage m_currentTestResult;42 private IRemoteSuiteListener m_suiteListener;43 private IRemoteTestListener m_testListener;44 private List<String> m_params = null;45 public ResultContentHandler(IRemoteSuiteListener suiteListener,46 IRemoteTestListener testListener, boolean resolveClasses /* ignored */) {47 m_suiteListener = suiteListener;48 m_testListener = testListener;49 }50 @Override51 public void startElement (String uri, String localName,52 String qName, Attributes attributes) {53 p("Start " + qName);54 if (TAG_SUITE.equals(qName)) {55 m_suiteListener.onInitialization(new GenericMessage(MessageHelper.GENERIC_SUITE_COUNT));56 m_suiteMethodCount = 0;57 m_currentSuite = new SuiteMessage(attributes.getValue(ATTR_NAME),58 true /* start */, m_suiteMethodCount);59 m_suiteListener.onStart(m_currentSuite);60 } else if (TAG_TEST.equals(qName)) {61 m_passed = m_failed = m_skipped = 0;62 m_currentTest = new TestMessage(true /* start */, m_currentSuite.getSuiteName(),63 attributes.getValue(ATTR_NAME), m_testMethodCount,64 m_passed, m_failed, m_skipped, 0);65 m_testListener.onStart(m_currentTest);66 } else if (TAG_CLASS.equals(qName)) {67 m_className = attributes.getValue(ATTR_NAME);68 } else if (TAG_TEST_METHOD.equals(qName)) {69 Integer status = XMLReporterConfig.getStatus(attributes.getValue(ATTR_STATUS));70 m_currentTestResult = new TestResultMessage(status, m_currentSuite.getSuiteName(),71 m_currentTest.getTestName(), m_className, attributes.getValue(ATTR_NAME),72 attributes.getValue(ATTR_DESC),73 attributes.getValue(ATTR_DESC),74 new String[0], /* no parameters, filled later */75 0, Long.parseLong(attributes.getValue(ATTR_DURATION_MS)),76 "" /* stack trace, filled later */,77 m_invocationCount, m_currentInvocationCount);78 m_suiteMethodCount++;79 m_testMethodCount++;80 if (status == ITestResult.SUCCESS) m_passed++;81 else if (status == ITestResult.FAILURE) m_failed++;82 else if (status == ITestResult.SKIP) m_skipped++;83 } else if (TAG_PARAMS.equals(qName)) {...