Search in sources :

Example 1 with IFactoryTestCaseStep

use of org.cerberus.crud.factory.IFactoryTestCaseStep in project cerberus-source by cerberustesting.

the class UseTestCaseStep method processRequest.

protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, CerberusException {
    response.setContentType("text/html;charset=UTF-8");
    appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
    ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
    IFactoryTestCaseStep testCaseStepFactory = appContext.getBean(IFactoryTestCaseStep.class);
    ITestCaseCountryService testCaseCountry = appContext.getBean(ITestCaseCountryService.class);
    ITestCaseCountryPropertiesService testCaseCountryProperties = appContext.getBean(ITestCaseCountryPropertiesService.class);
    this.database = appContext.getBean(DatabaseSpring.class);
    /**
     * Get Parameters Test : Target Test TestCase : Target TestCase Step :
     * Target Step fromTest : from Test fromTestCase : from TestCase
     * fromStep : from Step
     */
    String test = request.getParameter("Test");
    String testCase = request.getParameter("TestCase");
    Integer step = Integer.valueOf(request.getParameter("Step"));
    String loop = request.getParameter("Loop");
    String conditionOper = request.getParameter("ConditionOper");
    String conditionVal1 = request.getParameter("ConditionVal1");
    String conditionVal2 = request.getParameter("ConditionVal2");
    String description = request.getParameter("Description");
    String fromTest = request.getParameter("FromTest");
    String fromTestCase = request.getParameter("FromTestCase");
    Integer fromStep = Integer.valueOf(request.getParameter("FromStep"));
    String importProperty = "N";
    if (request.getParameter("ImportProperty") != null) {
        LOG.debug(request.getParameter("ImportProperty"));
        importProperty = request.getParameter("ImportProperty");
    }
    TestCaseStep tcs = testCaseStepFactory.create(test, testCase, step, step, loop, conditionOper, conditionVal1, conditionVal2, description, "Y", fromTest, fromTestCase, fromStep, null);
    /**
     * Import Step, properties
     */
    LOG.debug("Use Step");
    testCaseStepService.create(tcs);
    if (importProperty.equalsIgnoreCase("Y")) {
        /**
         * Get List of Country of the origin testcase and the destination
         * Testcase
         */
        List<String> tccListString = null;
        List<String> tccFromListString = null;
        List<TestCaseCountryProperties> tccpList = null;
        if (importProperty.equalsIgnoreCase("Y")) {
            tccListString = testCaseCountry.findListOfCountryByTestTestCase(test, testCase);
            tccFromListString = testCaseCountry.findListOfCountryByTestTestCase(test, testCase);
        }
        /**
         * For the country defined in the destination testcase, insert the
         * properties of the origine testcase
         */
        // retrieve list of property name used in the step
        List<String> propertyNamesOfStep = new ArrayList<String>();
        List<TestCaseStepAction> testCaseStepActions = testCaseStepActionService.getListOfAction(fromTest, fromTestCase, fromStep);
        for (TestCaseStepAction action : testCaseStepActions) {
            if (!propertyNamesOfStep.contains(action.getValue2())) {
                propertyNamesOfStep.add(action.getValue2());
            }
        }
        LOG.debug("Rewrite TestCaseCountryProperties");
        if (tccListString != null) {
            tccListString.retainAll(tccFromListString);
            if (tccListString.size() > 0 && propertyNamesOfStep.size() > 0) {
                List<TestCaseCountryProperties> tccpToImport = new ArrayList();
                for (String country : tccListString) {
                    tccpList = testCaseCountryProperties.findListOfPropertyPerTestTestCaseCountry(fromTest, fromTestCase, country);
                    for (TestCaseCountryProperties tccp : tccpList) {
                        // only add property of the test case if it is used by the step
                        if (propertyNamesOfStep.contains(tccp.getProperty())) {
                            tccp.setTest(test);
                            tccp.setTestCase(testCase);
                            tccpToImport.add(tccp);
                        }
                    }
                }
                // if the list of property to import is not empty, insert them.
                if (!tccpToImport.isEmpty()) {
                    testCaseCountryProperties.insertListTestCaseCountryProperties(tccpToImport);
                }
            }
        }
    }
    response.sendRedirect("TestCase.jsp?Load=Load&Test=" + test + "&TestCase=" + testCase);
}
Also used : ITestCaseStepActionService(org.cerberus.crud.service.ITestCaseStepActionService) TestCaseStepAction(org.cerberus.crud.entity.TestCaseStepAction) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) 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) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) DatabaseSpring(org.cerberus.database.DatabaseSpring)

