Search in sources :

Example 6 with ITestCaseCountryPropertiesService

use of org.cerberus.crud.service.ITestCaseCountryPropertiesService in project cerberus-source by cerberustesting.

the class DuplicateTestCase method processRequest.

// </editor-fold>
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException, CerberusException {
    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"), null);
    /**
     * Checking all constrains before calling the services.
     */
    if (StringUtil.isNullOrEmpty(test) || StringUtil.isNullOrEmpty(testCase) || StringUtil.isNullOrEmpty(originalTest) || originalTestCase != null) {
        msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
        msg.setDescription(msg.getDescription().replace("%ITEM%", "Test Case").replace("%OPERATION%", "Duplicate").replace("%REASON%", "mandatory fields are missing."));
        ans.setResultMessage(msg);
    } else {
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
        ITestCaseCountryService testCaseCountryService = appContext.getBean(ITestCaseCountryService.class);
        ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
        ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);
        ITestCaseStepActionService testCaseStepActionService = appContext.getBean(ITestCaseStepActionService.class);
        ITestCaseStepActionControlService testCaseStepActionControlService = appContext.getBean(ITestCaseStepActionControlService.class);
        ITestCaseLabelService testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
        AnswerItem originalTestAI = testCaseService.readByKey(originalTest, originalTestCase);
        AnswerItem targetTestAI = testCaseService.readByKey(test, testCase);
        TestCase originalTC = (TestCase) originalTestAI.getItem();
        TestCase targetTC = (TestCase) targetTestAI.getItem();
        if (!(originalTestAI.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && originalTestAI.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%", "Duplicate").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 (!request.isUserInRole("Test")) {
            // 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%", "Duplicate").replace("%REASON%", "Not enought privilege to duplicate the testcase. You must belong to Test Privilege."));
            ans.setResultMessage(msg);
        } else if (targetTC != null) {
            // If target Test Case already exists.
            msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate").replace("%REASON%", "The test case you try to create already exists. Please define a test/testcase that is not already existing."));
            ans.setResultMessage(msg);
        } else {
            getInfo(request, originalTC);
            // Update object with new testcase id and insert it in db
            originalTC.setTest(test);
            originalTC.setTestCase(testCase);
            ans = testCaseService.create(originalTC);
            List<TestCaseCountry> countryList = new ArrayList();
            countryList = testCaseCountryService.findTestCaseCountryByTestTestCase(originalTest, originalTestCase);
            boolean success = true;
            if (!countryList.isEmpty()) {
                ans = testCaseCountryService.duplicateList(countryList, test, testCase);
            }
            // List<TestCaseCountry> countryList = getCountryList(test, testCase, request);
            // boolean success = false;
            // if (countryList.isEmpty()) {
            // success = true;
            // } else {
            // success = testCaseCountryService.insertListTestCaseCountry(countryList);
            // }
            List<TestCaseCountryProperties> tccpList = new ArrayList();
            if (!countryList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
                tccpList = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCase(originalTest, originalTestCase);
                if (!tccpList.isEmpty()) {
                    ans = testCaseCountryPropertiesService.duplicateList(tccpList, test, testCase);
                }
            }
            List<TestCaseStep> tcsList = new ArrayList();
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
                tcsList = testCaseStepService.getListOfSteps(originalTest, originalTestCase);
                if (!tcsList.isEmpty()) {
                    ans = testCaseStepService.duplicateList(tcsList, test, testCase);
                }
            }
            List<TestCaseStepAction> tcsaList = new ArrayList();
            if (!tcsList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
                tcsaList = testCaseStepActionService.findTestCaseStepActionbyTestTestCase(originalTest, originalTestCase);
                if (!tcsaList.isEmpty()) {
                    ans = testCaseStepActionService.duplicateList(tcsaList, test, testCase);
                }
            }
            if (!tcsList.isEmpty() && !tcsaList.isEmpty() && ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
                List<TestCaseStepActionControl> tcsacList = testCaseStepActionControlService.findControlByTestTestCase(originalTest, originalTestCase);
                if (!tcsacList.isEmpty()) {
                    ans = testCaseStepActionControlService.duplicateList(tcsacList, test, testCase);
                }
            }
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
                List<TestCaseLabel> tclList = testCaseLabelService.readByTestTestCase(originalTest, originalTestCase).getDataList();
                if (!tclList.isEmpty()) {
                    ans = testCaseLabelService.duplicateList(tclList, test, testCase);
                }
            }
            if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && success) {
                msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);
                msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase").replace("%OPERATION%", "Duplicate"));
                ans.setResultMessage(msg);
                /**
                 * Update was successful. Adding Log entry.
                 */
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/DuplicateTestCase", "CREATE", "Create testcase : ['" + test + "'|'" + testCase + "']", 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) 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) TestCaseCountry(org.cerberus.crud.entity.TestCaseCountry) IFactoryTestCaseCountry(org.cerberus.crud.factory.IFactoryTestCaseCountry) ILogEventService(org.cerberus.crud.service.ILogEventService) TestCaseStepActionControl(org.cerberus.crud.entity.TestCaseStepActionControl) ITestCaseLabelService(org.cerberus.crud.service.ITestCaseLabelService) ITestCaseStepService(org.cerberus.crud.service.ITestCaseStepService) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) ITestCaseStepActionControlService(org.cerberus.crud.service.ITestCaseStepActionControlService) AnswerItem(org.cerberus.util.answer.AnswerItem) Answer(org.cerberus.util.answer.Answer) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase)

