Java 类org.testng.reporters.XMLStringBuffer 实例源码

项目:heat    文件:CustomJUnitReportListener.java   
private void setFailedTcAttribute(XMLStringBuffer doc, ITestResult failedTestCase) {
    Properties attributesFailedTestSuites = new Properties();
    String tcName = ((HashMap<String, String>) failedTestCase.getParameters()[0]).get(PROP_TEST_ID);
    attributesFailedTestSuites.setProperty(XMLConstants.ATTR_NAME, tcName);
    long elapsedTimeMillis = failedTestCase.getEndMillis() - failedTestCase.getStartMillis();
    testRunningTotalTime += elapsedTimeMillis;
    Throwable t = failedTestCase.getThrowable();
    doc.push(XMLConstants.TESTCASE, attributesFailedTestSuites);
    if (t != null) {
        attributesFailedTestSuites.setProperty(XMLConstants.ATTR_TYPE, t.getClass().getName());
        String message = t.getMessage();
        if ((message != null) && (message.length() > 0)) {
            attributesFailedTestSuites.setProperty(XMLConstants.ATTR_MESSAGE, encodeAttr(message)); // ENCODE
        }
        doc.push(XMLConstants.FAILURE, attributesFailedTestSuites);
        doc.addCDATA(Utils.stackTrace(t, false)[0]);
        doc.pop();
    } else {
        doc.addEmptyElement(XMLConstants.FAILURE); // THIS IS AN ERROR
    }
    doc.pop();
}
项目:wtf-core    文件:XmlJuintReport.java   
public static void createFailureElement(XMLStringBuffer doc, ITestResult tr) {
  Properties attrs = new Properties();
  Throwable t = tr.getThrowable();
  if (t != null) {
    attrs.setProperty(XMLConstants.ATTR_TYPE, t.getClass().getName());
    String message= t.getMessage();
    if ((message != null) && (message.length() > 0)) {
      attrs.setProperty(XMLConstants.ATTR_MESSAGE, encodeAttr(message)); // ENCODE
    }
    doc.push(XMLConstants.FAILURE, attrs);
    doc.addCDATA(Utils.stackTrace(t, false)[0]);
    doc.pop();
  } else {
    doc.addEmptyElement(XMLConstants.FAILURE); // THIS IS AN ERROR
  }
}
项目:automation-test-engine    文件:TestStepsXMLReporterUtils.java   
/**
 * Adds the test steps.
 * 
 * @param xmlBuffer
 *            the xml buffer
 * @param testResult
 *            the test result
 */
