Search in sources :

Example 6 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseExecutionQueueDAO method updateToDone.

@Override
public void updateToDone(long id, String comment, long exeId) throws CerberusException {
    String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'DONE', `" + COLUMN_EXEID + "` = ?, `" + COLUMN_COMMENT + "` = ?, `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now() " + "WHERE `" + COLUMN_ID + "` = ? ";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.id : " + id);
    }
    try (Connection connection = databaseSpring.connect();
        PreparedStatement updateStateAndCommentStatement = connection.prepareStatement(query)) {
        // fillUpdateStateAndCommentAndIdStatement(id, TestCaseExecutionQueue.State.DONE, comment, exeId, updateStateAndCommentStatement);
        updateStateAndCommentStatement.setLong(1, exeId);
        updateStateAndCommentStatement.setString(2, comment);
        updateStateAndCommentStatement.setLong(3, id);
        int updateResult = updateStateAndCommentStatement.executeUpdate();
        if (updateResult <= 0) {
            LOG.warn("Unable to move state to DONE for execution in queue " + id + " (update result: " + updateResult + ")");
            throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
        }
    } catch (SQLException e) {
        LOG.warn("Unable to set move to DONE for execution in queue id " + id, e);
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 7 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseExecutionQueueDAO method updateToError.

@Override
public void updateToError(long id, String comment) throws CerberusException {
    String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'ERROR', `" + COLUMN_COMMENT + "` = ?, `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now() " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` = 'STARTING'";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.id : " + id);
    }
    try (Connection connection = databaseSpring.connect();
        PreparedStatement updateStateAndCommentStatement = connection.prepareStatement(query)) {
        updateStateAndCommentStatement.setString(1, comment);
        updateStateAndCommentStatement.setLong(2, id);
        int updateResult = updateStateAndCommentStatement.executeUpdate();
        if (updateResult <= 0) {
            LOG.warn("Unable to move state to ERROR for execution in queue " + id + " (update result: " + updateResult + ")");
            throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
        }
    } catch (SQLException e) {
        LOG.warn("Unable to set move to ERROR for execution in queue id " + id, e);
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 8 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseExecutionSysVerDAO method insertTestCaseExecutionSysVer.

@Override
public void insertTestCaseExecutionSysVer(TestCaseExecutionSysVer testCaseExecutionSysVer) throws CerberusException {
    final String query = "INSERT INTO testcaseexecutionsysver (id, system, build, revision) " + "VALUES (?, ?, ?, ?)";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.id : " + testCaseExecutionSysVer.getID());
        LOG.debug("SQL.param.system : " + testCaseExecutionSysVer.getSystem());
        LOG.debug("SQL.param.build : " + testCaseExecutionSysVer.getBuild());
        LOG.debug("SQL.param.revision : " + testCaseExecutionSysVer.getRevision());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setLong(1, testCaseExecutionSysVer.getID());
            preStat.setString(2, testCaseExecutionSysVer.getSystem());
            preStat.setString(3, testCaseExecutionSysVer.getBuild());
            preStat.setString(4, testCaseExecutionSysVer.getRevision());
            preStat.executeUpdate();
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
            throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 9 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseStepActionControlDAO method insertTestCaseStepActionControl.

@Override
public void insertTestCaseStepActionControl(TestCaseStepActionControl testCaseStepActionControl) throws CerberusException {
    boolean throwExcep = false;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO testcasestepactioncontrol (`test`, `testCase`, `step`, `sequence`, `controlSequence`, `sort`, `conditionOper`, `conditionVal1`, `conditionVal2`, `control`, `value1`, `value2`, `fatal`, `Description`, `screenshotfilename`) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        preStat.setString(1, testCaseStepActionControl.getTest());
        preStat.setString(2, testCaseStepActionControl.getTestCase());
        preStat.setInt(3, testCaseStepActionControl.getStep());
        preStat.setInt(4, testCaseStepActionControl.getSequence());
        preStat.setInt(5, testCaseStepActionControl.getControlSequence());
        preStat.setInt(6, testCaseStepActionControl.getSort());
        preStat.setString(7, testCaseStepActionControl.getConditionOper());
        preStat.setString(8, testCaseStepActionControl.getConditionVal1());
        preStat.setString(9, testCaseStepActionControl.getConditionVal2());
        preStat.setString(10, testCaseStepActionControl.getControl());
        preStat.setString(11, testCaseStepActionControl.getValue1());
        preStat.setString(12, testCaseStepActionControl.getValue2());
        preStat.setString(13, testCaseStepActionControl.getFatal());
        preStat.setString(14, testCaseStepActionControl.getDescription());
        preStat.setString(15, testCaseStepActionControl.getScreenshotFilename());
        throwExcep = preStat.executeUpdate() == 0;
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 10 with CerberusException

use of org.cerberus.exception.CerberusException in project cerberus-source by cerberustesting.

the class TestCaseStepActionControlDAO method deleteTestCaseStepActionControl.

@Override
public void deleteTestCaseStepActionControl(TestCaseStepActionControl tcsac) throws CerberusException {
    boolean throwExcep = false;
    final String query = "DELETE FROM testcasestepactioncontrol WHERE test = ? and testcase = ? and step = ? and `sequence` = ? and `controlSequence` = ?";
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, tcsac.getTest());
        preStat.setString(2, tcsac.getTestCase());
        preStat.setInt(3, tcsac.getStep());
        preStat.setInt(4, tcsac.getSequence());
        preStat.setInt(5, tcsac.getControlSequence());
        throwExcep = preStat.executeUpdate() == 0;
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    if (throwExcep) {
        throw new CerberusException(new MessageGeneral(MessageGeneralEnum.CANNOT_UPDATE_TABLE));
    }
}
Also used : CerberusException(org.cerberus.exception.CerberusException) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

CerberusException (org.cerberus.exception.CerberusException)159 MessageEvent (org.cerberus.engine.entity.MessageEvent)64 MessageGeneral (org.cerberus.engine.entity.MessageGeneral)58 ApplicationContext (org.springframework.context.ApplicationContext)58 JSONObject (org.json.JSONObject)54 JSONException (org.json.JSONException)53 Connection (java.sql.Connection)48 SQLException (java.sql.SQLException)48 PreparedStatement (java.sql.PreparedStatement)47 AnswerItem (org.cerberus.util.answer.AnswerItem)41 ArrayList (java.util.ArrayList)37 IOException (java.io.IOException)35 PolicyFactory (org.owasp.html.PolicyFactory)35 ILogEventService (org.cerberus.crud.service.ILogEventService)34 Answer (org.cerberus.util.answer.Answer)34 ServletException (javax.servlet.ServletException)26 ResultSet (java.sql.ResultSet)18 TestCase (org.cerberus.crud.entity.TestCase)16 JSONArray (org.json.JSONArray)16 HashMap (java.util.HashMap)12