Search in sources :

Example 21 with TestCaseStepActionControl

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

the class TestCaseStepActionControlDAO method findTestCaseStepActionControlByKey.

@Override
public TestCaseStepActionControl findTestCaseStepActionControlByKey(String test, String testcase, int stepNumber, int sequence, int controlSequence) {
    TestCaseStepActionControl actionControl = null;
    final String query = "SELECT * FROM testcasestepactioncontrol WHERE test = ? AND testcase = ? AND step = ? AND sequence = ? AND control = ?";
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query)) {
        preStat.setString(1, test);
        preStat.setString(2, testcase);
        preStat.setInt(3, stepNumber);
        preStat.setInt(4, sequence);
        preStat.setInt(5, controlSequence);
        try (ResultSet resultSet = preStat.executeQuery()) {
            if (resultSet.first()) {
                int sort = resultSet.getInt("Sort");
                String conditionOper = resultSet.getString("conditionOper");
                String conditionVal1 = resultSet.getString("conditionVal1");
                String conditionVal2 = resultSet.getString("conditionVal2");
                String control = resultSet.getString("Control");
                String value1 = resultSet.getString("Value1");
                String value2 = resultSet.getString("Value2");
                String fatal = resultSet.getString("Fatal");
                String description = resultSet.getString("Description");
                String screenshotFilename = resultSet.getString("screenshotFilename");
                actionControl = factoryTestCaseStepActionControl.create(test, testcase, stepNumber, sequence, controlSequence, sort, conditionOper, conditionVal1, conditionVal2, control, value1, value2, fatal, description, screenshotFilename);
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    }
    return actionControl;
}
Also used : SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) PreparedStatement(java.sql.PreparedStatement)

Example 22 with TestCaseStepActionControl

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

the class TestCaseStepActionControlDAO 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<TestCaseStepActionControl> controlList = new ArrayList<TestCaseStepActionControl>();
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasestepactioncontrol WHERE test = ? AND testcase = ?");
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        Statement stm = connection.createStatement()) {
        preStat.setString(1, test);
        preStat.setString(2, testcase);
        try (ResultSet resultSet = preStat.executeQuery();
            ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
            // gets the data
            while (resultSet.next()) {
                controlList.add(this.loadFromResultSet(resultSet));
            }
            // get the total number of rows
            int nrTotalRows = 0;
            if (rowSet != null && rowSet.next()) {
                nrTotalRows = rowSet.getInt(1);
            }
            if (controlList.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(controlList, controlList.size());
            } else if (controlList.size() <= 0) {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                response = new AnswerList(controlList, controlList.size());
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                response = new AnswerList(controlList, controlList.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!"));
        }
    } 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!"));
    }
    response.setResultMessage(msg);
    return response;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) PreparedStatement(java.sql.PreparedStatement)

Example 23 with TestCaseStepActionControl

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

the class TestCaseStepActionControlDAO method readByVarious1.

@Override
public AnswerList readByVarious1(String test, String testcase, int step, int sequence) {
    AnswerList response = new AnswerList();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    List<TestCaseStepActionControl> controlList = new ArrayList<TestCaseStepActionControl>();
    StringBuilder query = new StringBuilder();
    query.append("SELECT * FROM testcasestepactioncontrol WHERE test = ? AND testcase = ? AND step = ? AND sequence = ?");
    try (Connection connection = this.databaseSpring.connect();
        PreparedStatement preStat = connection.prepareStatement(query.toString());
        Statement stm = connection.createStatement()) {
        preStat.setString(1, test);
        preStat.setString(2, testcase);
        preStat.setInt(3, step);
        preStat.setInt(4, sequence);
        try (ResultSet resultSet = preStat.executeQuery();
            ResultSet rowSet = stm.executeQuery("SELECT FOUND_ROWS()")) {
            // gets the data
            while (resultSet.next()) {
                controlList.add(this.loadFromResultSet(resultSet));
            }
            // get the total number of rows
            int nrTotalRows = 0;
            if (rowSet != null && rowSet.next()) {
                nrTotalRows = rowSet.getInt(1);
            }
            if (controlList.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(controlList, controlList.size());
            } else if (controlList.size() <= 0) {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);
                response = new AnswerList(controlList, controlList.size());
            } else {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME).replace("%OPERATION%", "SELECT"));
                response = new AnswerList(controlList, controlList.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!"));
        }
    } 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!"));
    }
    response.setResultMessage(msg);
    return response;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) SQLException(java.sql.SQLException) MessageEvent(org.cerberus.engine.entity.MessageEvent) PreparedStatement(java.sql.PreparedStatement) Statement(java.sql.Statement) ArrayList(java.util.ArrayList) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) PreparedStatement(java.sql.PreparedStatement)

Example 24 with TestCaseStepActionControl

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

the class TestCaseStepActionControlService method duplicateList.

@Override
public Answer duplicateList(List<TestCaseStepActionControl> objectList, String targetTest, String targetTestCase) {
    Answer ans = new Answer(null);
    List<TestCaseStepActionControl> listToCreate = new ArrayList();
    for (TestCaseStepActionControl objectToDuplicate : objectList) {
        objectToDuplicate.setTest(targetTest);
        objectToDuplicate.setTestCase(targetTestCase);
        listToCreate.add(objectToDuplicate);
    }
    ans = createList(listToCreate);
    return ans;
}
Also used : Answer(org.cerberus.util.answer.Answer) ArrayList(java.util.ArrayList) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl)

Example 25 with TestCaseStepActionControl

use of org.cerberus.crud.entity.TestCaseStepActionControl 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

TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)25 ArrayList (java.util.ArrayList)16 TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)12 IFactoryTestCaseStepActionControl (org.cerberus.crud.factory.IFactoryTestCaseStepActionControl)12 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)11 TestCase (org.cerberus.crud.entity.TestCase)8 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)8 ITestCaseStepActionControlService (org.cerberus.crud.service.ITestCaseStepActionControlService)8 ITestCaseStepActionService (org.cerberus.crud.service.ITestCaseStepActionService)8 ITestCaseStepService (org.cerberus.crud.service.ITestCaseStepService)8 JSONObject (org.json.JSONObject)8 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)7 ITestCaseService (org.cerberus.crud.service.ITestCaseService)7 Connection (java.sql.Connection)6 PreparedStatement (java.sql.PreparedStatement)6 ResultSet (java.sql.ResultSet)6 SQLException (java.sql.SQLException)6 ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)6 MessageEvent (org.cerberus.engine.entity.MessageEvent)6 JSONArray (org.json.JSONArray)6