use of com.axway.ats.log.autodb.entities.Testcase in project ats-framework by Axway.
the class DbEventRequestProcessor method deleteRequestedTestcase.
private void deleteRequestedTestcase() throws DatabaseAccessException {
/*
* This code runs on the Test Executor side
*/
// delete this testcase
List<Object> testcasesToDelete = new ArrayList<Object>();
Testcase tc = new Testcase();
tc.testcaseId = String.valueOf(testcaseToDelete);
testcasesToDelete.add(tc);
dbAccess.deleteTestcase(testcasesToDelete);
/*
* Remember this testcase was deleted.
* From now on all events related to this testcase will be simply skipped without going to the DB
*/
deletedTestcases.add(testcaseToDelete);
testcaseToDelete = -1;
}
use of com.axway.ats.log.autodb.entities.Testcase in project ats-framework by Axway.
the class DbReadAccess method getTestcases.
public List<Testcase> getTestcases(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending, boolean dateFormatNoYear) throws DatabaseAccessException {
List<Testcase> testcases = new ArrayList<Testcase>();
String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
Connection connection = getConnection();
CallableStatement callableStatement = null;
ResultSet rs = null;
try {
callableStatement = connection.prepareCall("{ call sp_get_testcases(?, ?, ?, ?, ?) }");
callableStatement.setString(1, String.valueOf(startRecord));
callableStatement.setString(2, String.valueOf(recordsCount));
callableStatement.setString(3, whereClause);
callableStatement.setString(4, sortColumn);
callableStatement.setString(5, (ascending ? "ASC" : "DESC"));
int numberRecords = 0;
rs = callableStatement.executeQuery();
while (rs.next()) {
Testcase testcase = new Testcase();
testcase.testcaseId = rs.getString("testcaseId");
testcase.scenarioId = rs.getString("scenarioId");
testcase.suiteId = rs.getString("suiteId");
testcase.name = rs.getString("name");
if (dateFormatNoYear) {
testcase.dateStart = formatDateNoYear(rs.getTimestamp("dateStart"));
testcase.dateEnd = formatDateNoYear(rs.getTimestamp("dateEnd"));
} else {
testcase.dateStart = formatDate(rs.getTimestamp("dateStart"));
testcase.dateEnd = formatDate(rs.getTimestamp("dateEnd"));
}
int duration = rs.getInt("duration");
if (duration < 0) {
// this may happen when the test case is not ended and the time of the log server
// is behind with the time of the test executor host
duration = 0;
}
testcase.duration = formatTimeDiffereceFromSecondsToString(duration);
testcase.result = rs.getInt("result");
/*
* -- 0 FAILED
* -- 1 PASSED
* -- 2 SKIPPED
* -- 4 RUNNING
*/
switch(testcase.result) {
case 0:
testcase.state = "FAILED";
break;
case 1:
testcase.state = "PASSED";
break;
case 2:
testcase.state = "SKIPPED";
break;
case 4:
testcase.state = "RUNNING";
break;
default:
//TODO: add warning
testcase.state = "unknown";
}
testcase.userNote = rs.getString("userNote");
testcases.add(testcase);
numberRecords++;
}
logQuerySuccess(sqlLog, "test cases", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return testcases;
}
use of com.axway.ats.log.autodb.entities.Testcase in project ats-framework by Axway.
the class SuiteWrapper method calculateFinalStatistics.
public void calculateFinalStatistics() {
if (dataLoadedFromDb) {
// all statistics came calculated
return;
}
for (Entry<String, List<Testcase>> scenarioEntry : testcasesMap.entrySet()) {
++scenariosTotal;
ScenarioResult scenarioResult = ScenarioResult.PASSED;
Collection<Testcase> testcasesPerScenario = scenarioEntry.getValue();
for (Testcase testcase : testcasesPerScenario) {
++testcasesTotal;
switch(testcase.result) {
case // FAILED
0:
++testcasesFailed;
scenarioResult = ScenarioResult.FAILED;
break;
case // SKIPPED
2:
++testcasesSkipped;
if (scenarioResult == ScenarioResult.PASSED) {
scenarioResult = ScenarioResult.SKIPPED;
}
break;
default:
break;
}
}
if (scenarioResult == ScenarioResult.FAILED) {
++scenariosFailed;
} else if (scenarioResult == ScenarioResult.SKIPPED) {
++scenariosSkipped;
}
}
}
use of com.axway.ats.log.autodb.entities.Testcase 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