/** * {@inheritDoc} */ @Override public void characters( char[] ch, int start, int length ) { assert start >= 0; assert length >= 0; if ( valid && isNotBlank( start, length, ch ) ) { currentElement.append( ch, start, length ); } }
static String parseErrorLine( StringBuilder currentElement, String fullClassName ) { final String[] linePatterns = { "at " + fullClassName + '.', "at " + fullClassName + '$' }; int[] indexes = lastIndexOf( currentElement, linePatterns ); int patternStartsAt = indexes[0]; if ( patternStartsAt != -1 ) { int searchFrom = patternStartsAt + ( linePatterns[ indexes[1] ] ).length(); searchFrom = 1 + currentElement.indexOf( ":", searchFrom ); int searchTo = currentElement.indexOf( ")", searchFrom ); return isNumeric( currentElement, searchFrom, searchTo ) ? currentElement.substring( searchFrom, searchTo ) : ""; } return ""; }
public List<ReportTestSuite> parse( String xmlPath ) throws ParserConfigurationException, SAXException, IOException { File f = new File( xmlPath ); try ( InputStreamReader stream = new InputStreamReader( new FileInputStream( f ), UTF_8 ) ) { return parse( stream ); } }
final TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger ); for ( File aXmlReportFileList : xmlReportFiles ) testSuites.addAll( parser.parse( aXmlReportFileList.getAbsolutePath() ) );
/** * {@inheritDoc} */ @Override public void endElement( String uri, String localName, String qName ) throws SAXException { // todo: use jdk7 switch-case if ( "testcase".equals( qName ) ) { currentSuite.getTestCases().add( testCase ); } else if ( "failure".equals( qName ) || "error".equals( qName ) ) { testCase.setFailureDetail( currentElement.toString() ) .setFailureErrorLine( parseErrorLine( currentElement, testCase.getFullClassName() ) ); } else if ( "time".equals( qName ) ) { try { defaultSuite.setTimeElapsed( numberFormat.parse( currentElement.toString() ).floatValue() ); } catch ( ParseException e ) { throw new SAXException( e.getMessage(), e ); } } // TODO extract real skipped reasons }
final TestSuiteXmlParser parser = new TestSuiteXmlParser( consoleLogger ); for ( File aXmlReportFileList : xmlReportFiles ) testSuites.addAll( parser.parse( aXmlReportFileList.getAbsolutePath() ) );
case "error": testCase.setFailureDetail( currentElement.toString() ) .setFailureErrorLine( parseErrorLine( currentElement, testCase.getFullClassName() ) ); break; case "time":
static String parseErrorLine( StringBuilder currentElement, String fullClassName ) { final String[] linePatterns = { "at " + fullClassName + '.', "at " + fullClassName + '$' }; int[] indexes = lastIndexOf( currentElement, linePatterns ); int patternStartsAt = indexes[0]; if ( patternStartsAt != -1 ) { int searchFrom = patternStartsAt + ( linePatterns[ indexes[1] ] ).length(); searchFrom = 1 + currentElement.indexOf( ":", searchFrom ); int searchTo = currentElement.indexOf( ")", searchFrom ); return isNumeric( currentElement, searchFrom, searchTo ) ? currentElement.substring( searchFrom, searchTo ) : ""; } return ""; }
public List<ReportTestSuite> parse( String xmlPath ) throws ParserConfigurationException, SAXException, IOException { FileInputStream fileInputStream = new FileInputStream( new File( xmlPath ) ); InputStreamReader inputStreamReader = new InputStreamReader( fileInputStream, "UTF-8" ); try { return parse( inputStreamReader ); } finally { inputStreamReader.close(); fileInputStream.close(); } }
/** * {@inheritDoc} */ @Override public void characters( char[] ch, int start, int length ) throws SAXException { assert start >= 0; assert length >= 0; if ( valid && isNotBlank( start, length, ch ) ) { currentElement.append( ch, start, length ); } }