Search in sources :

Example 16 with TestCaseStepActionControl

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

the class UpdateTestCaseWithDependencies1 method getTestCaseStepActionControlFromParameter.

private List<TestCaseStepActionControl> getTestCaseStepActionControlFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, JSONArray controlArray) throws JSONException {
    List<TestCaseStepActionControl> testCaseStepActionControl = new ArrayList();
    IFactoryTestCaseStepActionControl testCaseStepActionControlFactory = appContext.getBean(IFactoryTestCaseStepActionControl.class);
    for (int i = 0; i < controlArray.length(); i++) {
        JSONObject controlJson = controlArray.getJSONObject(i);
        boolean delete = controlJson.getBoolean("toDelete");
        int step = controlJson.isNull("step") ? -1 : controlJson.getInt("step");
        int sequence = controlJson.isNull("sequence") ? -1 : controlJson.getInt("sequence");
        int control = controlJson.isNull("controlSequence") ? -1 : controlJson.getInt("controlSequence");
        int sort = controlJson.isNull("sort") ? -1 : controlJson.getInt("sort");
        String conditionOper = controlJson.isNull("conditionOper") ? "always" : controlJson.getString("conditionOper");
        String conditionVal1 = controlJson.isNull("conditionVal1") ? "" : controlJson.getString("conditionVal1");
        String conditionVal2 = controlJson.isNull("conditionVal2") ? "" : controlJson.getString("conditionVal2");
        String type = controlJson.getString("objType");
        String controlValue = controlJson.getString("control");
        String value1 = controlJson.getString("value1");
        String value2 = controlJson.getString("value2");
        String fatal = controlJson.getString("fatal");
        String description = controlJson.getString("description");
        String screenshot = controlJson.getString("screenshotFileName");
        if (!delete) {
            testCaseStepActionControl.add(testCaseStepActionControlFactory.create(test, testCase, step, sequence, control, sort, conditionOper, conditionVal1, conditionVal2, controlValue, value1, value2, fatal, description, screenshot));
        }
    }
    return testCaseStepActionControl;
}
Also used : IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl) JSONObject(org.json.JSONObject) ArrayList(java.util.ArrayList) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl)

Example 17 with TestCaseStepActionControl

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

