Search in sources :

Example 26 with TestCaseStepAction

use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.

the class TestCaseStepActionDAO method readByTestTestCase.

@Override
public AnswerList readByTestTestCase(String test, String testcase) {
    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 = ?");
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            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 27 with TestCaseStepAction

use of org.cerberus.crud.entity.TestCaseStepAction in project cerberus-source by cerberustesting.

the class LoadTestCaseService method loadTestCaseStepAction.

public List<TestCaseStepAction> loadTestCaseStepAction(TestCaseStep testCaseStep, TestCaseStep UsedTestCaseStep) {
    List<TestCaseStepAction> result = new ArrayList<TestCaseStepAction>();
    List<TestCaseStepAction> tcsaToAdd;
    /**
     * If use Step, take the List of action and control of the used step
     */
    boolean useStep = (UsedTestCaseStep != null);
    if (!useStep) {
        tcsaToAdd = this.testCaseStepActionService.getListOfAction(testCaseStep.getTest(), testCaseStep.getTestCase(), testCaseStep.getStep());
    } else {
        tcsaToAdd = this.testCaseStepActionService.getListOfAction(UsedTestCaseStep.getTest(), UsedTestCaseStep.getTestCase(), UsedTestCaseStep.getStep());
    }
    /**
     * Iterate on the list of action to get the control
     * In case of useStep, print the test,testcase,step of the executed test instead of the used step
     */
    for (TestCaseStepAction testCaseStepAction : tcsaToAdd) {
        LOG.debug("set list of action :" + testCaseStepAction.getAction());
        /**
         */
        List<TestCaseStepActionControl> tcsacList = this.loadTestCaseStepActionControl(testCaseStep, testCaseStepAction);
        if (tcsacList != null) {
            testCaseStepAction.setTestCaseStepActionControl(tcsacList);
        }
        /**
         * Update the test, Testcase, Step in case of useStep
         */
        testCaseStepAction.setTest(testCaseStep.getTest());
        testCaseStepAction.setTestCase(testCaseStep.getTestCase());
        testCaseStepAction.setStep(testCaseStep.getStep());
        LOG.debug("adding testCaseStepAction" + testCaseStepAction.getAction());
        result.add(testCaseStepAction);
        LOG.debug("added testCaseStepAction" + testCaseStepAction.getAction());
    }
    LOG.debug("return List<TestCaseStepAction>");
    return result;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) ArrayList(java.util.ArrayList) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl)

Aggregations

TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)27 ArrayList (java.util.ArrayList)19 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)13 TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)12 IFactoryTestCaseStepAction (org.cerberus.crud.factory.IFactoryTestCaseStepAction)12 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)9 ITestCaseStepActionService (org.cerberus.crud.service.ITestCaseStepActionService)9 ITestCaseStepService (org.cerberus.crud.service.ITestCaseStepService)9 TestCase (org.cerberus.crud.entity.TestCase)8 ITestCaseStepActionControlService (org.cerberus.crud.service.ITestCaseStepActionControlService)8 JSONObject (org.json.JSONObject)8 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)7 ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)7 ITestCaseService (org.cerberus.crud.service.ITestCaseService)7 MessageEvent (org.cerberus.engine.entity.MessageEvent)7 JSONArray (org.json.JSONArray)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 SQLException (java.sql.SQLException)6 ITestCaseCountryService (org.cerberus.crud.service.ITestCaseCountryService)6