Search in sources :

Example 71 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseStepActionControlExecutionDAO method readByKey.

@Override
public AnswerItem readByKey(long executionId, String test, String testCase, int step, int index, int sequence, int controlSequence) {
    MessageEvent msg;
    AnswerItem answer = new AnswerItem();
    TestCaseStepActionControlExecution tcsa = null;
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasestepactioncontrolexecution a ");
    query.append("where id = ? and test = ? and testcase = ? and step = ? and `index` = ? and controlSequence = ?");
    query.append("and sequence = ?");
    // 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, executionId);
            preStat.setString(2, test);
            preStat.setString(3, testCase);
            preStat.setInt(4, step);
            preStat.setInt(5, index);
            preStat.setInt(6, sequence);
            preStat.setInt(7, controlSequence);
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    tcsa = this.loadFromResultset(resultSet);
                }
                if (tcsa == null) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                }
            } 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 {
                if (resultSet != null) {
                    resultSet.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 {
            if (preStat != null) {
                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());
        }
    }
    answer.setItem(tcsa);
    answer.setResultMessage(msg);
    return answer;
}
Also used : IFactoryTestCaseStepActionControlExecution(org.cerberus.crud.factory.IFactoryTestCaseStepActionControlExecution) TestCaseStepActionControlExecution(org.cerberus.crud.entity.TestCaseStepActionControlExecution) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Example 72 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseStepActionDAO method create.

@Override
public Answer create(TestCaseStepAction testCaseStepAction) {
    Answer ans = new Answer();
    MessageEvent msg = null;
    StringBuilder query = new StringBuilder();
    query.append("INSERT INTO testcasestepaction (`test`, `testCase`, `step`, `sequence`, `sort`, `conditionOper`, `conditionVal1`, `conditionVal2`, `action`, `Value1`, `Value2`, `ForceExeStatus`, `description`, `screenshotfilename`) ");
    query.append("VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
    try (Connection connection = databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString())) {
        // Prepare and execute query
        preStat.setString(1, testCaseStepAction.getTest());
        preStat.setString(2, testCaseStepAction.getTestCase());
        preStat.setInt(3, testCaseStepAction.getStep());
        preStat.setInt(4, testCaseStepAction.getSequence());
        preStat.setInt(5, testCaseStepAction.getSort());
        preStat.setString(6, testCaseStepAction.getConditionOper());
        preStat.setString(7, testCaseStepAction.getConditionVal1());
        preStat.setString(8, testCaseStepAction.getConditionVal2());
        preStat.setString(9, testCaseStepAction.getAction());
        preStat.setString(10, testCaseStepAction.getValue1());
        preStat.setString(11, testCaseStepAction.getValue2());
        preStat.setString(12, testCaseStepAction.getForceExeStatus());
        preStat.setString(13, testCaseStepAction.getDescription());
        preStat.setString(14, testCaseStepAction.getScreenshotFilename());
        preStat.executeUpdate();
        // Set the final message
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK).resolveDescription("ITEM", OBJECT_NAME).resolveDescription("OPERATION", "CREATE");
    } catch (Exception e) {
        LOG.warn("Unable to create TestCaseStepAction: " + e.getMessage());
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED).resolveDescription("DESCRIPTION", e.toString());
    } finally {
        ans.setResultMessage(msg);
    }
    return ans;
}
Also used : Answer(org.cerberus.util.answer.Answer) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement) CerberusException(org.cerberus.exception.CerberusException) SQLException(java.sql.SQLException)

Example 73 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseStepActionDAO method readByVarious1.

