use of com.axway.ats.log.autodb.events.EndSuiteEvent in project ats-framework by Axway.
the class ReportAppender method append.
/* (non-Javadoc)
* @see org.apache.log4j.AppenderSkeleton#append(org.apache.log4j.spi.LoggingEvent)
*/
@Override
protected void append(LoggingEvent event) {
// All events from all threads come into here.
if (event instanceof AbstractLoggingEvent) {
AbstractLoggingEvent dbLoggingEvent = (AbstractLoggingEvent) event;
switch(dbLoggingEvent.getEventType()) {
case START_RUN:
run = new RunWrapper();
suitesMap = new HashMap<String, SuiteWrapper>();
StartRunEvent startRunEvent = (StartRunEvent) event;
run.productName = startRunEvent.getProductName();
run.versionName = startRunEvent.getVersionName();
run.buildName = startRunEvent.getBuildName();
run.os = startRunEvent.getOsName();
run.runName = startRunEvent.getRunName();
run.dateStart = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(startRunEvent.getTimeStamp());
break;
case START_SUITE:
StartSuiteEvent startSuiteEvent = (StartSuiteEvent) event;
lastPlayedSuite = startSuiteEvent.getSuiteName();
if (!suitesMap.containsKey(lastPlayedSuite)) {
SuiteWrapper newSuite = new SuiteWrapper();
newSuite.name = startSuiteEvent.getSuiteName();
newSuite.packageName = startSuiteEvent.getPackage();
newSuite.dateStart = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(startSuiteEvent.getTimeStamp());
suitesMap.put(newSuite.packageName + "." + newSuite.name, newSuite);
run.addSuite(newSuite);
}
break;
case START_TEST_CASE:
StartTestCaseEvent startTestcaseEvent = (StartTestCaseEvent) dbLoggingEvent;
startTestcaseEvent.getSuiteFullName();
Testcase newTestcase = new Testcase();
newTestcase.scenarioName = startTestcaseEvent.getScenarioName();
newTestcase.name = startTestcaseEvent.getTestcaseName();
suitesMap.get(startTestcaseEvent.getSuiteFullName()).addTestcase(newTestcase);
/*
* There are very rare cases when the test harness system does not execute all tests from
* same suite one after another, but there will be some tests from another suite executed
* in between.
*
* That is why the next line navigates to the right suite when starting the test scenario
*/
lastPlayedSuite = startTestcaseEvent.getSuiteFullName();
break;
case END_TEST_CASE:
EndTestCaseEvent endTestCaseEvent = (EndTestCaseEvent) event;
// update the result of the current testcase
suitesMap.get(lastPlayedSuite).getLastTestcase().result = endTestCaseEvent.getTestCaseResult().toInt();
break;
case END_SUITE:
EndSuiteEvent endSuiteEvent = (EndSuiteEvent) event;
SuiteWrapper currentSuite = getCurrentSuite();
if (currentSuite != null) {
currentSuite.calculateFinalStatistics();
currentSuite.dateEnd = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(endSuiteEvent.getTimeStamp());
currentSuite.duration = calculateDuration(currentSuite.dateStart, currentSuite.dateEnd);
currentSuite.testcasesPassedPercent = "0";
if (currentSuite.testcasesTotal > 0) {
currentSuite.testcasesPassedPercent = String.valueOf((currentSuite.testcasesTotal - currentSuite.testcasesFailed - currentSuite.testcasesSkipped) * 100 / currentSuite.testcasesTotal);
}
}
// we cleanup here in case first Scenario of next Suite has same name
// as last Scenario of current Suite
lastPlayedSuite = "";
break;
case END_RUN:
// The run is over, we want to mail a report about this run
EndRunEvent endRunEvent = (EndRunEvent) event;
run.calculateFinalStatistics();
run.dateEnd = AbstractDbAccess.DATE_FORMAT_NO_YEAR.format(endRunEvent.getTimeStamp());
run.duration = calculateDuration(run.dateStart, run.dateEnd);
run.testcasesPassedPercent = "0";
if (run.testcasesTotal > 0) {
run.testcasesPassedPercent = String.valueOf((run.testcasesTotal - run.testcasesFailed - run.testcasesSkipped) * 100 / run.testcasesTotal);
try {
// format the report
ReportFormatter reportFormatter = new ReportFormatter(run);
// so, just add the test data to the map
if (!combinedHtmlMailReport) {
// send report by mail
MailReportSender mailReportSender = new MailReportSender(generateMailSubject(run, reportFormatter.getRunsState()), reportFormatter.toHtml());
mailReportSender.send();
} else {
// delay report to collect data for all runs
htmlReportsList.add(run);
}
} catch (Exception e) {
errorHandler.error("Error processing/mailing log report", e, ErrorCode.GENERIC_FAILURE);
}
}
break;
}
}
}
Aggregations