the class UpdateTestCaseWithDependencies1 method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 * @throws org.cerberus.exception.CerberusException
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
    JSONObject jsonResponse = new JSONObject();
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    response.setContentType("application/json");
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    /**
     * Parsing and securing all required parameters.
     */
    StringBuilder sb = new StringBuilder();
    BufferedReader br = request.getReader();
    String str;
    while ((str = br.readLine()) != null) {
        sb.append(str);
    }
    JSONObject jObj = new JSONObject(sb.toString());
    String initialTest = jObj.getString("informationInitialTest");
    String initialTestCase = jObj.getString("informationInitialTestCase");
    String test = jObj.getString("informationTest");
    String testCase = jObj.getString("informationTestCase");
    JSONArray properties = jObj.getJSONArray("propArr");
    JSONArray stepArray = jObj.getJSONArray("stepArray");
    boolean duplicate = false;
    /**
     * Checking all constrains before calling the services.
     */
    if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testCase)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Update").replace("%REASON%", "mendatory fields are missing."));
        ans.setResultMessage(msg);
    } else {
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
        ITestCaseCountryPropertiesService tccpService = appContext.getBean(ITestCaseCountryPropertiesService.class);
        ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);
        ITestCaseStepActionService tcsaService = appContext.getBean(ITestCaseStepActionService.class);
        ITestCaseStepActionControlService tcsacService = appContext.getBean(ITestCaseStepActionControlService.class);
        AnswerItem resp = testCaseService.readByKey(test, testCase);
        TestCase tc = (TestCase) resp.getItem();
        if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {
            /**
             * Object could not be found. We stop here and report the error.
             */
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Update").replace("%REASON%", "TestCase does not exist."));
            ans.setResultMessage(msg);
        } else /**
         * The service was able to perform the query and confirm the object
         * exist, then we can update it.
         */
        if (!testCaseService.hasPermissionsUpdate(tc, request)) {
            // We cannot update the testcase if the user is not at least in Test role.
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Update").replace("%REASON%", "Not enought privilege to update the testcase. You mut belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));
            ans.setResultMessage(msg);
        } else {
            // Test Case exist and we can update it so Global update start here //
            /**
             * TestcaseCountryProperties Update.
             */
            List<TestCaseCountryProperties> tccpFromPage = getTestCaseCountryPropertiesFromParameter(request, appContext, test, testCase, properties);
            tccpService.compareListAndUpdateInsertDeleteElements(initialTest, initialTestCase, tccpFromPage);
            /*
                 * Get steps, actions and controls from page by:
                 * - generating a new step, action or control number,
                 * - setting the correct related step and action for action or control
                 */
            List<TestCaseStep> tcsFromPage = getTestCaseStepFromParameter(request, appContext, test, testCase, duplicate, stepArray);
            List<TestCaseStepAction> tcsaFromPage = new ArrayList();
            List<TestCaseStepActionControl> tcsacFromPage = new ArrayList();
            int nextStepNumber = getMaxStepNumber(tcsFromPage);
            for (TestCaseStep tcs : tcsFromPage) {
                if (tcs.getStep() == -1) {
                    tcs.setStep(++nextStepNumber);
                }
                if (tcs.getTestCaseStepAction() != null) {
                    int nextSequenceNumber = getMaxSequenceNumber(tcs.getTestCaseStepAction());
                    for (TestCaseStepAction tcsa : tcs.getTestCaseStepAction()) {
                        if (tcsa.getSequence() == -1) {
                            tcsa.setSequence(++nextSequenceNumber);
                        }
                        tcsa.setStep(tcs.getStep());
                        if (tcsa.getTestCaseStepActionControl() != null) {
                            int nextControlNumber = getMaxControlNumber(tcsa.getTestCaseStepActionControl());
                            for (TestCaseStepActionControl tscac : tcsa.getTestCaseStepActionControl()) {
                                if (tscac.getControlSequence() == -1) {
                                    tscac.setControlSequence(++nextControlNumber);
                                }
                                tscac.setStep(tcs.getStep());
                                tscac.setSequence(tcsa.getSequence());
                            }
                            tcsacFromPage.addAll(tcsa.getTestCaseStepActionControl());
                        }
                    }
                    tcsaFromPage.addAll(tcs.getTestCaseStepAction());
                }
            }
            /*
                 * Create, update or delete step, action and control according to the needs
                 */
            List<TestCaseStep> tcsFromDtb = new ArrayList(tcsService.getListOfSteps(initialTest, initialTestCase));
            tcsService.compareListAndUpdateInsertDeleteElements(tcsFromPage, tcsFromDtb, duplicate);
            List<TestCaseStepAction> tcsaFromDtb = new ArrayList(tcsaService.findTestCaseStepActionbyTestTestCase(initialTest, initialTestCase));
            tcsaService.compareListAndUpdateInsertDeleteElements(tcsaFromPage, tcsaFromDtb, duplicate);
            List<TestCaseStepActionControl> tcsacFromDtb = new ArrayList(tcsacService.findControlByTestTestCase(initialTest, initialTestCase));
            tcsacService.compareListAndUpdateInsertDeleteElements(tcsacFromPage, tcsacFromDtb, duplicate);
            tc.setTestCaseVersion(tc.getTestCaseVersion() + 1);
            testCaseService.updateTestCase(tc);
            /**
             * Adding Log entry.
             */
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                /**
                 * Update was successful. Adding Log entry.
                 */
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/UpdateTestCaseWithDependencies1", "UPDATE", "Update testcase : ['" + tc.getTest() + "'|'" + tc.getTestCase() + "'] version : " + tc.getTestCaseVersion(), request);
            }
        }
    }
    /**
     * Formating and returning the json result.
     */
    jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", ans.getResultMessage().getDescription());
    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
}
Also used : ITestCaseStepActionService(org.cerberus.crud.service.ITestCaseStepActionService) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) PolicyFactory(org.owasp.html.PolicyFactory) MessageEvent(org.cerberus.engine.entity.MessageEvent) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) JSONArray(org.json.JSONArray) ArrayList(java.util.ArrayList) ILogEventService(org.cerberus.crud.service.ILogEventService) LogEventService(org.cerberus.crud.service.impl.LogEventService) ITestCaseStepActionControlService(org.cerberus.crud.service.ITestCaseStepActionControlService) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) AnswerItem(org.cerberus.util.answer.AnswerItem) Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) BufferedReader(java.io.BufferedReader) ITestCaseService(org.cerberus.crud.service.ITestCaseService) ILogEventService(org.cerberus.crud.service.ILogEventService) ArrayList(java.util.ArrayList) List(java.util.List) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl)

