use of com.axway.ats.log.autodb.entities.Scenario in project ats-framework by Axway.
the class DbReadAccess method getScenarios.
public List<Scenario> getScenarios(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending, boolean dateFormatNoYear) throws DatabaseAccessException {
List<Scenario> scenarios = new ArrayList<Scenario>();
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_scenarios(?, ?, ?, ?, ?) }");
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()) {
Scenario scenario = new Scenario();
scenario.scenarioId = rs.getString("scenarioId");
scenario.suiteId = rs.getString("suiteId");
scenario.name = rs.getString("name");
scenario.description = rs.getString("description");
scenario.testcasesTotal = rs.getInt("testcasesTotal");
scenario.testcasesFailed = rs.getInt("testcasesFailed");
scenario.testcasesPassedPercent = String.valueOf(rs.getInt("testcasesPassedPercent")) + "%";
scenario.testcaseIsRunning = rs.getBoolean("testcaseIsRunning");
if (dateFormatNoYear) {
scenario.dateStart = formatDateNoYear(rs.getTimestamp("dateStart"));
scenario.dateEnd = formatDateNoYear(rs.getTimestamp("dateEnd"));
} else {
scenario.dateStart = formatDate(rs.getTimestamp("dateStart"));
scenario.dateEnd = formatDate(rs.getTimestamp("dateEnd"));
}
int duration = rs.getInt("duration");
if (duration < 0) {
// this may happen when the scenario is not ended and the time of the log server
// is behind with the time of the test executor host
duration = 0;
}
scenario.duration = formatTimeDiffereceFromSecondsToString(duration);
scenario.result = rs.getInt("result");
/*
* -- 0 FAILED
* -- 1 PASSED
* -- 2 SKIPPED
* -- 4 RUNNING
*/
switch(scenario.result) {
case 0:
scenario.state = "FAILED";
break;
case 1:
scenario.state = "PASSED";
break;
case 2:
scenario.state = "SKIPPED";
break;
case 4:
scenario.state = "RUNNING";
break;
default:
//TODO: add warning
scenario.state = "unknown";
}
scenario.userNote = rs.getString("userNote");
scenarios.add(scenario);
numberRecords++;
}
logQuerySuccess(sqlLog, "scenarios", numberRecords);
} catch (Exception e) {
throw new DatabaseAccessException("Error when " + sqlLog, e);
} finally {
DbUtils.closeResultSet(rs);
DbUtils.close(connection, callableStatement);
}
return scenarios;
}
Aggregations