* Returns a String representation of this XML suite.
*
* @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);
for (String paramName : m_parameters.keySet()) {
Properties paramProps = new Properties();
paramProps.setProperty("name", paramName);
paramProps.setProperty("value", m_parameters.get(paramName));
xsb.addEmptyElement("parameter", paramProps);
}
if (null != m_listeners && !m_listeners.isEmpty()) {
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 (null != getXmlPackages() && !getXmlPackages().isEmpty()) {
xsb.push("packages");
for (XmlPackage pack : getXmlPackages()) {
xsb.getStringBuffer().append(pack.toXml(" "));
}
xsb.pop("packages");
}
if (null != getMethodSelectors() && !getMethodSelectors().isEmpty()) {
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");
}
for (XmlTest test : getTests()) {
xsb.getStringBuffer().append(test.toXml(" "));
}
xsb.pop("suite");
return xsb.toXML();
}