Example 7 with ITestCaseCountryPropertiesService

use of org.cerberus.crud.service.ITestCaseCountryPropertiesService in project cerberus-source by cerberustesting.

the class GetPropertiesForTestCase 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 {
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try {
        String test = request.getParameter("test");
        String testcase = request.getParameter("testcase");
        String property = request.getParameter("property");
        ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
        ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(ITestCaseCountryPropertiesService.class);
        JSONArray propertyList = new JSONArray();
        List<TestCaseCountryProperties> properties = testCaseCountryPropertiesService.findDistinctPropertiesOfTestCase(test, testcase);
        for (TestCaseCountryProperties prop : properties) {
            if (property == null || "".equals(property.trim()) || property.equals(prop.getProperty())) {
                JSONObject propertyFound = new JSONObject();
                propertyFound.put("property", prop.getProperty());
                propertyFound.put("description", prop.getDescription());
                propertyFound.put("type", prop.getType());
                propertyFound.put("database", prop.getDatabase());
                propertyFound.put("value1", prop.getValue1());
                propertyFound.put("value2", prop.getValue2());
                propertyFound.put("length", prop.getLength());
                propertyFound.put("rowLimit", prop.getRowLimit());
                propertyFound.put("nature", prop.getNature());
                propertyFound.put("retryNb", prop.getRetryNb());
                propertyFound.put("retryPeriod", prop.getRetryPeriod());
                propertyFound.put("cacheExpire", prop.getCacheExpire());
                List<String> countriesSelected = testCaseCountryPropertiesService.findCountryByProperty(prop);
                JSONArray countries = new JSONArray();
                for (String country : countriesSelected) {
                    countries.put(country);
                }
                propertyFound.put("country", countries);
                propertyList.put(propertyFound);
            }
        }
        response.setContentType("application/json");
        response.getWriter().print(propertyList.toString());
    } catch (JSONException ex) {
        LOG.warn(ex.toString());
    } finally {
        out.close();
    }
}
Also used : ApplicationContext(org.springframework.context.ApplicationContext) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) JSONObject(org.json.JSONObject) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) JSONArray(org.json.JSONArray) JSONException(org.json.JSONException) PrintWriter(java.io.PrintWriter)

Example 8 with ITestCaseCountryPropertiesService

use of org.cerberus.crud.service.ITestCaseCountryPropertiesService in project cerberus-source by cerberustesting.