Example 18 with TestCaseStepActionControl

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

the class CreateTestCase method processRequest.

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException, JSONException {
    JSONObject jsonResponse = new JSONObject();
    Answer ans = new Answer();
    MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);
    msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));
    ans.setResultMessage(msg);
    PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);
    response.setContentType("application/json");
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    /**
     * Parsing and securing all required parameters.
     */
    String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");
    String testcase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), "");
    String originalTest = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTest"), "");
    String originalTestCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("originalTestCase"), "");
    // Prepare the final answer.
    MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);
    Answer finalAnswer = new Answer(msg1);
    /**
     * Checking all constrains before calling the services.
     */
    if (StringUtil.isNullOrEmpty(test) && StringUtil.isNullOrEmpty(testcase)) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Create").replace("%REASON%", "mandatory fields (test or testcase) are missing."));
        finalAnswer.setResultMessage(msg);
    } else {
        /**
         * All data seems cleans so we can call the services.
         */
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        testCaseService = appContext.getBean(ITestCaseService.class);
        testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
        testCaseLabelFactory = appContext.getBean(IFactoryTestCaseLabel.class);
        testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
        testCaseCountryFactory = appContext.getBean(IFactoryTestCaseCountry.class);
        testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
        testCaseStepService = appContext.getBean(ITestCaseStepService.class);
        testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
        testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
        TestCase testCaseData = getTestCaseFromRequest(request);
        ans = testCaseService.create(testCaseData);
        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
        if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
            /**
             * Object created. Adding Log entry.
             */
            ILogEventService logEventService = appContext.getBean(LogEventService.class);
            logEventService.createForPrivateCalls("/CreateTestCase", "CREATE", "Create TestCase : ['" + testcase + "']", request);
            // Update labels
            if (request.getParameter("labelList") != null) {
                JSONArray objLabelArray = new JSONArray(request.getParameter("labelList"));
                List<TestCaseLabel> labelList = new ArrayList();
                labelList = getLabelListFromRequest(request, appContext, test, testcase, objLabelArray);
                // Update the Database with the new list.
                ans = testCaseLabelService.compareListAndUpdateInsertDeleteElements(test, testcase, labelList);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
            }
            // Update Countries
            if (request.getParameter("countryList") != null) {
                JSONArray objCountryArray = new JSONArray(request.getParameter("countryList"));
                List<TestCaseCountry> tccList = new ArrayList();
                tccList = getCountryListFromRequest(request, appContext, test, testcase, objCountryArray);
                // Update the Database with the new list.
                ans = testCaseCountryService.compareListAndUpdateInsertDeleteElements(test, testcase, tccList);
                finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                // Duplicate other objects.
                List<TestCaseCountryProperties> tccpList = new ArrayList();
                List<TestCaseCountryProperties> newTccpList = new ArrayList();
                if (!tccList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                    tccpList = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCase(originalTest, originalTestCase);
                    // Build a new list with the countries that exist for the testcase.
                    for (TestCaseCountryProperties curTccp : tccpList) {
                        if (testCaseCountryService.exist(test, testcase, curTccp.getCountry())) {
                            newTccpList.add(curTccp);
                        }
                    }
                    if (!newTccpList.isEmpty()) {
                        ans = testCaseCountryPropertiesService.duplicateList(newTccpList, test, testcase);
                        finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                    }
                }
            }
            List<TestCaseStep> tcsList = new ArrayList();
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                tcsList = testCaseStepService.getListOfSteps(originalTest, originalTestCase);
                if (!tcsList.isEmpty()) {
                    ans = testCaseStepService.duplicateList(tcsList, test, testcase);
                    finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                }
            }
            List<TestCaseStepAction> tcsaList = new ArrayList();
            if (!tcsList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                tcsaList = testCaseStepActionService.findTestCaseStepActionbyTestTestCase(originalTest, originalTestCase);
                if (!tcsaList.isEmpty()) {
                    ans = testCaseStepActionService.duplicateList(tcsaList, test, testcase);
                    finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                }
            }
            if (!tcsList.isEmpty() && !tcsaList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                List<TestCaseStepActionControl> tcsacList = testCaseStepActionControlService.findControlByTestTestCase(originalTest, originalTestCase);
                if (!tcsacList.isEmpty()) {
                    ans = testCaseStepActionControlService.duplicateList(tcsacList, test, testcase);
                    finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);
                }
            }
        }
    }
    /**
     * Formating and returning the json result.
     */
    jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());
    jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());
    response.getWriter().print(jsonResponse);
    response.getWriter().flush();
}
Also used : ITestCaseStepActionService(org.cerberus.crud.service.ITestCaseStepActionService) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) PolicyFactory(org.owasp.html.PolicyFactory) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) ApplicationContext(org.springframework.context.ApplicationContext) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) ITestCaseService(org.cerberus.crud.service.ITestCaseService) ILogEventService(org.cerberus.crud.service.ILogEventService) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) IFactoryTestCaseCountry(org.cerberus.crud.factory.IFactoryTestCaseCountry) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) ITestCaseLabelService(org.cerberus.crud.service.ITestCaseLabelService) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel) JSONArray(org.json.JSONArray) IFactoryTestCaseCountry(org.cerberus.crud.factory.IFactoryTestCaseCountry) ITestCaseStepActionControlService(org.cerberus.crud.service.ITestCaseStepActionControlService) Answer(org.cerberus.util.answer.Answer) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase) IFactoryTestCaseLabel(org.cerberus.crud.factory.IFactoryTestCaseLabel)

