Search in sources :

Example 1 with TestCaseStepAction

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

the class TestCaseStepActionDAO method findTestCaseStepActionbyTestTestCase.

@Override
public List<TestCaseStepAction> findTestCaseStepActionbyTestTestCase(String test, String testCase) throws CerberusException {
    List<TestCaseStepAction> list = null;
    final StringBuilder query = new StringBuilder();
    query.append("SELECT tca.* ");
    query.append("FROM testcasestepaction AS tca ");
    query.append("RIGHT JOIN testcasestep AS tcs ON tca.Test = tcs.Test AND tca.TestCase = tcs.TestCase AND tca.Step = tcs.Step ");
    query.append("WHERE tca.Test = ? AND tca.TestCase = ? ");
    query.append("GROUP BY tca.Test, tca.TestCase, tca.Step, tca.Sequence ");
    query.append("ORDER BY tcs.Sort, tca.Sort ");
    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 {
                list = new ArrayList<TestCaseStepAction>();
                while (resultSet.next()) {
                    list.add(this.loadFromResultSet(resultSet));
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return list;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 2 with TestCaseStepAction

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

the class TestCaseStepActionDAO method findActionByTestTestCaseStep.

@Override
public List<TestCaseStepAction> findActionByTestTestCaseStep(String test, String testcase, int stepNumber) {
    List<TestCaseStepAction> list = null;
    final String query = "SELECT * FROM testcasestepaction tca WHERE tca.test = ? AND tca.testcase = ? AND tca.step = ? ORDER BY tca.sort";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setString(1, test);
            preStat.setString(2, testcase);
            preStat.setInt(3, stepNumber);
            ResultSet resultSet = preStat.executeQuery();
            try {
                list = new ArrayList<TestCaseStepAction>();
                while (resultSet.next()) {
                    list.add(this.loadFromResultSet(resultSet));
                }
            } catch (SQLException exception) {
                LOG.warn("Unable to execute query : " + exception.toString());
            } finally {
                if (resultSet != null) {
                    resultSet.close();
                }
            }
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return list;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 3 with TestCaseStepAction

use of org.cerberus.crud.entity.TestCaseStepAction 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 4 with TestCaseStepAction

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

the class TestCaseStepActionDAO method changeTestCaseStepActionSequence.

@Override
public boolean changeTestCaseStepActionSequence(String test, String testCase, int step, int oldSequence, int newSequence) {
    TestCaseStepAction testCaseStepAction = null;
    final String query = "update testcasestepaction set sequence = ? WHERE test = ? AND testcase = ? AND step = ? AND sequence = ?";
    Connection connection = this.databaseSpring.connect();
    try {
        PreparedStatement preStat = connection.prepareStatement(query);
        try {
            preStat.setInt(1, newSequence);
            preStat.setString(2, test);
            preStat.setString(3, testCase);
            preStat.setInt(4, step);
            preStat.setInt(5, oldSequence);
            int lines = preStat.executeUpdate();
            return (lines > 0);
        } catch (SQLException exception) {
            LOG.warn("Unable to execute query : " + exception.toString());
        } finally {
            if (preStat != null) {
                preStat.close();
            }
        }
    } catch (SQLException exception) {
        LOG.warn("Unable to execute query : " + exception.toString());
    } finally {
        try {
            if (connection != null) {
                connection.close();
            }
        } catch (SQLException e) {
            LOG.warn(e.toString());
        }
    }
    return false;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) SQLException(java.sql.SQLException) Connection(java.sql.Connection) PreparedStatement(java.sql.PreparedStatement)

Example 5 with TestCaseStepAction

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

the class LoadTestCaseService method loadTestCaseStep.

@Override
public List<TestCaseStep> loadTestCaseStep(TestCase testCase) {
    List<TestCaseStep> result = new ArrayList<TestCaseStep>();
    for (TestCaseStep testCaseStep : this.testCaseStepService.getListOfSteps(testCase.getTest(), testCase.getTestCase())) {
        LOG.debug("set list of step :" + testCaseStep.getStep());
        /**
         * If use Step, load action and control of used step
         */
        if (!testCaseStep.getUseStep().equals("Y")) {
            List<TestCaseStepAction> tcsa = this.loadTestCaseStepAction(testCaseStep, null);
            if (tcsa != null) {
                testCaseStep.setTestCaseStepAction(tcsa);
            }
        } else {
            // Step is used from another testcase.
            List<TestCaseStepAction> tcsa = this.loadTestCaseStepAction(testCaseStep, factoryTCS.create(testCaseStep.getUseStepTest(), testCaseStep.getUseStepTestCase(), testCaseStep.getUseStepStep(), testCaseStep.getSort(), null, null, null, null, null, null, null, null, 0, null));
            if (tcsa != null) {
                testCaseStep.setTestCaseStepAction(tcsa);
            }
            // Copy the usedStep property to main step. Loop and conditionoper are taken from used step.
            testCaseStep = testCaseStepService.modifyTestCaseStepDataFromUsedStep(testCaseStep);
        }
        LOG.debug("adding testCaseStep");
        result.add(testCaseStep);
    }
    LOG.debug("return List<TestCaseStep>");
    return result;
}
Also used : TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) ArrayList(java.util.ArrayList) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

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