Search in sources :

Example 1 with Scenario

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;
}
Also used : CallableStatement(java.sql.CallableStatement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) ResultSet(java.sql.ResultSet) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) Scenario(com.axway.ats.log.autodb.entities.Scenario)

Aggregations

DbConnection (com.axway.ats.core.dbaccess.DbConnection)1 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)1 Scenario (com.axway.ats.log.autodb.entities.Scenario)1 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 ArrayList (java.util.ArrayList)1