public String toXml(String indent) { XMLStringBuffer xsb = new XMLStringBuffer(indent); boolean hasElements = hasElements(m_includes); if (hasElements) { xsb.push("define", "name", m_name); } for (String s : m_includes) { xsb.addEmptyElement("include", "name", s); } if (hasElements) { xsb.pop("define"); } return xsb.toXML(); }
private void addParameter(XMLStringBuffer xmlBuffer, Object parameter, int i) { Properties attrs = new Properties(); attrs.setProperty(XMLReporterConfig.ATTR_INDEX, String.valueOf(i)); xmlBuffer.push(XMLReporterConfig.TAG_PARAM, attrs); if (parameter == null) { Properties valueAttrs = new Properties(); valueAttrs.setProperty(XMLReporterConfig.ATTR_IS_NULL, "true"); xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_PARAM_VALUE, valueAttrs); } else { xmlBuffer.push(XMLReporterConfig.TAG_PARAM_VALUE); xmlBuffer.addCDATA(parameter.toString()); xmlBuffer.pop(); } xmlBuffer.pop(); }
private void generateClassPanel(Class c, List<ITestResult> results, XMLStringBuffer xsb, String status, ISuite suite) { xsb.push(D, C, "suite-" + suiteToTag(suite) + "-class-" + status); xsb.push(D, C, "main-panel-header rounded-window-top"); // Passed/failed icon xsb.addEmptyElement("img", "src", Model.getImage(status)); xsb.addOptional(S, c.getName(), C, "class-name"); xsb.pop(D); xsb.push(D, C, "main-panel-content rounded-window-bottom"); for (ITestResult tr : results) { generateMethod(tr, xsb); } xsb.pop(D); xsb.pop(D); }
/** Put a XML start or empty tag to the XMLStringBuffer depending on hasChildElements parameter */ private boolean putElement(XMLStringBuffer xsb, String tagName, Properties attributes, boolean hasChildElements) { if (hasChildElements) { xsb.push(tagName, attributes); } else { xsb.addEmptyElement(tagName, attributes); } return hasChildElements; }
public void push(String tagName, String... attributes) { push(tagName, createProperties(attributes)); }
public void addEmptyElement(String tagName, String... attributes) { addEmptyElement(tagName, createProperties(attributes)); }
@Override public String getContent(ISuite suite, XMLStringBuffer main) { XMLStringBuffer xsb = new XMLStringBuffer(main.getCurrentIndent()); xsb.push("pre"); xsb.addString(Utils.escapeHtml(suite.getXmlSuite().toXml())); xsb.pop("pre"); return xsb.toXML(); }
private void writeReporterOutput(XMLStringBuffer xmlBuffer) { // TODO: Cosmin - maybe a <line> element isn't indicated for each line xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT); List<String> output = Reporter.getOutput(); for (String line : output) { if (line != null) { xmlBuffer.push(XMLReporterConfig.TAG_LINE); xmlBuffer.addCDATA(line); xmlBuffer.pop(); } } xmlBuffer.pop(); }
private void generateResult(XMLStringBuffer header, int failed, int skipped, int passed, ISuite suite, String suiteName) { // // Results // header.push(D, C, "result-section"); header.push(D, C, "suite-section-title"); header.addRequired(S, "Results"); header.pop(D); // Method stats int total = failed + skipped + passed; String stats = String.format("%s, %s %s %s", pluralize(total, "method"), maybe(failed, "failed", ", "), maybe(skipped, "skipped", ", "), maybe(passed, "passed", "")); header.push(D, C, "suite-section-content"); header.push("ul"); header.push("li"); header.addOptional(S, stats, C, "method-stats"); header.pop("li"); generateMethodList("Failed methods", new ResultsByStatus(suite, "failed", ITestResult.FAILURE), suiteName, header); generateMethodList("Skipped methods", new ResultsByStatus(suite, "skipped", ITestResult.SKIP), suiteName, header); generateMethodList("Passed methods", new ResultsByStatus(suite, "passed", ITestResult.SUCCESS), suiteName, header); }
@Override public void generate(XMLStringBuffer xsb) { xsb.push(D, C, "top-banner-root"); xsb.addRequired(S, "Test results", C, "top-banner-title-font"); xsb.addEmptyElement("br"); int failedCount = getModel().getAllFailedResults().size(); String testResult = failedCount > 0 ? ", " + pluralize(failedCount, "failed test") : ""; String subTitle = pluralize(getModel().getSuites().size(), "suite") + testResult; xsb.addRequired(S, subTitle, C, "top-banner-font-1"); xsb.pop(D); }
private void addLinkTo(XMLStringBuffer header, INavigatorPanel panel, ISuite suite) { String text = panel.getNavigatorLink(suite); header.push("li"); header.push("a", "href", "#", "panel-name", panel.getPanelName(suite), C, "navigator-link "); String className = panel.getClassName(); if (className != null) { header.addOptional(S, text, C, className); } else { header.addOptional(S, text); } header.pop("a"); header.pop("li"); }
private synchronized void createElementFromIgnoredTests(XMLStringBuffer doc, ITestContext context) { Collection<ITestNGMethod> methods = context.getExcludedMethods(); for (ITestNGMethod method : methods) { Properties properties = getPropertiesFor(method, 0); doc.push(XMLConstants.TESTCASE,properties); doc.addEmptyElement(XMLConstants.ATTR_IGNORED); doc.pop(); } }
public void addTestMethodParams(XMLStringBuffer xmlBuffer, ITestResult testResult) { Object[] parameters = testResult.getParameters(); if ((parameters != null) && (parameters.length > 0)) { xmlBuffer.push(XMLReporterConfig.TAG_PARAMS); for (int i = 0; i < parameters.length; i++) { addParameter(xmlBuffer, parameters[i], i); } xmlBuffer.pop(); } }
private void generateInfo(XMLStringBuffer header, ISuite suite) { // // Info // header.push(D, C, "suite-section-title"); header.addRequired(S, "Info"); header.pop(D); header.push(D, C, "suite-section-content"); header.push("ul"); // All the panels for (INavigatorPanel panel : m_panels) { addLinkTo(header, panel, suite); } header.pop("ul"); header.pop(D); // suite-section-content }
private void showProperties(XMLStringBuffer report) { report.push(XMLConstants.PROPERTIES); // Add all system properties report.addComment("Java System properties"); for (Object key : System.getProperties().keySet()) { Properties property = new Properties(); property.setProperty(XMLConstants.ATTR_NAME, key.toString()); property.setProperty(XMLConstants.ATTR_VALUE, System.getProperty(key.toString())); report.addEmptyElement(XMLConstants.PROPERTY, property); } // Add all environment variables report.addComment("Environment variables"); for (String key : System.getenv().keySet()) { Properties property = new Properties(); property.setProperty(XMLConstants.ATTR_NAME, key); property.setProperty(XMLConstants.ATTR_VALUE, System.getenv(key)); report.addEmptyElement(XMLConstants.PROPERTY, property); } report.pop(); }
private void writeSuiteToFile(File suiteFile, ISuite suite) { XMLStringBuffer xmlBuffer = new XMLStringBuffer(); writeSuiteToBuffer(xmlBuffer, suite); File parentDir = suiteFile.getParentFile(); suiteFile.getParentFile().mkdirs(); if (parentDir.exists() || suiteFile.getParentFile().exists()) { Utils.writeUtf8File(parentDir.getAbsolutePath(), FILE_NAME, xmlBuffer.toXML()); } }
/** * Add an empty element tag (e.g. <foo/>) * * @param tagName The name of the tag * */ public void addEmptyElement(String tagName) { addEmptyElement(tagName, (Properties) null); }
/** * Push a new tag. Its value is stored and will be compared against the parameter * passed to pop(). * * @param tagName The name of the tag. */ public void push(String tagName) { push(tagName, ""); }
/** * Pop the last pushed element without verifying it if matches the previously * pushed tag. */ public void pop() { pop(null); }
public void addRequired(String tagName, @Nullable String value, String... attributes) { addRequired(tagName, value, createProperties(attributes)); }