the class UpdateTestCaseProperties1 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 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_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 initialTest = request.getParameter("informationInitialTest");
    String initialTestCase = request.getParameter("informationInitialTestCase");
    String test = request.getParameter("informationTest");
    String testCase = request.getParameter("informationTestCase");
    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);
        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);
                ans = tccpService.compareListAndUpdateInsertDeleteElements(initialTest, initialTestCase, tccpFromPage);
                /**
                 * 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() + "']", 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 : TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) PolicyFactory(org.owasp.html.PolicyFactory) MessageEvent(org.cerberus.engine.entity.MessageEvent) 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) ITestCaseService(org.cerberus.crud.service.ITestCaseService) ILogEventService(org.cerberus.crud.service.ILogEventService)

Example 9 with ITestCaseCountryPropertiesService

use of org.cerberus.crud.service.ITestCaseCountryPropertiesService 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 10 with ITestCaseCountryPropertiesService

use of org.cerberus.crud.service.ITestCaseCountryPropertiesService in project cerberus-source by cerberustesting.

the class CreateNotDefinedProperty 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 {
    JSONObject jsonResponse = new JSONObject();
    MessageEvent rs = null;
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    ITestCaseCountryPropertiesService testCaseCountryPropertiesService = appContext.getBean(TestCaseCountryPropertiesService.class);
    ITestCaseCountryService testCaseCountryService = appContext.getBean(TestCaseCountryService.class);
    IFactoryTestCaseCountryProperties factoryTestCaseCountryProperties = appContext.getBean(FactoryTestCaseCountryProperties.class);
    try {
        String propertyName = request.getParameter("property");
        if (propertyName != null) {
            propertyName = propertyName.replace("%", "");
        }
        String toTest = request.getParameter("totest");
        String toTestCase = request.getParameter("totestcase");
        String propertyType = request.getParameter("propertyType");
        String userLanguage = request.getParameter("userLanguage");
        // We retrieve all country of the destination TestCase
        List<String> toCountriesAll = testCaseCountryService.findListOfCountryByTestTestCase(toTest, toTestCase);
        if (toCountriesAll != null && toCountriesAll.size() > 0) {
            // Variable for the properties list of the destination TestCase
            List<TestCaseCountryProperties> listOfPropertiesToInsert = new ArrayList<TestCaseCountryProperties>();
            // Variable for the countries of a property of the destination TestCase
            List<String> toCountriesProp;
            IDocumentationService docService = appContext.getBean(DocumentationService.class);
            String notDefinedProperty = docService.findLabel("page_testcase", "txt_property_not_defined", "** Property not defined **", userLanguage);
            // List of all country of the destination test for the current property
            List<String> toCountries = new ArrayList<String>();
            toCountries.addAll(toCountriesAll);
            // Retrieve the country of the destination TestCase for the property,
            // if not empty remove it (property aleady exists for these countries)
            toCountriesProp = testCaseCountryPropertiesService.findCountryByPropertyNameAndTestCase(toTest, toTestCase, propertyName);
            if (toCountriesProp != null && toCountriesProp.size() > 0) {
                toCountries.removeAll(toCountriesProp);
            }
            for (String country : toCountries) {
                listOfPropertiesToInsert.add(factoryTestCaseCountryProperties.create(toTest, toTestCase, country, propertyName, "", propertyType, "---", notDefinedProperty, "", "0", 0, "STATIC", 0, 10000, 0));
            }
            Answer answer = testCaseCountryPropertiesService.createListTestCaseCountryPropertiesBatch(listOfPropertiesToInsert);
            rs = answer.getResultMessage();
            // then a new entry should be added by the log service
            if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
                // Adding Log entry.
                ILogEventService logEventService = appContext.getBean(LogEventService.class);
                logEventService.createForPrivateCalls("/CreateNotDefinedProperty", "CREATE", "Create NotDefinedProperty:" + " " + propertyName, request);
            }
        } else {
            rs = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);
            rs.setDescription(rs.getDescription().replace("%ITEM%", "Property ").replace("%OPERATION%", "CREATE").replace("%REASON%", "No countries were defined for the test case."));
        }
        // sets the message returned by the operations
        jsonResponse.put("messageType", rs.getMessage().getCodeString());
        jsonResponse.put("message", rs.getDescription());
        response.setContentType("application/json");
        response.getWriter().print(jsonResponse);
        response.getWriter().flush();
    } catch (JSONException ex) {
        LOG.warn(ex);
        // returns a default error message with the json format that is able to be parsed by the client-side
        response.getWriter().print(AnswerUtil.createGenericErrorAnswer());
    }
}
Also used : FactoryTestCaseCountryProperties(org.cerberus.crud.factory.impl.FactoryTestCaseCountryProperties) TestCaseCountryProperties(org.cerberus.crud.entity.TestCaseCountryProperties) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) ITestCaseCountryService(org.cerberus.crud.service.ITestCaseCountryService) Answer(org.cerberus.util.answer.Answer) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) ITestCaseCountryPropertiesService(org.cerberus.crud.service.ITestCaseCountryPropertiesService) ILogEventService(org.cerberus.crud.service.ILogEventService) IFactoryTestCaseCountryProperties(org.cerberus.crud.factory.IFactoryTestCaseCountryProperties) IDocumentationService(org.cerberus.crud.service.IDocumentationService)

Aggregations

ITestCaseCountryPropertiesService (org.cerberus.crud.service.ITestCaseCountryPropertiesService)10 TestCaseCountryProperties (org.cerberus.crud.entity.TestCaseCountryProperties)9 ArrayList (java.util.ArrayList)8 ITestCaseCountryService (org.cerberus.crud.service.ITestCaseCountryService)7 JSONObject (org.json.JSONObject)7 ApplicationContext (org.springframework.context.ApplicationContext)7 TestCaseStep (org.cerberus.crud.entity.TestCaseStep)6 TestCaseStepAction (org.cerberus.crud.entity.TestCaseStepAction)6 ILogEventService (org.cerberus.crud.service.ILogEventService)6 ITestCaseStepActionService (org.cerberus.crud.service.ITestCaseStepActionService)6 ITestCaseStepService (org.cerberus.crud.service.ITestCaseStepService)6 TestCase (org.cerberus.crud.entity.TestCase)5 TestCaseStepActionControl (org.cerberus.crud.entity.TestCaseStepActionControl)5 ITestCaseService (org.cerberus.crud.service.ITestCaseService)5 ITestCaseStepActionControlService (org.cerberus.crud.service.ITestCaseStepActionControlService)5 MessageEvent (org.cerberus.engine.entity.MessageEvent)5 Answer (org.cerberus.util.answer.Answer)5 AnswerItem (org.cerberus.util.answer.AnswerItem)4 List (java.util.List)3 TestCaseCountry (org.cerberus.crud.entity.TestCaseCountry)3