@Override
public AnswerList readByVarious1(String test, String testcase, int step) {
    AnswerList response = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    List<TestCaseStepAction> actionList = new ArrayList<TestCaseStepAction>();
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasestepaction tca WHERE tca.test = ? AND tca.testcase = ? AND tca.step = ?");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            preStat.setInt(3, step);
            ResultSet resultSet = preStat.executeQuery();
            try {
                // gets the data
                while (resultSet.next()) {
                    actionList.add(this.loadFromResultSet(resultSet));
                }
                // get the total number of rows
                resultSet = preStat.executeQuery("SELECT FOUND_ROWS()");
                int nrTotalRows = 0;
                if (resultSet != null && resultSet.next()) {
                    nrTotalRows = resultSet.getInt(1);
                }
                if (actionList.size() >= MAX_ROW_SELECTED) {
                    // Result of SQl was limited by MAX_ROW_SELECTED constrain. That means that we may miss some lines in the resultList.
                    LOG.error("Partial Result in the query.");
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT);
                    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", "Maximum row reached : " + MAX_ROW_SELECTED));
                    response = new AnswerList(actionList, actionList.size());
                } else if (actionList.size() <= 0) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                    response = new AnswerList(actionList, actionList.size());
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                    msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                    response = new AnswerList(actionList, actionList.size());
                }
            } 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%", "Unable to retrieve the list of entries!"));
            } finally {
                if (resultSet != null) {
                    resultSet.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%", "Unable to retrieve the list of entries!"));
        } finally {
            if (preStat != null) {
                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%", "Unable to retrieve the list of entries!"));
    } finally {
        try {
            if (!this.databaseSpring.isOnTransaction()) {
                if (connection != null) {
                    connection.close();
                }
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to close connection : " + exception.toString());
        }
    }
    response.setResultMessage(msg);
    return response;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 74 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseStepActionExecutionDAO method readByVarious1.

@Override
public AnswerList readByVarious1(long executionId, String test, String testCase, int step, int index) {
    MessageEvent msg;
    AnswerList answer = new AnswerList();
    List<TestCaseStepActionExecution> list = new ArrayList<TestCaseStepActionExecution>();
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasestepactionexecution exa ");
    query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? ");
    // 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, executionId);
            preStat.setString(2, test);
            preStat.setString(3, testCase);
            preStat.setInt(4, step);
            preStat.setInt(5, index);
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    list.add(this.loadFromResultset(resultSet));
                }
                if (list.isEmpty()) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                }
            } 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()));
                list.clear();
            } finally {
                if (resultSet != null) {
                    resultSet.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 {
            if (preStat != null) {
                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());
        }
    }
    answer.setTotalRows(list.size());
    answer.setDataList(list);
    answer.setResultMessage(msg);
    return answer;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IFactoryTestCaseStepActionExecution(org.cerberus.crud.factory.IFactoryTestCaseStepActionExecution) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) PreparedStatement(java.sql.PreparedStatement)

Example 75 with MessageEvent

use of org.cerberus.engine.entity.MessageEvent in project cerberus-source by cerberustesting.

the class TestCaseStepActionExecutionDAO method readByKey.

@Override
public AnswerItem readByKey(long executionId, String test, String testCase, int step, int index, int sequence) {
    MessageEvent msg;
    AnswerItem answer = new AnswerItem();
    TestCaseStepActionExecution tcsa = null;
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasestepactionexecution exa ");
    query.append("where exa.id = ? and exa.test = ? and exa.testcase = ? and exa.step = ? and exa.index = ? and exa.sequence = .");
    // 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, executionId);
            preStat.setString(2, test);
            preStat.setString(3, testCase);
            preStat.setInt(4, step);
            preStat.setInt(5, index);
            preStat.setInt(6, sequence);
            ResultSet resultSet = preStat.executeQuery();
            try {
                while (resultSet.next()) {
                    tcsa = this.loadFromResultset(resultSet);
                }
                if (tcsa == null) {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                } else {
                    msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                }
            } 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 {
                if (resultSet != null) {
                    resultSet.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 {
            if (preStat != null) {
                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());
        }
    }
    answer.setItem(tcsa);
    answer.setResultMessage(msg);
    return answer;
}
Also used : SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) IFactoryTestCaseStepActionExecution(org.cerberus.crud.factory.IFactoryTestCaseStepActionExecution) TestCaseStepActionExecution(org.cerberus.crud.entity.TestCaseStepActionExecution) PreparedStatement(java.sql.PreparedStatement) AnswerItem(org.cerberus.util.answer.AnswerItem)

Aggregations

MessageEvent (org.cerberus.engine.entity.MessageEvent)629 SQLException (java.sql.SQLException)306 Connection (java.sql.Connection)304 PreparedStatement (java.sql.PreparedStatement)301 Answer (org.cerberus.util.answer.Answer)227 AnswerItem (org.cerberus.util.answer.AnswerItem)212 ArrayList (java.util.ArrayList)180 ResultSet (java.sql.ResultSet)172 AnswerList (org.cerberus.util.answer.AnswerList)152 JSONObject (org.json.JSONObject)144 ApplicationContext (org.springframework.context.ApplicationContext)122 CerberusException (org.cerberus.exception.CerberusException)95 PolicyFactory (org.owasp.html.PolicyFactory)93 List (java.util.List)83 ILogEventService (org.cerberus.crud.service.ILogEventService)79 JSONException (org.json.JSONException)79 Map (java.util.Map)71 CerberusEventException (org.cerberus.exception.CerberusEventException)51 IOException (java.io.IOException)48 WebDriverException (org.openqa.selenium.WebDriverException)38