Example 19 with TestCaseStepActionControl

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

the class UpdateTestCaseWithDependencies method getTestCaseStepFromParameter.

private List<TestCaseStep> getTestCaseStepFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, boolean duplicate) {
    List<TestCaseStep> testCaseStep = new ArrayList();
    ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);
    String[] testcase_step_increment = getParameterValuesIfExists(request, "step_increment");
    IFactoryTestCaseStep testCaseStepFactory = appContext.getBean(IFactoryTestCaseStep.class);
    if (testcase_step_increment != null) {
        for (String inc : testcase_step_increment) {
            String delete = getParameterIfExists(request, "step_delete_" + inc);
            String stepInUse = getParameterIfExists(request, "step_InUseInOtherTestCase_" + inc);
            int step = getParameterIfExists(request, "step_technical_number_" + inc) == null ? 0 : Integer.parseInt(getParameterIfExists(request, "step_technical_number_" + inc));
            int sort = getParameterIfExists(request, "step_number_" + inc) == null ? 0 : Integer.parseInt(getParameterIfExists(request, "step_number_" + inc));
            int initialStep = getParameterIfExists(request, "initial_step_number_" + inc) == null ? 0 : Integer.parseInt(getParameterIfExists(request, "initial_step_number_" + inc));
            String loop = getParameterIfExists(request, "step_loop_" + inc);
            String conditionOper = getParameterIfExists(request, "step_conditionoper_" + inc);
            String conditionVal1 = getParameterIfExists(request, "step_conditionval1_" + inc);
            String conditionVal2 = getParameterIfExists(request, "step_conditionval2_" + inc);
            String desc = getParameterIfExists(request, "step_description_" + inc);
            String useStep = getParameterIfExists(request, "step_useStep_" + inc);
            String useStepChanged = getParameterIfExists(request, "step_useStepChanged_" + inc);
            String useStepTest = getParameterIfExists(request, "step_useStepTest_" + inc) == null ? "" : getParameterIfExists(request, "step_useStepTest_" + inc);
            String useStepTestCase = getParameterIfExists(request, "step_useStepTestCase_" + inc) == null ? "" : getParameterIfExists(request, "step_useStepTestCase_" + inc);
            String stepValue = getParameterIfExists(request, "step_useStepStep_" + inc);
            int useStepStep = stepValue == null || stepValue.equals("") ? -1 : Integer.parseInt(getParameterIfExists(request, "step_useStepStep_" + inc));
            String inLibrary = getParameterIfExists(request, "step_inLibrary_" + inc);
            /* If delete, don't add it to the list of steps */
            if (delete == null) {
                TestCaseStep tcStep = testCaseStepFactory.create(test, testCase, step, sort, loop, conditionOper, conditionVal1, conditionVal2, desc, useStep == null ? "N" : useStep, useStepTest, useStepTestCase, useStepStep, inLibrary == null ? "N" : inLibrary);
                /* Take action and control only if not use step*/
                if (useStep == null || useStep.equals("N")) {
                    String isToCopySteps = getParameterIfExists(request, "isToCopySteps_" + inc);
                    if (isToCopySteps != null && isToCopySteps.equals("Y")) {
                        // TODO:FN the information about the useStep should be cleared?
                        // tcStep.setTestCaseStepAction(tcsService.findTestCaseStep(useStepTest, useStepTestCase, useStepStep));
                        ITestCaseStepActionService tcsaService = appContext.getBean(TestCaseStepActionService.class);
                        ITestCaseStepActionControlService tcsacService = appContext.getBean(TestCaseStepActionControlService.class);
                        int stepNumber = Integer.parseInt(stepValue);
                        List<TestCaseStepAction> actions = tcsaService.getListOfAction(useStepTest, useStepTestCase, stepNumber);
                        for (TestCaseStepAction act : actions) {
                            List<TestCaseStepActionControl> controlsPerAction = tcsacService.findControlByTestTestCaseStepSequence(useStepTest, useStepTestCase, stepNumber, act.getSequence());
                            // these actions now belong to the current test case, therefore we need to change it
                            act.setTest(test);
                            act.setTestCase(testCase);
                            act.setStep(step);
                            List<TestCaseStepActionControl> updatedControlsPerAction = new ArrayList<TestCaseStepActionControl>();
                            for (TestCaseStepActionControl ctrl : controlsPerAction) {
                                ctrl.setTest(test);
                                ctrl.setTestCase(testCase);
                                ctrl.setStep(step);
                                updatedControlsPerAction.add(ctrl);
                            }
                            act.setTestCaseStepActionControl(updatedControlsPerAction);
                        }
                        tcStep.setTestCaseStepAction(actions);
                    } else {
                        tcStep.setTestCaseStepAction(getTestCaseStepActionFromParameter(request, appContext, test, testCase, inc));
                    }
                    // clears the information about the usestep
                    tcStep.setUseStep("N");
                    tcStep.setUseStepTest("");
                    tcStep.setUseStepTestCase("");
                    tcStep.setUseStepStep(-1);
                    // updates the test step action list with the new step
                    List<TestCaseStepAction> actionsForStep = tcStep.getTestCaseStepAction();
                    for (TestCaseStepAction ac : actionsForStep) {
                        List<TestCaseStepActionControl> actionControlList = ac.getTestCaseStepActionControl();
                        for (TestCaseStepActionControl acControl : actionControlList) {
                            acControl.setStep(step);
                        }
                        ac.setStep(step);
                    }
                // update the step associated with the actions that are now the new actions
                } else {
                    TestCaseStep tcs = null;
                    if (useStepStep != -1 && !useStepTest.equals("") && !useStepTestCase.equals("")) {
                        /* If use step, verify if used step alread use another one */
                        if ((useStepChanged != null && useStepChanged.equals("Y")) || duplicate) {
                            // if it is to duplicate then we need to get the new step information
                            // save the information about the test + testcase + step that was used to duplicate the test
                            tcs = tcsService.findTestCaseStep(useStepTest, useStepTestCase, useStepStep);
                            if (tcs != null) {
                                tcStep.setUseStepTest(tcs.getTest());
                                tcStep.setUseStepTestCase(tcs.getTestCase());
                                tcStep.setUseStepStep(tcs.getStep());
                            }
                        } else {
                            // if there was no changes then it uses the same information
                            tcs = tcsService.findTestCaseStep(test, testCase, step);
                            if (tcs != null) {
                                tcStep.setUseStepTest(tcs.getUseStepTest());
                                tcStep.setUseStepTestCase(tcs.getUseStepTestCase());
                                tcStep.setUseStepStep(tcs.getUseStepStep());
                            }
                        }
                    } else {
                        // does not defines a valid step, then keep as it was before
                        tcs = tcsService.findTestCaseStep(test, testCase, step);
                        if (tcs != null) {
                            tcStep.setUseStep("N");
                            tcStep.setUseStepTest(tcs.getUseStepTest());
                            tcStep.setUseStepTestCase(tcs.getUseStepTestCase());
                            tcStep.setUseStepStep(tcs.getUseStepStep());
                            tcStep.setTestCaseStepAction(getTestCaseStepActionFromParameter(request, appContext, test, testCase, inc));
                            List<TestCaseStepAction> actionsForStep = tcStep.getTestCaseStepAction();
                            for (TestCaseStepAction ac : actionsForStep) {
                                List<TestCaseStepActionControl> actionControlList = ac.getTestCaseStepActionControl();
                                for (TestCaseStepActionControl acControl : actionControlList) {
                                    acControl.setStep(step);
                                }
                                ac.setStep(step);
                            }
                        }
                    }
                    if (tcs != null) {
                        /**
                         * If description is empty, take the one from the
                         * use step
                         */
                        if (desc.equals("")) {
                            tcStep.setDescription(tcs.getDescription());
                        }
                    } else {
                        // if the step that should be defined is not imported then we should save the data
                        // and the test case should have the useStep = 'N'
                        tcStep.setUseStep("N");
                    }
                }
                if (stepInUse != null && stepInUse.equals("Y")) {
                    tcStep.setIsStepInUseByOtherTestCase(true);
                    tcStep.setInitialStep(initialStep);
                } else {
                    tcStep.setIsStepInUseByOtherTestCase(false);
                }
                testCaseStep.add(tcStep);
            }
        }
    }
    return testCaseStep;
}
Also used : ITestCaseStepActionService(org.cerberus.crud.service.ITestCaseStepActionService) IFactoryTestCaseStepAction(org.cerberus.crud.factory.IFactoryTestCaseStepAction) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) ArrayList(java.util.ArrayList) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep) ITestCaseStepActionControlService(org.cerberus.crud.service.ITestCaseStepActionControlService) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl)

