public void generateEarlReport( File outputDirectory, File reportFile, String suiteName, Map params ) throws UnsupportedEncodingException { DocumentBuilderFactory docFactory = createDcumentBuilder(); Document document; try { document = docFactory.newDocumentBuilder().parse( reportFile ); } catch ( IOException | SAXException | ParserConfigurationException e ) { throw new RuntimeException( e ); } document.getDocumentElement().normalize(); Model earlReport = generateEarlReport( suiteName, params, document ); try { writeModel( earlReport, outputDirectory, true ); } catch ( IOException iox ) { throw new RuntimeException( "Failed to serialize EARL results", iox ); } }
private TestInfo getTestinfo( Element logElements ) { Element starttestElements = getElementByTagName( logElements, "starttest" ); Element endtestElements = getElementByTagName( logElements, "endtest" ); String assertion = parseTextContent( logElements, "assertion" ); if ( assertion == null ) { assertion = "Null"; } String testName = starttestElements.getAttribute( "local-name" ); int result = Integer.parseInt( endtestElements.getAttribute( "result" ) ); Element ccElement = getElementByTagName( logElements, "conformanceClass" ); boolean isCC = ( ccElement != null ) ? true : false; boolean isBasic = false; if ( ccElement != null && ccElement.hasAttribute( "isBasic" ) && Boolean.valueOf( ccElement.getAttribute( "isBasic" ) ) ) { isBasic = true; } return new TestInfo( assertion, testName, result, isCC, isBasic ); }
File testLog = new File(resultsDir, "report_logs.xml"); CtlEarlReporter report = new CtlEarlReporter(); try{ report.generateEarlReport (resultsDir, testLog, suiteName, this.testInputs); } catch (IOException iox) { throw new RuntimeException("Failed to serialize EARL results to " + resultsDir.getAbsolutePath(), iox);
String testcallPath = childtestcallElement.getAttribute( "path" ); Element childlogElement = findMatchingLogElement( logList, testcallPath ); TestInfo testDetails = getTestinfo( childlogElement ); earlResult.addProperty( DCTerms.date, earl.createTypedLiteral( calTime ) ); processTestResult( childlogElement, testDetails, earlResult ); processRequests( earlResult, childlogElement, earl ); else earl.createResource( conformanceClass ).addProperty( DCTerms.hasPart, testCase ); processTestResults( earl, childlogElement, logList, conformanceClass, testCase );
private Resource createEarlRequest( Model earl, Element reqElement ) { Element requestNode = getElementByTagName( reqElement, "http://www.occamlab.com/ctl", "request" ); if ( requestNode != null ) { String httpMethod = parseTextContent( requestNode, "http://www.occamlab.com/ctl", "method" ); String url = parseTextContent( requestNode, "http://www.occamlab.com/ctl", "url" ); Resource earlRequest = earl.createResource( HTTP.Request ); if ( "GET".equalsIgnoreCase( httpMethod ) ) { Map<String, String> parameters = parseParameters( requestNode ); String urlWithQueryString = createUrlWithQueryString( url, parameters ); earlRequest.addProperty( HTTP.methodName, httpMethod ); earlRequest.addProperty( HTTP.requestURI, urlWithQueryString );
String testcallPath = testcallElement.getAttribute( "path" ); Element logElements = findMatchingLogElement( logList, testcallPath ); TestInfo testInfo = getTestinfo( logElements ); this.cWarningCount = 0; this.cInheritedFailureCount = 0; addTestRequirements( model, testInfo ); processTestResults( model, logElements, logList, conformanceClass, null );
private Model generateEarlReport( String suiteName, Map params, Document document ) throws UnsupportedEncodingException { Model model = initializeModel( suiteName ); addTestInputs( model, params ); this.reqs = model.createSeq(); NodeList executionList = document.getElementsByTagName( "execution" ); for ( int temp = 0; temp < executionList.getLength(); temp++ ) { Node executionNode = executionList.item( temp ); Element executionElement = (Element) executionNode; NodeList logList = executionElement.getElementsByTagName( "log" ); Element logElement = (Element) logList.item( 0 ); NodeList testcallList = logElement.getElementsByTagName( "testcall" ); getSubtestResult( model, testcallList, logList ); } this.testRun.addProperty( CITE.requirements, this.reqs ); this.testRun.addLiteral( CITE.testsPassed, new Integer( this.totalPassCount ) ); this.testRun.addLiteral( CITE.testsFailed, new Integer( this.totalFailCount ) ); this.testRun.addLiteral( CITE.testsSkipped, new Integer( this.totalSkipCount ) ); this.testRun.addLiteral( CITE.testsContinue, new Integer( this.totalContinueCount ) ); this.testRun.addLiteral( CITE.testsBestPractice, new Integer( this.totalBestPracticeCount ) ); this.testRun.addLiteral( CITE.testsNotTested, new Integer( this.totalNotTestedCount ) ); this.testRun.addLiteral( CITE.testsWarning, new Integer( this.totalWarningCount ) ); this.testRun.addLiteral( CITE.testsInheritedFailure, new Integer( this.totalInheritedFailureCount ) ); this.testRun.addLiteral( CITE.testSuiteType, "ctl" ); this.testRun.addLiteral( CITE.passedCoreConformanceClasses, passedCoreConformanceClasses ); this.earlModel.add( model ); return this.earlModel; }
private void processRequest( Resource earlResult, Model earl, Element reqElement ) { Resource httpReq = createEarlRequest( earl, reqElement ); if ( httpReq == null ) return; String response = parseNodeAsString( reqElement, "response" ); if ( response != null ) { Resource httpRsp = earl.createResource( HTTP.Response ); Resource rspContent = earl.createResource( CONTENT.ContentAsXML ); rspContent.addProperty( CONTENT.rest, response ); httpRsp.addProperty( HTTP.body, rspContent ); httpReq.addProperty( HTTP.resp, httpRsp ); } earlResult.addProperty( CITE.message, httpReq ); }
private Element getElementByTagName( Element element, String tagName ) { return getElementByTagName( element, null, tagName ); }
File testLog = new File(resultsDir, "report_logs.xml"); CtlEarlReporter report = new CtlEarlReporter(); try{ report.generateEarlReport (resultsDir, testLog, suiteName, this.testInputs); } catch (IOException iox) { throw new RuntimeException("Failed to serialize EARL results to " + resultsDir.getAbsolutePath(), iox);
String testcallPath = childtestcallElement.getAttribute( "path" ); Element childlogElement = findMatchingLogElement( logList, testcallPath ); TestInfo testDetails = getTestinfo( childlogElement ); earlResult.addProperty( DCTerms.date, earl.createTypedLiteral( calTime ) ); processTestResult( childlogElement, testDetails, earlResult ); processRequests( earlResult, childlogElement, earl ); else earl.createResource( conformanceClass ).addProperty( DCTerms.hasPart, testCase ); processTestResults( earl, childlogElement, logList, conformanceClass, testCase );
private Resource createEarlRequest( Model earl, Element reqElement ) { Element requestNode = getElementByTagName( reqElement, "http://www.occamlab.com/ctl", "request" ); if ( requestNode != null ) { String httpMethod = parseTextContent( requestNode, "http://www.occamlab.com/ctl", "method" ); String url = parseTextContent( requestNode, "http://www.occamlab.com/ctl", "url" ); Resource earlRequest = earl.createResource( HTTP.Request ); if ( "GET".equalsIgnoreCase( httpMethod ) ) { Map<String, String> parameters = parseParameters( requestNode ); String urlWithQueryString = createUrlWithQueryString( url, parameters ); earlRequest.addProperty( HTTP.methodName, httpMethod ); earlRequest.addProperty( HTTP.requestURI, urlWithQueryString );
String testcallPath = testcallElement.getAttribute( "path" ); Element logElements = findMatchingLogElement( logList, testcallPath ); TestInfo testInfo = getTestinfo( logElements ); this.cWarningCount = 0; this.cInheritedFailureCount = 0; addTestRequirements( model, testInfo ); processTestResults( model, logElements, logList, conformanceClass, null );
private Model generateEarlReport( String suiteName, Map params, Document document ) throws UnsupportedEncodingException { Model model = initializeModel( suiteName ); addTestInputs( model, params ); this.reqs = model.createSeq(); NodeList executionList = document.getElementsByTagName( "execution" ); for ( int temp = 0; temp < executionList.getLength(); temp++ ) { Node executionNode = executionList.item( temp ); Element executionElement = (Element) executionNode; NodeList logList = executionElement.getElementsByTagName( "log" ); Element logElement = (Element) logList.item( 0 ); NodeList testcallList = logElement.getElementsByTagName( "testcall" ); getSubtestResult( model, testcallList, logList ); } this.testRun.addProperty( CITE.requirements, this.reqs ); this.testRun.addLiteral( CITE.testsPassed, new Integer( this.totalPassCount ) ); this.testRun.addLiteral( CITE.testsFailed, new Integer( this.totalFailCount ) ); this.testRun.addLiteral( CITE.testsSkipped, new Integer( this.totalSkipCount ) ); this.testRun.addLiteral( CITE.testsContinue, new Integer( this.totalContinueCount ) ); this.testRun.addLiteral( CITE.testsBestPractice, new Integer( this.totalBestPracticeCount ) ); this.testRun.addLiteral( CITE.testsNotTested, new Integer( this.totalNotTestedCount ) ); this.testRun.addLiteral( CITE.testsWarning, new Integer( this.totalWarningCount ) ); this.testRun.addLiteral( CITE.testsInheritedFailure, new Integer( this.totalInheritedFailureCount ) ); this.testRun.addLiteral( CITE.testSuiteType, "ctl" ); this.earlModel.add( model ); return this.earlModel; }
private void processRequest( Resource earlResult, Model earl, Element reqElement ) { Resource httpReq = createEarlRequest( earl, reqElement ); if ( httpReq == null ) return; String response = parseNodeAsString( reqElement, "response" ); if ( response != null ) { Resource httpRsp = earl.createResource( HTTP.Response ); Resource rspContent = earl.createResource( CONTENT.ContentAsXML ); rspContent.addProperty( CONTENT.rest, response ); httpRsp.addProperty( HTTP.body, rspContent ); httpReq.addProperty( HTTP.resp, httpRsp ); } earlResult.addProperty( CITE.message, httpReq ); }
private Element getElementByTagName( Element element, String tagName ) { return getElementByTagName( element, null, tagName ); }
public void generateEarlReport( OutputStream targetEarlReport, InputStream report, String suiteName, Map params ) throws UnsupportedEncodingException { DocumentBuilderFactory docFactory = createDcumentBuilder(); Document document; try { document = docFactory.newDocumentBuilder().parse( report ); } catch ( IOException | SAXException | ParserConfigurationException e ) { throw new RuntimeException( e ); } document.getDocumentElement().normalize(); Model earlReport = generateEarlReport( suiteName, params, document ); try { writeModel( earlReport, targetEarlReport, true ); } catch ( IOException iox ) { throw new RuntimeException( "Failed to serialize EARL results", iox ); } }
CtlEarlReporter report = new CtlEarlReporter(); report.generateEarlReport(resultsDir, testLog, opts.getSourcesName(), testInputMap);
private TestInfo getTestinfo( Element logElements ) { Element starttestElements = getElementByTagName( logElements, "starttest" ); Element endtestElements = getElementByTagName( logElements, "endtest" ); String assertion = parseTextContent( logElements, "assertion" ); if ( assertion == null ) { assertion = "Null"; } String testName = starttestElements.getAttribute( "local-name" ); int result = Integer.parseInt( endtestElements.getAttribute( "result" ) ); Element ccElement = getElementByTagName( logElements, "conformanceClass" ); boolean isCC = ( ccElement != null ) ? true : false; boolean isBasic = false; if ( ccElement != null && ccElement.hasAttribute( "isBasic" ) && Boolean.valueOf( ccElement.getAttribute( "isBasic" ) ) ) { isBasic = true; } return new TestInfo( assertion, testName, result, isCC, isBasic ); }
private String parseTextContent( Element element, String tagNamespaceUri, String tagName ) { Element elementByTagName = getElementByTagName( element, tagNamespaceUri, tagName ); if ( elementByTagName != null ) return elementByTagName.getTextContent(); return null; }