Search in sources :

Example 1 with Run

use of com.axway.ats.log.autodb.entities.Run in project ats-framework by Axway.

the class ReportExtactor method extractRunEntities.

/**
     * extract the runs
     * 
     * @param runIds
     * @return
     */
private List<RunWrapper> extractRunEntities(int[] runIds) {
    StringBuilder whereClause = new StringBuilder();
    whereClause.append(" WHERE runId IN (");
    for (int runId : runIds) {
        whereClause.append(runId).append(", ");
    }
    whereClause.setLength(whereClause.lastIndexOf(","));
    whereClause.append(")");
    List<Run> dbRuns;
    try {
        dbRuns = dbReadAccess.getRuns(0, 10000, whereClause.toString(), "runId", true);
    } catch (DatabaseAccessException e) {
        throw new ReportExtractorException("Error loading runs " + whereClause, e);
    }
    List<RunWrapper> runs = new ArrayList<RunWrapper>();
    for (Run dbRun : dbRuns) {
        // load this run's suites
        List<Suite> suites;
        try {
            suites = dbReadAccess.getSuites(0, 10000, "WHERE runId=" + dbRun.runId, "suiteId", true, false);
        } catch (DatabaseAccessException e) {
            throw new ReportExtractorException("Error loading suites for run with id " + dbRun.runId, e);
        }
        RunWrapper run = new RunWrapper(dbRun, suites);
        runs.add(run);
    }
    return runs;
}
Also used : Suite(com.axway.ats.log.autodb.entities.Suite) ReportExtractorException(com.axway.ats.log.report.exceptions.ReportExtractorException) ArrayList(java.util.ArrayList) Run(com.axway.ats.log.autodb.entities.Run) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException)

Example 2 with Run

use of com.axway.ats.log.autodb.entities.Run in project ats-framework by Axway.

the class DbReadAccess method getRuns.

@BackwardCompatibility
public List<Run> getRuns(int startRecord, int recordsCount, String whereClause, String sortColumn, boolean ascending) throws DatabaseAccessException {
    List<Run> runs = new ArrayList<Run>();
    Connection connection = getConnection();
    String sqlLog = new SqlRequestFormatter().add("start record", startRecord).add("records", recordsCount).add("where", whereClause).add("sort by", sortColumn).add("asc", ascending).format();
    CallableStatement callableStatement = null;
    ResultSet rs = null;
    try {
        callableStatement = connection.prepareCall("{ call sp_get_runs(?, ?, ?, ?, ?) }");
        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()) {
            Run run = new Run();
            run.runId = rs.getString("runId");
            run.productName = rs.getString("productName");
            run.versionName = rs.getString("versionName");
            run.buildName = rs.getString("buildName");
            run.runName = rs.getString("runName");
            run.os = rs.getString("OS");
            run.hostName = "";
            try {
                @BackwardCompatibility int // run.hostName introduced in 3.10.0 (internalVersion = 1)
                dbInternalVersion = getDatabaseInternalVersion();
                if (dbInternalVersion >= 1) {
                    run.hostName = rs.getString("hostName");
                }
            } catch (NumberFormatException nfe) {
                run.hostName = "";
                log.warn("Error parsing dbInternalVersion. ", nfe);
            }
            Timestamp dateStartTimestamp = rs.getTimestamp("dateStart");
            run.dateStart = formatDateNoYear(dateStartTimestamp);
            run.dateStartLong = formatDate(dateStartTimestamp);
            Timestamp dateEndTimestamp = rs.getTimestamp("dateEnd");
            run.dateEnd = formatDateNoYear(dateEndTimestamp);
            run.dateEndLong = formatDate(dateEndTimestamp);
            int duration = rs.getInt("duration");
            if (duration < 0) {
                // this may happen when the run is not ended and the time of the log server
                // is behind with the time of the test executor host
                duration = 0;
            }
            run.durationSeconds = duration;
            run.duration = formatTimeDiffereceFromSecondsToString(duration);
            run.scenariosTotal = rs.getInt("scenariosTotal");
            run.scenariosFailed = rs.getInt("scenariosFailed");
            run.scenariosSkipped = rs.getInt("scenariosSkipped");
            run.testcasesTotal = rs.getInt("testcasesTotal");
            run.testcasesFailed = rs.getInt("testcasesFailed");
            run.testcasesPassedPercent = String.valueOf(rs.getInt("testcasesPassedPercent")) + "%";
            run.testcaseIsRunning = rs.getBoolean("testcaseIsRunning");
            run.total = run.scenariosTotal + "/" + run.testcasesTotal;
            run.failed = run.scenariosFailed + "/" + run.testcasesFailed;
            run.userNote = rs.getString("userNote");
            if (run.userNote == null) {
                run.userNote = "";
            }
            runs.add(run);
            numberRecords++;
        }
        logQuerySuccess(sqlLog, "runs", numberRecords);
    } catch (Exception e) {
        throw new DatabaseAccessException("Error when " + sqlLog, e);
    } finally {
        DbUtils.closeResultSet(rs);
        DbUtils.close(connection, callableStatement);
    }
    return runs;
}
Also used : ArrayList(java.util.ArrayList) Connection(java.sql.Connection) DbConnection(com.axway.ats.core.dbaccess.DbConnection) Run(com.axway.ats.log.autodb.entities.Run) Timestamp(java.sql.Timestamp) Checkpoint(com.axway.ats.log.autodb.entities.Checkpoint) SQLException(java.sql.SQLException) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) BackwardCompatibility(com.axway.ats.core.utils.BackwardCompatibility) CallableStatement(java.sql.CallableStatement) ResultSet(java.sql.ResultSet) DatabaseAccessException(com.axway.ats.log.autodb.exceptions.DatabaseAccessException) BackwardCompatibility(com.axway.ats.core.utils.BackwardCompatibility)

Aggregations

Run (com.axway.ats.log.autodb.entities.Run)2 DatabaseAccessException (com.axway.ats.log.autodb.exceptions.DatabaseAccessException)2 ArrayList (java.util.ArrayList)2 DbConnection (com.axway.ats.core.dbaccess.DbConnection)1 BackwardCompatibility (com.axway.ats.core.utils.BackwardCompatibility)1 Checkpoint (com.axway.ats.log.autodb.entities.Checkpoint)1 Suite (com.axway.ats.log.autodb.entities.Suite)1 ReportExtractorException (com.axway.ats.log.report.exceptions.ReportExtractorException)1 CallableStatement (java.sql.CallableStatement)1 Connection (java.sql.Connection)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Timestamp (java.sql.Timestamp)1