Example 20 with TestCaseStepActionControl

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

the class FactoryTestCaseStepActionControl method create.

@Override
public TestCaseStepActionControl create(String test, String testCase, int step, int sequence, int controlSequence, int sort, String conditionOper, String conditionVal1, String conditionVal2, String control, String value1, String value2, String fatal, String description, String screenshotFilename) {
    TestCaseStepActionControl testCaseStepActionControl = new TestCaseStepActionControl();
    testCaseStepActionControl.setTest(test);
    testCaseStepActionControl.setTestCase(testCase);
    testCaseStepActionControl.setStep(step);
    testCaseStepActionControl.setSequence(sequence);
    testCaseStepActionControl.setControlSequence(controlSequence);
    testCaseStepActionControl.setSort(sort);
    testCaseStepActionControl.setConditionOper(conditionOper);
    testCaseStepActionControl.setConditionVal1(conditionVal1);
    testCaseStepActionControl.setConditionVal2(conditionVal2);
    testCaseStepActionControl.setControl(control);
    testCaseStepActionControl.setValue1(value1);
    testCaseStepActionControl.setValue2(value2);
    testCaseStepActionControl.setFatal(fatal);
    testCaseStepActionControl.setDescription(description);
    testCaseStepActionControl.setScreenshotFilename(screenshotFilename);
    return testCaseStepActionControl;
}
Also used : TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) IFactoryTestCaseStepActionControl(org.cerberus.crud.factory.IFactoryTestCaseStepActionControl)

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