Search in sources :

Example 21 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseDAO method create.

@Override
public Answer create(TestCase testCase) {
    MessageEvent msg = null;
    final StringBuffer sql = new StringBuffer("INSERT INTO `testcase` ").append(" ( `Test`, `TestCase`, `Application`, `Project`, `Ticket`, ").append("`Description`, `BehaviorOrValueExpected`, ").append("`Priority`, `Status`, `TcActive`, ").append("`Group`, `Origine`, `RefOrigine`, `HowTo`, `Comment`, ").append("`FromBuild`, `FromRev`, `ToBuild`, `ToRev`, ").append("`BugID`, `TargetBuild`, `TargetRev`, `UsrCreated`, ").append("`Implementer`, `function`, `activeQA`, `activeUAT`, `activePROD`, `useragent`, `screenSize`, `conditionOper`, `conditionVal1`, `conditionVal2`, `testCaseVersion`) ").append("VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ").append("?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ? ); ");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + sql.toString());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(sql.toString());
        try {
            int i = 1;
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTest(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTestCase(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getApplication(), ""));
            preStat.setString(i++, testCase.getProject());
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTicket(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getDescription(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBehaviorOrValueExpected(), ""));
            preStat.setString(i++, Integer.toString(testCase.getPriority()));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getStatus(), ""));
            preStat.setString(i++, testCase.getTcActive() != null && !testCase.getTcActive().equals("Y") ? "N" : "Y");
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getGroup(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getOrigine(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getRefOrigine(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getHowTo(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getComment(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromBuild(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFromRev(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToBuild(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getToRev(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getBugID(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetBuild(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getTargetRev(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUsrCreated(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getImplementer(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getFunction(), ""));
            preStat.setString(i++, testCase.getActiveQA() != null && !testCase.getActiveQA().equals("Y") ? "N" : "Y");
            preStat.setString(i++, testCase.getActiveUAT() != null && !testCase.getActiveUAT().equals("Y") ? "N" : "Y");
            preStat.setString(i++, testCase.getActivePROD() != null && !testCase.getActivePROD().equals("N") ? "Y" : "N");
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getUserAgent(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getScreenSize(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionOper(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal1(), ""));
            preStat.setString(i++, ParameterParserUtil.parseStringParam(testCase.getConditionVal2(), ""));
            preStat.setInt(i++, ParameterParserUtil.parseIntegerParam(testCase.getTestCaseVersion(), 0));
            preStat.executeUpdate();
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString(), exception);
            if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
                // 23000 is the sql state for duplicate entries
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
            }
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}
Also used : Answer(org.cerberus.util.answer.Answer) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 22 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseExecutionFileDAO method create.

@Override
public Answer create(TestCaseExecutionFile object) {
    MessageEvent msg = null;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO testcaseexecutionfile (`exeid`, `level`, `fileDesc`, `fileName`, `fileType`, `usrcreated`) ");
    query.append("VALUES (?,?,?,?,?,?)");
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query.toString());
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setLong(1, object.getExeId());
            preStat.setString(2, object.getLevel());
            preStat.setString(3, object.getFileDesc());
            preStat.setString(4, object.getFileName());
            preStat.setString(5, object.getFileType());
            preStat.setString(6, object.getUsrCreated());
            preStat.executeUpdate();
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT"));
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            if (exception.getSQLState().equals(SQL_DUPLICATED_CODE)) {
                // 23000 is the sql state for duplicate entries
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_DUPLICATE);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "INSERT").replace("%REASON%", exception.toString()));
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
                msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
            }
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.error("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}
Also used : Answer(org.cerberus.util.answer.Answer) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 23 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseExecutionFileDAO method update.

@Override
public Answer update(TestCaseExecutionFile object) {
    MessageEvent msg = null;
    final String query = "UPDATE testcaseexecutionfile SET exeid = ?, level = ?, `filedesc` = ?, `filename` = ?, filetype = ?, usrmodif = ?, datemodif = ?  WHERE id = ?";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setLong(1, object.getExeId());
            preStat.setString(2, object.getLevel());
            preStat.setString(3, object.getFileDesc());
            preStat.setString(4, object.getFileName());
            preStat.setString(5, object.getFileType());
            preStat.setString(6, object.getUsrModif());
            preStat.setTimestamp(7, object.getDateModif());
            preStat.setLong(8, object.getId());
            preStat.executeUpdate();
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
            msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}
Also used : Answer(org.cerberus.util.answer.Answer) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 24 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseExecutionQueueDAO method updateToCancelled.

@Override
public Answer updateToCancelled(long id, String comment) {
    MessageEvent msg = null;
    String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'CANCELLED', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` IN ('ERROR','QUEUED')";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
        LOG.debug("SQL.param.id : " + id);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            int i = 1;
            preStat.setString(i++, comment);
            preStat.setLong(i++, id);
            int updateResult = preStat.executeUpdate();
            if (updateResult <= 0) {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_NOUPDATE);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%DESCRIPTION%", "Unable to move state to CANCELLED for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in ERROR or QUEUED ?"));
                LOG.warn("Unable to move state to CANCELLED for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in ERROR or QUEUED ?");
            // throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}
Also used : Answer(org.cerberus.util.answer.Answer) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 25 with Answer

use of org.cerberus.util.answer.Answer in project cerberus-source by cerberustesting.

the class TestCaseExecutionQueueDAO method updateToCancelledForce.

@Override
public Answer updateToCancelledForce(long id, String comment) {
    MessageEvent msg = null;
    String query = "UPDATE `" + TABLE + "` " + "SET `" + COLUMN_STATE + "` = 'CANCELLED', `" + COLUMN_REQUEST_DATE + "` = now(), `" + COLUMN_DATEMODIF + "` = now(), `" + COLUMN_COMMENT + "` = ? " + "WHERE `" + COLUMN_ID + "` = ? " + "AND `" + COLUMN_STATE + "` IN ('WAITING','STARTING','EXECUTING')";
    // Debug message on SQL.
    if (LOG.isDebugEnabled()) {
        LOG.debug("SQL : " + query);
    }
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            int i = 1;
            preStat.setString(i++, comment);
            preStat.setLong(i++, id);
            int updateResult = preStat.executeUpdate();
            if (updateResult <= 0) {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_NOUPDATE);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%DESCRIPTION%", "Unable to move state to CANCELLED (forced) for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in WAITING or STARTING or EXECUTING ?"));
                LOG.warn("Unable to move state to CANCELLED (forced) for execution in queue " + id + " (update result: " + updateResult + "). Maybe execution is no longuer in WAITING or STARTING or EXECUTING ?");
            // throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "UPDATE"));
            }
        } catch (SQLException exception) {
            LOG.error("Unable to execute query : " + exception.toString());
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
            msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
        } finally {
            preStat.close();
        }
    } catch (SQLException exception) {
        LOG.error("Unable to execute query : " + exception.toString());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
        msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", exception.toString()));
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    return new Answer(msg);
}
Also used : Answer(org.cerberus.util.answer.Answer) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Aggregations

Answer (org.cerberus.util.answer.Answer)241 MessageEvent (org.cerberus.engine.entity.MessageEvent)227 Connection (java.sql.Connection)127 PreparedStatement (java.sql.PreparedStatement)127 SQLException (java.sql.SQLException)127 ApplicationContext (org.springframework.context.ApplicationContext)77 JSONObject (org.json.JSONObject)75 ILogEventService (org.cerberus.crud.service.ILogEventService)74 PolicyFactory (org.owasp.html.PolicyFactory)60 AnswerItem (org.cerberus.util.answer.AnswerItem)53 CerberusException (org.cerberus.exception.CerberusException)45 ArrayList (java.util.ArrayList)35 JSONException (org.json.JSONException)26 IOException (java.io.IOException)23 ServletException (javax.servlet.ServletException)19 JSONArray (org.json.JSONArray)15 LogEventService (org.cerberus.crud.service.impl.LogEventService)13 TestCase (org.cerberus.crud.entity.TestCase)10 ITestCaseService (org.cerberus.crud.service.ITestCaseService)10 CountryEnvParam (org.cerberus.crud.entity.CountryEnvParam)8