/**
* @return A String representation of this XML suite.
*/
public String toXml() {
XMLStringBuffer xsb = new XMLStringBuffer();
xsb.setDocType("suite SYSTEM \"" + Parser.TESTNG_DTD_URL + '\"');
Properties p = new Properties();
p.setProperty("name", getName());
if (getVerbose() != null) {
XmlUtils.setProperty(p, "verbose", getVerbose().toString(), DEFAULT_VERBOSE.toString());
}
final String parallel= getParallel();
if(isStringNotEmpty(parallel) && !DEFAULT_PARALLEL.equals(parallel)) {
p.setProperty("parallel", parallel);
}
XmlUtils.setProperty(p, "configfailurepolicy", getConfigFailurePolicy(),
DEFAULT_CONFIG_FAILURE_POLICY);
XmlUtils.setProperty(p, "thread-count", String.valueOf(getThreadCount()),
DEFAULT_THREAD_COUNT.toString());
XmlUtils.setProperty(p, "data-provider-thread-count", String.valueOf(getDataProviderThreadCount()),
DEFAULT_DATA_PROVIDER_THREAD_COUNT.toString());
if (! DEFAULT_JUNIT.equals(m_isJUnit)) {
p.setProperty("junit", m_isJUnit != null ? m_isJUnit.toString() : "false"); // TESTNG-141
}
XmlUtils.setProperty(p, "skipfailedinvocationcounts", m_skipFailedInvocationCounts.toString(),
DEFAULT_SKIP_FAILED_INVOCATION_COUNTS.toString());
if(null != m_objectFactory) {
p.setProperty("object-factory", m_objectFactory.getClass().getName());
}
XmlUtils.setProperty(p, "allow-return-values", String.valueOf(getAllowReturnValues()),
DEFAULT_ALLOW_RETURN_VALUES.toString());
xsb.push("suite", p);
XmlUtils.dumpParameters(xsb, m_parameters);
if (hasElements(m_listeners)) {
xsb.push("listeners");
for (String listenerName: m_listeners) {
Properties listenerProps = new Properties();
listenerProps.setProperty("class-name", listenerName);
xsb.addEmptyElement("listener", listenerProps);
}
xsb.pop("listeners");
}
if (hasElements(getXmlPackages())) {
xsb.push("packages");
for (XmlPackage pack : getXmlPackages()) {
xsb.getStringBuffer().append(pack.toXml(" "));
}
xsb.pop("packages");
}
if (getXmlMethodSelectors() != null) {
xsb.getStringBuffer().append(getXmlMethodSelectors().toXml(" "));
} else {
// deprecated
if (hasElements(getMethodSelectors())) {
xsb.push("method-selectors");
for (XmlMethodSelector selector : getMethodSelectors()) {
xsb.getStringBuffer().append(selector.toXml(" "));
}
xsb.pop("method-selectors");
}
}
List<String> suiteFiles = getSuiteFiles();
if (suiteFiles.size() > 0) {
xsb.push("suite-files");
for (String sf : suiteFiles) {
Properties prop = new Properties();
prop.setProperty("path", sf);
xsb.addEmptyElement("suite-file", prop);
}
xsb.pop("suite-files");
}
List<String> included = getIncludedGroups();
List<String> excluded = getExcludedGroups();
if (hasElements(included) || hasElements(excluded)) {
xsb.push("groups");
xsb.push("run");
for (String g : included) {
xsb.addEmptyElement("include", "name", g);
}
for (String g : excluded) {
xsb.addEmptyElement("exclude", "name", g);
}
xsb.pop("run");
xsb.pop("groups");
}
if (m_xmlGroups != null) {
xsb.getStringBuffer().append(m_xmlGroups.toXml(" "));
}
for (XmlTest test : getTests()) {
xsb.getStringBuffer().append(test.toXml(" "));
}
xsb.pop("suite");
return xsb.toXML();
}