Example 2 with IFactoryTestCaseStep

use of org.cerberus.crud.factory.IFactoryTestCaseStep in project cerberus-source by cerberustesting.

the class UpdateTestCaseWithDependencies1 method getTestCaseStepFromParameter.

private List<TestCaseStep> getTestCaseStepFromParameter(HttpServletRequest request, ApplicationContext appContext, String test, String testCase, boolean duplicate, JSONArray stepArray) throws JSONException {
    List<TestCaseStep> testCaseStep = new ArrayList();
    ITestCaseStepService tcsService = appContext.getBean(ITestCaseStepService.class);
    IFactoryTestCaseStep testCaseStepFactory = appContext.getBean(IFactoryTestCaseStep.class);
    for (int i = 0; i < stepArray.length(); i++) {
        JSONObject step = stepArray.getJSONObject(i);
        boolean delete = step.getBoolean("toDelete");
        int stepNumber = step.isNull("step") ? -1 : step.getInt("step");
        int sort = step.isNull("sort") ? -1 : step.getInt("sort");
        String loop = step.getString("loop");
        String conditionOper = step.getString("conditionOper");
        String conditionVal1 = step.getString("conditionVal1");
        String conditionVal2 = step.getString("conditionVal2");
        String description = step.getString("description");
        String useStep = step.getString("useStep");
        String useStepTest = step.getString("useStepTest");
        String useStepTestCase = step.getString("useStepTestCase");
        int useStepStep = step.getInt("useStepStep");
        String inLibrary = step.getString("inLibrary");
        JSONArray stepActions = step.getJSONArray("actionArr");
        if (!delete) {
            TestCaseStep tcStep = testCaseStepFactory.create(test, testCase, stepNumber, sort, loop, conditionOper, conditionVal1, conditionVal2, description, useStep, useStepTest, useStepTestCase, useStepStep, inLibrary);
            if (useStep.equals("N")) {
                tcStep.setTestCaseStepAction(getTestCaseStepActionFromParameter(request, appContext, test, testCase, stepActions));
            } else {
                TestCaseStep tcs = null;
                if (useStepStep != -1 && !useStepTest.equals("") && !useStepTestCase.equals("")) {
                    tcs = tcsService.findTestCaseStep(useStepTest, useStepTestCase, useStepStep);
                    if (tcs != null) {
                        tcStep.setUseStepTest(tcs.getTest());
                        tcStep.setUseStepTestCase(tcs.getTestCase());
                        tcStep.setUseStepStep(tcs.getStep());
                    }
                }
            }
            testCaseStep.add(tcStep);
        }
    }
    return testCaseStep;
}
Also used : JSONObject(org.json.JSONObject) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) IFactoryTestCaseStep(org.cerberus.crud.factory.IFactoryTestCaseStep) TestCaseStep(org.cerberus.crud.entity.TestCaseStep)

Example 3 with IFactoryTestCaseStep

use of org.cerberus.crud.factory.IFactoryTestCaseStep 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)

Aggregations

ArrayList (java.util.ArrayList)3 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)3 IFactoryTestCaseStep (org.cerberus.crud.factory.IFactoryTestCaseStep)3 ITestCaseStepService (org.cerberus.crud.service.ITestCaseStepService)3 TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)2 ITestCaseStepActionService (org.cerberus.crud.service.ITestCaseStepActionService)2 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)1 TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)1 IFactoryTestCaseStepAction (org.cerberus.crud.factory.IFactoryTestCaseStepAction)1 IFactoryTestCaseStepActionControl (org.cerberus.crud.factory.IFactoryTestCaseStepActionControl)1 ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)1 ITestCaseCountryService (org.cerberus.crud.service.ITestCaseCountryService)1 ITestCaseStepActionControlService (org.cerberus.crud.service.ITestCaseStepActionControlService)1 DatabaseSpring (org.cerberus.database.DatabaseSpring)1 JSONArray (org.json.JSONArray)1 JSONObject (org.json.JSONObject)1