public static void addTestSteps(XMLStringBuffer xmlBuffer,
        ITestResult testResult) {

    if (testResult.getAttribute(TestStepResult.STEPRESULTLIST) instanceof List<?>) {
        @SuppressWarnings("unchecked")
        List<TestStepResult> stepResults = (List<TestStepResult>) testResult
                .getAttribute(TestStepResult.STEPRESULTLIST);
        if (!stepResults.isEmpty()) {
            xmlBuffer.push(ATEXMLReporterConfig.TAG_STEPS);
            for (int i = 0; i < stepResults.size(); i++) {
                addStep(xmlBuffer, stepResults.get(i), i);
            }
            xmlBuffer.pop();
        }
    }
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
private void writeSuiteGroups(XMLStringBuffer xmlBuffer, ISuite suite) {
    xmlBuffer.push(XMLReporterConfig.TAG_GROUPS);
    Map<String, Collection<ITestNGMethod>> methodsByGroups = suite
            .getMethodsByGroups();
    for (Map.Entry<String, Collection<ITestNGMethod>> entry : methodsByGroups
            .entrySet()) {
        Properties groupAttrs = new Properties();
        groupAttrs.setProperty(XMLReporterConfig.ATTR_NAME, entry.getKey());
        xmlBuffer.push(XMLReporterConfig.TAG_GROUP, groupAttrs);
        Set<ITestNGMethod> groupMethods = getUniqueMethodSet(entry
                .getValue());
        for (ITestNGMethod groupMethod : groupMethods) {
            Properties methodAttrs = new Properties();
            methodAttrs.setProperty(XMLReporterConfig.ATTR_NAME,
                    groupMethod.getMethodName());
            methodAttrs.setProperty(XMLReporterConfig.ATTR_METHOD_SIG,
                    groupMethod.toString());
            methodAttrs.setProperty(XMLReporterConfig.ATTR_CLASS,
                    groupMethod.getRealClass().getName());
            xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_METHOD,
                    methodAttrs);
        }
        xmlBuffer.pop();
    }
    xmlBuffer.pop();
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private void addTestResults(XMLStringBuffer xmlBuffer, Set<ITestResult> testResults) {
  Map<String, List<ITestResult>> testsGroupedByClass = buildTestClassGroups(testResults);
  for (Map.Entry<String, List<ITestResult>> result : testsGroupedByClass.entrySet()) {
    Properties attributes = new Properties();
    String className = result.getKey();
    if (config.isSplitClassAndPackageNames()) {
      int dot = className.lastIndexOf('.');
      attributes.setProperty(XMLReporterConfig.ATTR_NAME,
              dot > -1 ? className.substring(dot + 1, className.length()) : className);
      attributes.setProperty(XMLReporterConfig.ATTR_PACKAGE, dot > -1 ? className.substring(0, dot) : "[default]");
    } else {
      attributes.setProperty(XMLReporterConfig.ATTR_NAME, className);
    }

    xmlBuffer.push(XMLReporterConfig.TAG_CLASS, attributes);
    List<ITestResult> sortedResults = result.getValue();
    Collections.sort( sortedResults );
    for (ITestResult testResult : sortedResults) {
      addTestResult(xmlBuffer, testResult);
    }
    xmlBuffer.pop();
  }
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private void addTestResult(XMLStringBuffer xmlBuffer, ITestResult testResult) {
  Properties attribs = getTestResultAttributes(testResult);
  attribs.setProperty(XMLReporterConfig.ATTR_STATUS, getStatusString(testResult.getStatus()));
  String testInstanceName;
  if (testResult.getName() == null) {
    testInstanceName = "";
  } else {
    testInstanceName = testResult.getName();
  }

  attribs.setProperty(XMLReporterConfig.ATTR_TEST_INSTANCE_NAME, testInstanceName);
  xmlBuffer.push(XMLReporterConfig.TAG_TEST_METHOD, attribs);
  addTestMethodParams(xmlBuffer, testResult);
  TestStepsXMLReporterUtils.addTestSteps(xmlBuffer, testResult);
  addTestResultException(xmlBuffer, testResult);
  addTestResultOutput(xmlBuffer, testResult);
  if (config.isGenerateTestResultAttributes()) {
    addTestResultAttributes(xmlBuffer, testResult);
  }
  xmlBuffer.pop();
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private void addTestResultAttributes(XMLStringBuffer xmlBuffer, ITestResult testResult) {
  if (testResult.getAttributeNames() != null && testResult.getAttributeNames().size() > 0) {
    xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTES);
    for (String attrName: testResult.getAttributeNames()) {
      if (attrName == null) {
        continue;
      }
      Object attrValue = testResult.getAttribute(attrName);

      Properties attributeAttrs = new Properties();
      attributeAttrs.setProperty(XMLReporterConfig.ATTR_NAME, attrName);
      if (attrValue == null) {
        attributeAttrs.setProperty(XMLReporterConfig.ATTR_IS_NULL, "true");
        xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs);
      } else {
        xmlBuffer.push(XMLReporterConfig.TAG_ATTRIBUTE, attributeAttrs);
        xmlBuffer.addCDATA(attrValue.toString());
        xmlBuffer.pop();
      }
    }
    xmlBuffer.pop();
  }
}
项目:wtf-core    文件:XmlJuintReport.java   
public static void createElement(XMLStringBuffer doc, ITestResult tr) {
  Properties attrs = new Properties();
  long elapsedTimeMillis = tr.getEndMillis() - tr.getStartMillis();
  String name =
      tr.getMethod().isTest() ? tr.getName() : Utils.detailedMethodName(tr.getMethod(), false);

  //SimpleDateFormat simpleDateFormat = new SimpleDateFormat("dd-MMMMM hh:mm aaa");
  //String testRunTest = String.format("%s", simpleDateFormat.format(new Date()));

  String testRunTest = FastDateFormat.getInstance("dd-MMMMM hh:mm aaa").format(new Date());

  attrs.setProperty(XMLConstants.ATTR_NAME, String.format("%s  [%s]", name, testRunTest));
  attrs.setProperty(XMLConstants.ATTR_CLASSNAME, tr.getTestClass().getRealClass().getName());
  attrs.setProperty(XMLConstants.ATTR_TIME, "" + (((double) elapsedTimeMillis) / 1000));

  if((ITestResult.FAILURE == tr.getStatus()) || (ITestResult.SKIP == tr.getStatus())) {
    doc.push(XMLConstants.TESTCASE, attrs);

    if(ITestResult.FAILURE == tr.getStatus()) {
      createFailureElement(doc, tr);
    }
    else if(ITestResult.SKIP == tr.getStatus()) {
      createSkipElement(doc, tr);
    }
    doc.pop();
  }else {
    doc.addEmptyElement(XMLConstants.TESTCASE, attrs);
  }
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
@Override
public void generateReport(List<XmlSuite> xmlSuites, List<ISuite> suites,
        String outputDirectory) {
    if (Utils.isStringEmpty(config.getOutputDirectory())) {
        config.setOutputDirectory(outputDirectory);
    }

    // Calculate passed/failed/skipped
    int passed = 0;
    int failed = 0;
    int skipped = 0;
    for (ISuite s : suites) {
        for (ISuiteResult sr : s.getResults().values()) {
            ITestContext testContext = sr.getTestContext();
            passed += testContext.getPassedTests().size();
            failed += testContext.getFailedTests().size();
            skipped += testContext.getSkippedTests().size();
        }
    }

    rootBuffer = new XMLStringBuffer();
    Properties p = new Properties();
    p.put("passed", passed);
    p.put("failed", failed);
    p.put("skipped", skipped);
    p.put("total", passed + failed + skipped);
    rootBuffer.push(XMLReporterConfig.TAG_TESTNG_RESULTS, p);
    writeReporterOutput(rootBuffer);
    for (int i = 0; i < suites.size(); i++) {
        writeSuite(suites.get(i).getXmlSuite(), suites.get(i));
    }
    rootBuffer.pop();
    Utils.writeUtf8File(config.getOutputDirectory(), FILE_NAME, rootBuffer,
            null /* no prefix */);
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
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();
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
private void writeSuiteToFile(File suiteFile, ISuite suite) {
    XMLStringBuffer xmlBuffer = new XMLStringBuffer();
    writeSuiteToBuffer(xmlBuffer, suite);
    File parentDir = suiteFile.getParentFile();
    if (parentDir.exists() || suiteFile.getParentFile().mkdirs()) {
        Utils.writeFile(parentDir.getAbsolutePath(), FILE_NAME,
                xmlBuffer.toXML());
    }
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
private File referenceSuite(XMLStringBuffer xmlBuffer, ISuite suite) {
    String relativePath = suite.getName() + File.separatorChar + FILE_NAME;
    File suiteFile = new File(config.getOutputDirectory(), relativePath);
    Properties attrs = new Properties();
    attrs.setProperty(XMLReporterConfig.ATTR_URL, relativePath);
    xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_SUITE, attrs);
    return suiteFile;
}
项目:automation-test-engine    文件:ATEXMLReporter.java   
private void writeSuiteToBuffer(XMLStringBuffer xmlBuffer, ISuite suite) {
    xmlBuffer.push(XMLReporterConfig.TAG_SUITE, getSuiteAttributes(suite));
    writeSuiteGroups(xmlBuffer, suite);

    Map<String, ISuiteResult> results = suite.getResults();
    ATEXMLSuiteResultWriter suiteResultWriter = new ATEXMLSuiteResultWriter(
            config);
    for (Map.Entry<String, ISuiteResult> result : results.entrySet()) {
        suiteResultWriter.writeSuiteResult(xmlBuffer, result.getValue());
    }

    xmlBuffer.pop();
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
/**
* Writes the specified ISuiteResult in the given XMLStringBuffer. Please consider that depending on the settings in
* the <code>config</code> property it might generate an additional XML file with the actual content and only
* reference the file with an <code>url</code> attribute in the passed XMLStringBuffer.
*
* @param xmlBuffer The XML buffer where to write or reference the suite result
* @param suiteResult The <code>ISuiteResult</code> to serialize
*/
  public void writeSuiteResult(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) {
    if (XMLReporterConfig.FF_LEVEL_SUITE_RESULT != config.getFileFragmentationLevel()) {
      writeAllToBuffer(xmlBuffer, suiteResult);
    } else {
      String parentDir =
              config.getOutputDirectory() + File.separatorChar + suiteResult.getTestContext().getSuite().getName();
      File file = referenceSuiteResult(xmlBuffer, parentDir, suiteResult);
      XMLStringBuffer suiteXmlBuffer = new XMLStringBuffer();
      writeAllToBuffer(suiteXmlBuffer, suiteResult);
      Utils.writeUtf8File(file.getAbsoluteFile().getParent(), file.getName(), suiteXmlBuffer.toXML());
    }
  }
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private void writeAllToBuffer(XMLStringBuffer xmlBuffer, ISuiteResult suiteResult) {
  xmlBuffer.push(XMLReporterConfig.TAG_TEST, getSuiteResultAttributes(suiteResult));
  Set<ITestResult> testResults = Sets.newHashSet();
  ITestContext testContext = suiteResult.getTestContext();
  addAllTestResults(testResults, testContext.getPassedTests());
  addAllTestResults(testResults, testContext.getFailedTests());
  addAllTestResults(testResults, testContext.getSkippedTests());
  addAllTestResults(testResults, testContext.getPassedConfigurations());
  addAllTestResults(testResults, testContext.getSkippedConfigurations());
  addAllTestResults(testResults, testContext.getFailedConfigurations());
  addAllTestResults(testResults, testContext.getFailedButWithinSuccessPercentageTests());
  addTestResults(xmlBuffer, testResults);
  xmlBuffer.pop();
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private File referenceSuiteResult(XMLStringBuffer xmlBuffer, String parentDir, ISuiteResult suiteResult) {
  Properties attrs = new Properties();
  String suiteResultName = suiteResult.getTestContext().getName() + ".xml";
  attrs.setProperty(XMLReporterConfig.ATTR_URL, suiteResultName);
  xmlBuffer.addEmptyElement(XMLReporterConfig.TAG_TEST, attrs);
  return new File(parentDir + File.separatorChar + suiteResultName);
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
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();
  }
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
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();
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private void addTestResultException(XMLStringBuffer xmlBuffer, ITestResult testResult) {
  Throwable exception = testResult.getThrowable();
  if (exception != null) {
    Properties exceptionAttrs = new Properties();
    exceptionAttrs.setProperty(XMLReporterConfig.ATTR_CLASS, exception.getClass().getName());
    xmlBuffer.push(XMLReporterConfig.TAG_EXCEPTION, exceptionAttrs);

    if (!Utils.isStringEmpty(exception.getMessage())) {
      xmlBuffer.push(XMLReporterConfig.TAG_MESSAGE);
      xmlBuffer.addCDATA(exception.getMessage());
      xmlBuffer.pop();
    }

    String[] stackTraces = Utils.stackTrace(exception, false);
    if ((config.getStackTraceOutputMethod() & XMLReporterConfig.STACKTRACE_SHORT) == XMLReporterConfig
            .STACKTRACE_SHORT) {
      xmlBuffer.push(XMLReporterConfig.TAG_SHORT_STACKTRACE);
      xmlBuffer.addCDATA(stackTraces[0]);
      xmlBuffer.pop();
    }
    if ((config.getStackTraceOutputMethod() & XMLReporterConfig.STACKTRACE_FULL) == XMLReporterConfig
            .STACKTRACE_FULL) {
      xmlBuffer.push(XMLReporterConfig.TAG_FULL_STACKTRACE);
      xmlBuffer.addCDATA(stackTraces[1]);
      xmlBuffer.pop();
    }

    xmlBuffer.pop();
  }
}
项目:automation-test-engine    文件:ATEXMLSuiteResultWriter.java   
private void addTestResultOutput(XMLStringBuffer xmlBuffer, ITestResult testResult) {
  // TODO: Cosmin - maybe a <line> element isn't indicated for each line
  xmlBuffer.push(XMLReporterConfig.TAG_REPORTER_OUTPUT);
  List<String> output = Reporter.getOutput(testResult);
  for (String line : output) {
    if (line != null) {
      xmlBuffer.push(XMLReporterConfig.TAG_LINE);
      xmlBuffer.addCDATA(line);
      xmlBuffer.pop();
    }
  }
  xmlBuffer.pop();
}
项目:wtf-core    文件:XmlJuintReport.java   
public static void createSkipElement(XMLStringBuffer doc, ITestResult tr) {
  doc.addEmptyElement("skipped");
}