private void parseFiles(File[] reports, UnitTestIndex index) { SurefireStaxHandler staxParser = new SurefireStaxHandler(index); StaxParser parser = new StaxParser(staxParser, false); for (File report : reports) { try { parser.parse(report); } catch (XMLStreamException e) { throw new RuntimeException( "Fail to parse the Surefire report: " + report, e); } } }
private void parseTestCase(String testSuiteClassName, SMInputCursor testCase) throws XMLStreamException { for (SMEvent event = testCase.getNext(); event != null; event = testCase.getNext()) { if (event.compareTo(SMEvent.START_ELEMENT) == 0) { String testClassName = getClassname(testCase, testSuiteClassName); UnitTestClassReport classReport = index.index(testClassName); parseTestCase(testCase, testSuiteClassName, classReport); } } }
private void parseTestCase(SMInputCursor testCaseCursor, UnitTestClassReport report) throws XMLStreamException { report.add(parseTestResult(testCaseCursor)); }
private UnitTestResult parseTestResult(SMInputCursor testCaseCursor) throws XMLStreamException { UnitTestResult detail = new UnitTestResult(); String name = getTestCaseName(testCaseCursor); detail.setName(name); String status = UnitTestResult.STATUS_OK; long duration = getTimeAttributeInMS(testCaseCursor); SMInputCursor childNode = testCaseCursor.descendantElementCursor(); if (childNode.getNext() != null) { String elementName = childNode.getLocalName(); if ("skipped".equals(elementName)) { status = UnitTestResult.STATUS_SKIPPED; // bug with surefire reporting wrong time for skipped tests duration = 0L; } else if ("failure".equals(elementName)) { status = UnitTestResult.STATUS_FAILURE; setStackAndMessage(detail, childNode); } else if ("error".equals(elementName)) { status = UnitTestResult.STATUS_ERROR; setStackAndMessage(detail, childNode); } } while (childNode.getNext() != null) { // make sure we loop till the end of the elements cursor } detail.setDurationMilliseconds(duration); detail.setStatus(status); return detail; }
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite")); SMEvent testSuiteEvent; for (testSuiteEvent = testSuite.getNext(); testSuiteEvent != null; testSuiteEvent = testSuite.getNext()) { if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) { String testSuiteClassName = testSuite.getAttrValue("name"); if (StringUtils.contains(testSuiteClassName, "$")) { // test suites for inner classes are ignored return; } parseTestCase(testSuiteClassName, testSuite.childCursor(new ElementFilter("testcase"))); } } }
private UnitTestResult parseTestResult(SMInputCursor testCaseCursor) throws XMLStreamException { UnitTestResult detail = new UnitTestResult(); String name = getTestCaseName(testCaseCursor); detail.setName(name); String status = UnitTestResult.STATUS_OK; long duration = getTimeAttributeInMS(testCaseCursor); SMInputCursor childNode = testCaseCursor.descendantElementCursor(); if (childNode.getNext() != null) { String elementName = childNode.getLocalName(); if ("skipped".equals(elementName)) { status = UnitTestResult.STATUS_SKIPPED; // bug with surefire reporting wrong time for skipped tests duration = 0L; } else if ("failure".equals(elementName)) { status = UnitTestResult.STATUS_FAILURE; setStackAndMessage(detail, childNode); } else if ("error".equals(elementName)) { status = UnitTestResult.STATUS_ERROR; setStackAndMessage(detail, childNode); } } while (childNode.getNext() != null) { // make sure we loop till the end of the elements cursor } detail.setDurationMilliseconds(duration); detail.setStatus(status); return detail; }
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite")); SMEvent testSuiteEvent; for (testSuiteEvent = testSuite.getNext(); testSuiteEvent != null; testSuiteEvent = testSuite.getNext()) { if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) { String testSuiteClassName = testSuite.getAttrValue("name"); if (StringUtils.contains(testSuiteClassName, "$")) { // test suites for inner classes are ignored return; } parseTestCase(testSuiteClassName, testSuite.childCursor(new ElementFilter("testcase"))); } } }
private UnitTestResult parseTestResult(SMInputCursor testCaseCursor) throws XMLStreamException { UnitTestResult detail = new UnitTestResult(); String name = getTestCaseName(testCaseCursor); detail.setName(name); String status = UnitTestResult.STATUS_OK; long duration = getTimeAttributeInMS(testCaseCursor); SMInputCursor childNode = testCaseCursor.descendantElementCursor(); if (childNode.getNext() != null) { String elementName = childNode.getLocalName(); if ("skipped".equals(elementName)) { status = UnitTestResult.STATUS_SKIPPED; // bug with surefire reporting wrong time for skipped tests duration = 0L; } else if ("failure".equals(elementName)) { status = UnitTestResult.STATUS_FAILURE; setStackAndMessage(detail, childNode); } else if ("error".equals(elementName)) { status = UnitTestResult.STATUS_ERROR; setStackAndMessage(detail, childNode); } } while (childNode.getNext() != null) { // make sure we loop till the end of the elements cursor } detail.setDurationMilliseconds(duration); detail.setStatus(status); return detail; }
private void parseTestCase(String testSuiteClassName, SMInputCursor testCase) throws XMLStreamException { for (SMEvent event = testCase.getNext(); event != null; event = testCase.getNext()) { if (event.compareTo(SMEvent.START_ELEMENT) == 0) { String testClassName = getClassname(testCase, testSuiteClassName); UnitTestClassReport classReport = index.index(testClassName); parseTestCase(testCase, testSuiteClassName, classReport); } } }
private void parseFiles(File[] reports, UnitTestIndex index) { SurefireStaxHandler staxParser = new SurefireStaxHandler(index); StaxParser parser = new StaxParser(staxParser, false); for (File report : reports) { try { parser.parse(report); } catch (XMLStreamException e) { throw new IllegalStateException("Fail to parse the Surefire report: " + report, e); } } }
private static void parseTestCase(SMInputCursor testCaseCursor, String testSuiteClassName, UnitTestClassReport report) throws XMLStreamException { report.add(parseTestResult(testCaseCursor, testSuiteClassName)); }
private static UnitTestResult parseTestResult(SMInputCursor testCaseCursor, String testSuiteClassName) throws XMLStreamException { UnitTestResult detail = new UnitTestResult(); String name = getTestCaseName(testCaseCursor); detail.setName(name); detail.setTestSuiteClassName(testSuiteClassName); setStackAndMessage(detail, childNode); setStackAndMessage(detail, childNode); duration = getTimeAttributeInMS(time);
public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite")); SMEvent testSuiteEvent; while ((testSuiteEvent = testSuite.getNext()) != null) { if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) { String testSuiteClassName = testSuite.getAttrValue("name"); if (StringUtils.contains(testSuiteClassName, "$")) { // test suites for inner classes are ignored return; } SMInputCursor testCase = testSuite.childCursor(new ElementFilter("testcase")); SMEvent event; while ((event = testCase.getNext()) != null) { if (event.compareTo(SMEvent.START_ELEMENT) == 0) { String testClassName = getClassname(testCase, testSuiteClassName); UnitTestClassReport classReport = index.index(testClassName); parseTestCase(testCase, classReport); } } } } }
private void parseFiles(File[] reports, UnitTestIndex index) { SurefireStaxHandler staxParser = new SurefireStaxHandler(index); StaxParser parser = new StaxParser(staxParser, false); for (File report : reports) { try { parser.parse(report); } catch (XMLStreamException e) { throw new SonarException("Fail to parse the Surefire report: " + report, e); } } }
private void parseTestCase(SMInputCursor testCaseCursor, UnitTestClassReport report) throws XMLStreamException { report.add(parseTestResult(testCaseCursor)); }
private static UnitTestResult parseTestResult(SMInputCursor testCaseCursor, String testSuiteClassName) throws XMLStreamException { UnitTestResult detail = new UnitTestResult(); String name = getTestCaseName(testCaseCursor); detail.setName(name); detail.setTestSuiteClassName(testSuiteClassName); setStackAndMessage(detail, childNode); setStackAndMessage(detail, childNode); duration = getTimeAttributeInMS(time);
@Override public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite")); SMEvent testSuiteEvent; for (testSuiteEvent = testSuite.getNext(); testSuiteEvent != null; testSuiteEvent = testSuite.getNext()) { if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) { String testSuiteClassName = testSuite.getAttrValue("name"); if (StringUtils.contains(testSuiteClassName, "$")) { // test suites for inner classes are ignored return; } SMInputCursor testCase = testSuite.childCursor(new ElementFilter("testcase")); SMEvent event; for (event = testCase.getNext(); event != null; event = testCase.getNext()) { if (event.compareTo(SMEvent.START_ELEMENT) == 0) { String testClassName = getClassname(testCase, testSuiteClassName); UnitTestClassReport classReport = index.index(testClassName); parseTestCase(testCase, classReport); } } } } }
private void parseFiles(File[] reports, UnitTestIndex index) { SurefireStaxHandler staxParser = new SurefireStaxHandler(index); StaxParser parser = new StaxParser(staxParser, false); for (File report : reports) { try { parser.parse(report); } catch (XMLStreamException e) { throw new SonarException("Fail to parse the Surefire report: " + report, e); } } }
private void parseTestCase(SMInputCursor testCaseCursor, UnitTestClassReport report) throws XMLStreamException { report.add(parseTestResult(testCaseCursor)); }
@Override public void stream(SMHierarchicCursor rootCursor) throws XMLStreamException { SMInputCursor testSuite = rootCursor.constructDescendantCursor(new ElementFilter("testsuite")); SMEvent testSuiteEvent; for (testSuiteEvent = testSuite.getNext(); testSuiteEvent != null; testSuiteEvent = testSuite.getNext()) { if (testSuiteEvent.compareTo(SMEvent.START_ELEMENT) == 0) { String testSuiteClassName = testSuite.getAttrValue("name"); if (StringUtils.contains(testSuiteClassName, "$")) { // test suites for inner classes are ignored return; } SMInputCursor testCase = testSuite.childCursor(new ElementFilter("testcase")); SMEvent event; for (event = testCase.getNext(); event != null; event = testCase.getNext()) { if (event.compareTo(SMEvent.START_ELEMENT) == 0) { String testClassName = getClassname(testCase, testSuiteClassName); UnitTestClassReport classReport = index.index(testClassName); parseTestCase(testCase, classReport); } } } } }