Search in sources :

Example 41 with TestCaseExecution

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

the class ReadTestCaseExecutionByTag method getStatByEnvCountryRobotDecli.

private JSONObject getStatByEnvCountryRobotDecli(List<TestCaseExecution> testCaseExecutions, HashMap<String, SummaryStatisticsDTO> statMap, boolean env, boolean country, boolean robotDecli, boolean app, JSONObject statusFilter, JSONObject countryFilter, boolean splitStats) throws JSONException {
    SummaryStatisticsDTO total = new SummaryStatisticsDTO();
    total.setEnvironment("Total");
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        String controlStatus = testCaseExecution.getControlStatus();
        if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on") || !splitStats) {
            StringBuilder key = new StringBuilder();
            key.append((env) ? testCaseExecution.getEnvironment() : "");
            key.append("_");
            key.append((country) ? testCaseExecution.getCountry() : "");
            key.append("_");
            key.append((robotDecli) ? testCaseExecution.getRobotDecli() : "");
            key.append("_");
            key.append((app) ? testCaseExecution.getApplication() : "");
            if (statMap.containsKey(key.toString())) {
                statMap.get(key.toString()).updateStatisticByStatus(testCaseExecution.getControlStatus());
            }
            total.updateStatisticByStatus(testCaseExecution.getControlStatus());
        }
    }
    return extractSummaryData(statMap, total, splitStats);
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) SummaryStatisticsDTO(org.cerberus.dto.SummaryStatisticsDTO)

Example 42 with TestCaseExecution

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

the class ReadTestCaseExecutionByTag method generateStats.

private JSONObject generateStats(HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter, boolean splitStats) throws JSONException {
    JSONObject jsonResult = new JSONObject();
    boolean env = request.getParameter("env") != null || !splitStats;
    boolean country = request.getParameter("country") != null || !splitStats;
    boolean robotDecli = request.getParameter("robotDecli") != null || !splitStats;
    boolean app = request.getParameter("app") != null || !splitStats;
    HashMap<String, SummaryStatisticsDTO> statMap = new HashMap<String, SummaryStatisticsDTO>();
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        String controlStatus = testCaseExecution.getControlStatus();
        if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
            StringBuilder key = new StringBuilder();
            key.append((env) ? testCaseExecution.getEnvironment() : "");
            key.append("_");
            key.append((country) ? testCaseExecution.getCountry() : "");
            key.append("_");
            key.append((robotDecli) ? testCaseExecution.getRobotDecli() : "");
            key.append("_");
            key.append((app) ? testCaseExecution.getApplication() : "");
            SummaryStatisticsDTO stat = new SummaryStatisticsDTO();
            stat.setEnvironment(testCaseExecution.getEnvironment());
            stat.setCountry(testCaseExecution.getCountry());
            stat.setRobotDecli(testCaseExecution.getRobotDecli());
            stat.setApplication(testCaseExecution.getApplication());
            statMap.put(key.toString(), stat);
        }
    }
    jsonResult.put("contentTable", getStatByEnvCountryRobotDecli(testCaseExecutions, statMap, env, country, robotDecli, app, statusFilter, countryFilter, splitStats));
    return jsonResult;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) SummaryStatisticsDTO(org.cerberus.dto.SummaryStatisticsDTO)

Example 43 with TestCaseExecution

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

the class ReadTestCaseExecutionByTag method generateFunctionChart.

private JSONObject generateFunctionChart(List<TestCaseExecution> testCaseExecutions, String tag, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {
    JSONObject jsonResult = new JSONObject();
    Map<String, JSONObject> axisMap = new HashMap<String, JSONObject>();
    String globalStart = "";
    String globalEnd = "";
    long globalStartL = 0;
    long globalEndL = 0;
    String globalStatus = "Finished";
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        String key;
        JSONObject control = new JSONObject();
        JSONObject function = new JSONObject();
        String controlStatus = testCaseExecution.getControlStatus();
        if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
            if (testCaseExecution.getTestCaseObj() != null && testCaseExecution.getTestCaseObj().getFunction() != null && !"".equals(testCaseExecution.getTestCaseObj().getFunction())) {
                key = testCaseExecution.getTestCaseObj().getFunction();
            } else {
                key = testCaseExecution.getTest();
            }
            controlStatus = testCaseExecution.getControlStatus();
            control.put("value", 1);
            control.put("color", getColor(controlStatus));
            control.put("label", controlStatus);
            function.put("name", key);
            if (axisMap.containsKey(key)) {
                function = axisMap.get(key);
                if (function.has(controlStatus)) {
                    int prec = function.getJSONObject(controlStatus).getInt("value");
                    control.put("value", prec + 1);
                }
            }
            function.put(controlStatus, control);
            axisMap.put(key, function);
        }
        if (testCaseExecution.getStart() != 0) {
            if ((globalStartL == 0) || (globalStartL > testCaseExecution.getStart())) {
                globalStartL = testCaseExecution.getStart();
                globalStart = String.valueOf(new Date(testCaseExecution.getStart()));
            }
        }
        if (!testCaseExecution.getControlStatus().equalsIgnoreCase("PE") && testCaseExecution.getEnd() != 0) {
            if ((globalEndL == 0) || (globalEndL < testCaseExecution.getEnd())) {
                globalEndL = testCaseExecution.getEnd();
                globalEnd = String.valueOf(new Date(testCaseExecution.getEnd()));
            }
        }
        if (testCaseExecution.getControlStatus().equalsIgnoreCase("PE")) {
            globalStatus = "Pending...";
        }
    }
    Gson gson = new Gson();
    jsonResult.put("axis", axisMap.values());
    jsonResult.put("tag", tag);
    jsonResult.put("globalEnd", gson.toJson(new Timestamp(globalEndL)).replace("\"", ""));
    jsonResult.put("globalStart", globalStart);
    jsonResult.put("globalStatus", globalStatus);
    return jsonResult;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Gson(com.google.gson.Gson) Timestamp(java.sql.Timestamp) Date(java.util.Date)

Example 44 with TestCaseExecution

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

the class GetExecutionQueue 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.json.JSONException
 * @throws org.cerberus.exception.CerberusException
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException, CerberusException {
    AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
    JSONObject jsonResponse = new JSONObject();
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    boolean check = ParameterParserUtil.parseBooleanParam(request.getParameter("check"), false);
    boolean push = ParameterParserUtil.parseBooleanParam(request.getParameter("push"), false);
    if (check) {
        IApplicationService applicationService = appContext.getBean(IApplicationService.class);
        IInvariantService invariantService = appContext.getBean(IInvariantService.class);
        ITestService testService = appContext.getBean(ITestService.class);
        ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);
        ICountryEnvParamService cepService = appContext.getBean(ICountryEnvParamService.class);
        IParameterService parameterService = appContext.getBean(IParameterService.class);
        testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
        List<ExecutionValidator> inQueue = new ArrayList<>();
        JSONArray testCaseList = new JSONArray(request.getParameter("testcase"));
        JSONArray environmentList = new JSONArray(request.getParameter("environment"));
        JSONArray countryList = new JSONArray(request.getParameter("countries"));
        /**
         * Creating all the list from the JSON to call the services
         */
        List<TestCase> TCList = new ArrayList<>();
        List<String> envList = new ArrayList<>();
        List<String> countries = new ArrayList<>();
        for (int index = 0; index < testCaseList.length(); index++) {
            JSONObject testCaseJson = testCaseList.getJSONObject(index);
            TestCase tc = new TestCase();
            tc.setTest(testCaseJson.getString("test"));
            tc.setTestCase(testCaseJson.getString("testcase"));
            TCList.add(tc);
        }
        for (int index = 0; index < environmentList.length(); index++) {
            String environment = environmentList.getString(index);
            envList.add(environment);
        }
        for (int index = 0; index < countryList.length(); index++) {
            String country = countryList.getString(index);
            countries.add(country);
        }
        List<TestCaseExecution> tceList = testCaseExecutionService.createAllTestCaseExecution(TCList, envList, countries);
        IExecutionCheckService execCheckService = appContext.getBean(IExecutionCheckService.class);
        for (TestCaseExecution execution : tceList) {
            boolean exception = false;
            ExecutionValidator validator = new ExecutionValidator();
            try {
                execution.setTestObj(testService.convert(testService.readByKey(execution.getTest())));
            } catch (CerberusException ex) {
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_TEST_NOT_FOUND);
                mes.setDescription(mes.getDescription().replace("%TEST%", execution.getTest()));
                validator.setValid(false);
                validator.setMessage(mes.getDescription());
                exception = true;
            }
            try {
                execution.setTestCaseObj(testCaseService.findTestCaseByKey(execution.getTest(), execution.getTestCase()));
            } catch (CerberusException ex) {
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_TESTCASE_NOT_FOUND);
                mes.setDescription(mes.getDescription().replace("%TEST%", execution.getTest()));
                mes.setDescription(mes.getDescription().replace("%TESTCASE%", execution.getTestCase()));
                validator.setValid(false);
                validator.setMessage(mes.getDescription());
                exception = true;
            }
            try {
                execution.setApplicationObj(applicationService.convert(applicationService.readByKey(execution.getTestCaseObj().getApplication())));
            } catch (CerberusException ex) {
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_APPLICATION_NOT_FOUND);
                mes.setDescription(mes.getDescription().replace("%APPLI%", execution.getTestCaseObj().getApplication()));
                validator.setValid(false);
                validator.setMessage(mes.getDescription());
                exception = true;
            }
            execution.setEnvironmentData(execution.getEnvironment());
            try {
                execution.setCountryEnvParam(cepService.convert(cepService.readByKey(execution.getApplicationObj().getSystem(), execution.getCountry(), execution.getEnvironment())));
            } catch (CerberusException ex) {
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_COUNTRYENV_NOT_FOUND);
                mes.setDescription(mes.getDescription().replace("%SYSTEM%", execution.getApplicationObj().getSystem()));
                mes.setDescription(mes.getDescription().replace("%COUNTRY%", execution.getCountry()));
                mes.setDescription(mes.getDescription().replace("%ENV%", execution.getEnvironmentData()));
                validator.setValid(false);
                validator.setMessage(mes.getDescription());
                exception = true;
            }
            try {
                execution.setEnvironmentDataObj(invariantService.convert(invariantService.readByKey("ENVIRONMENT", execution.getEnvironmentData())));
            } catch (CerberusException ex) {
                MessageGeneral mes = new MessageGeneral(MessageGeneralEnum.VALIDATION_FAILED_ENVIRONMENT_DOESNOTEXIST);
                mes.setDescription(mes.getDescription().replace("%ENV%", execution.getEnvironmentData()));
                validator.setValid(false);
                validator.setMessage(mes.getDescription());
                exception = true;
            }
            String browser = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_BROWSER), DEFAULT_VALUE_BROWSER);
            if (!(StringUtil.isNullOrEmpty(browser))) {
                // if application is not GUI, we force browser to empty value.
                if (execution.getApplicationObj() != null && execution.getApplicationObj().getType() != null && !(execution.getApplicationObj().getType().equalsIgnoreCase(Application.TYPE_GUI))) {
                    execution.setBrowser("");
                }
            } else {
                execution.setBrowser(browser);
            }
            String manualExecution = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_MANUAL_EXECUTION), DEFAULT_VALUE_MANUAL_EXECUTION);
            execution.setManualExecution(manualExecution);
            if (exception == false) {
                /**
                 * Checking the execution as it would be checked in the
                 * engine
                 */
                MessageGeneral message = execCheckService.checkTestCaseExecution(execution);
                if (!(message.equals(new MessageGeneral(MessageGeneralEnum.EXECUTION_PE_CHECKINGPARAMETERS)))) {
                    validator.setValid(false);
                    validator.setMessage(message.getDescription());
                } else {
                    validator.setValid(true);
                    validator.setMessage("Valid Execution.");
                }
            }
            validator.setExecution(execution);
            inQueue.add(validator);
        }
        JSONArray dataArray = new JSONArray();
        for (ExecutionValidator tce : inQueue) {
            JSONObject exec = new JSONObject();
            exec.put("test", tce.getExecution().getTest());
            exec.put("testcase", tce.getExecution().getTestCase());
            exec.put("env", tce.getExecution().getEnvironment());
            exec.put("country", tce.getExecution().getCountry());
            exec.put("appType", tce.getExecution().getApplicationObj().getType());
            exec.put("isValid", tce.isValid());
            exec.put("message", tce.getMessage());
            dataArray.put(exec);
        }
        jsonResponse.put("contentTable", dataArray);
    }
    if (push) {
        IExecutionThreadPoolService executionThreadService = appContext.getBean(IExecutionThreadPoolService.class);
        IParameterService parameterService = appContext.getBean(IParameterService.class);
        IFactoryTestCaseExecutionQueue inQueueFactoryService = appContext.getBean(IFactoryTestCaseExecutionQueue.class);
        ITestCaseExecutionQueueService inQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);
        int addedToQueue = 0;
        JSONArray toAddList = new JSONArray(request.getParameter("toAddList"));
        JSONArray browsers = new JSONArray(request.getParameter("browsers"));
        Date requestDate = new Date();
        /**
         * RETRIEVING ROBOT SETTINGS *
         */
        String robot = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_ROBOT), null);
        String robotIP = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_ROBOT_IP), null);
        String robotPort = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_ROBOT_PORT), null);
        String browserVersion = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_BROWSER_VERSION), null);
        String platform = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_PLATFORM), null);
        String screenSize = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_SCREENSIZE), null);
        /**
         * RETRIEVING EXECUTION SETTINGS *
         */
        String tag = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_TAG), "");
        int screenshot = ParameterParserUtil.parseIntegerParam(request.getParameter(PARAMETER_SCREENSHOT), DEFAULT_VALUE_SCREENSHOT);
        int verbose = ParameterParserUtil.parseIntegerParam(request.getParameter(PARAMETER_VERBOSE), DEFAULT_VALUE_VERBOSE);
        String timeout = request.getParameter(PARAMETER_TIMEOUT);
        int pageSource = ParameterParserUtil.parseIntegerParam(request.getParameter(PARAMETER_PAGE_SOURCE), DEFAULT_VALUE_PAGE_SOURCE);
        int seleniumLog = ParameterParserUtil.parseIntegerParam(request.getParameter(PARAMETER_SELENIUM_LOG), DEFAULT_VALUE_SELENIUM_LOG);
        int retries = ParameterParserUtil.parseIntegerParam(request.getParameter(PARAMETER_RETRIES), DEFAULT_VALUE_RETRIES);
        String manualExecution = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_MANUAL_EXECUTION), DEFAULT_VALUE_MANUAL_EXECUTION);
        /**
         * RETRIEVING MANUAL ENVIRONMENT SETTINGS *
         */
        String manualHost = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_MANUAL_HOST), null);
        String manualContextRoot = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_MANUAL_CONTEXT_ROOT), null);
        String manualLoginRelativeURL = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_MANUAL_LOGIN_RELATIVE_URL), null);
        String manualEnvData = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_MANUAL_ENV_DATA), null);
        // Create Tag when exist.
        if (!StringUtil.isNullOrEmpty(tag)) {
            // We create or update it.
            ITagService tagService = appContext.getBean(ITagService.class);
            tagService.createAuto(tag, "", request.getRemoteUser());
        }
        for (int index = 0; index < toAddList.length(); index++) {
            JSONObject toAdd = toAddList.getJSONObject(index);
            int manualURL = 0;
            if (toAdd.getString("env").equals("MANUAL")) {
                manualURL = 1;
            }
            try {
                // Create the template
                TestCaseExecutionQueue tceiq = inQueueFactoryService.create(toAdd.getString("test"), toAdd.getString("testcase"), toAdd.getString("country"), toAdd.getString("env"), robot, robotIP, robotPort, "", browserVersion, platform, screenSize, manualURL, manualHost, manualContextRoot, manualLoginRelativeURL, manualEnvData, tag, screenshot, verbose, timeout, pageSource, seleniumLog, 0, retries, manualExecution, 1000, request.getRemoteUser(), null, null, null);
                // Then fill it with either no browser
                if ((browsers.length() == 0) || ((toAdd.getString("appType") != null) && (!toAdd.getString("appType").equalsIgnoreCase(Application.TYPE_GUI)))) {
                    inQueueService.convert(inQueueService.create(tceiq));
                    addedToQueue++;
                } else // Or with required browsers
                {
                    for (int iterBrowser = 0; iterBrowser < browsers.length(); iterBrowser++) {
                        tceiq.setBrowser(browsers.getString(iterBrowser));
                        try {
                            inQueueService.convert(inQueueService.create(tceiq));
                            addedToQueue++;
                        } catch (CerberusException e) {
                            LOG.warn("Unable to insert execution in queue " + tceiq, e);
                        }
                    }
                }
            } catch (FactoryCreationException e) {
                LOG.warn("Unable to create the execution queue template", e);
            }
        }
        // Trigger execution if necessary
        if (addedToQueue > 0) {
            try {
                executionThreadService.executeNextInQueueAsynchroneously(false);
            } catch (CerberusException ex) {
                String errorMessage = "Unable to feed the execution queue due to " + ex.getMessage();
                LOG.warn(errorMessage);
                answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));
                answer.getResultMessage().setDescription(errorMessage);
            }
            jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());
            jsonResponse.put("message", answer.getResultMessage().getDescription());
            jsonResponse.put("addedToQueue", addedToQueue);
            jsonResponse.put("redirect", "ReportingExecutionByTag.jsp?Tag=" + StringUtil.encodeAsJavaScriptURIComponent(tag));
        }
    }
    response.setContentType("application/json");
    response.getWriter().print(jsonResponse.toString());
}
Also used : IExecutionCheckService(org.cerberus.engine.execution.IExecutionCheckService) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) IParameterService(org.cerberus.crud.service.IParameterService) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) ExecutionValidator(org.cerberus.dto.ExecutionValidator) FactoryCreationException(org.cerberus.exception.FactoryCreationException) ApplicationContext(org.springframework.context.ApplicationContext) MessageGeneral(org.cerberus.engine.entity.MessageGeneral) ITestService(org.cerberus.crud.service.ITestService) ITestCaseService(org.cerberus.crud.service.ITestCaseService) TestCaseExecutionQueue(org.cerberus.crud.entity.TestCaseExecutionQueue) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) IApplicationService(org.cerberus.crud.service.IApplicationService) ITestCaseExecutionQueueService(org.cerberus.crud.service.ITestCaseExecutionQueueService) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CerberusException(org.cerberus.exception.CerberusException) IInvariantService(org.cerberus.crud.service.IInvariantService) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) IFactoryTestCaseExecutionQueue(org.cerberus.crud.factory.IFactoryTestCaseExecutionQueue) Date(java.util.Date) JSONObject(org.json.JSONObject) TestCase(org.cerberus.crud.entity.TestCase) IExecutionThreadPoolService(org.cerberus.engine.threadpool.IExecutionThreadPoolService) ITagService(org.cerberus.crud.service.ITagService) ICountryEnvParamService(org.cerberus.crud.service.ICountryEnvParamService)

Example 45 with TestCaseExecution

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

the class CIService method getCIResult.

@Override
public JSONObject getCIResult(String tag) {
    try {
        JSONObject jsonResponse = new JSONObject();
        List<TestCaseExecution> myList;
        int nbok = 0;
        int nbko = 0;
        int nbfa = 0;
        int nbpe = 0;
        int nbne = 0;
        int nbna = 0;
        int nbca = 0;
        int nbqu = 0;
        int nbtotal = 0;
        int nbkop1 = 0;
        int nbkop2 = 0;
        int nbkop3 = 0;
        int nbkop4 = 0;
        long longStart = 0;
        long longEnd = 0;
        try {
            myList = testExecutionService.readLastExecutionAndExecutionInQueueByTag(tag);
            for (TestCaseExecution curExe : myList) {
                if (longStart == 0) {
                    longStart = curExe.getStart();
                }
                if (curExe.getStart() < longStart) {
                    longStart = curExe.getStart();
                }
                if (longEnd == 0) {
                    longEnd = curExe.getEnd();
                }
                if (curExe.getEnd() > longEnd) {
                    longEnd = curExe.getEnd();
                }
                nbtotal++;
                switch(curExe.getControlStatus()) {
                    case TestCaseExecution.CONTROLSTATUS_KO:
                        nbko++;
                        break;
                    case TestCaseExecution.CONTROLSTATUS_OK:
                        nbok++;
                        break;
                    case TestCaseExecution.CONTROLSTATUS_FA:
                        nbfa++;
                        break;
                    case TestCaseExecution.CONTROLSTATUS_NA:
                        nbna++;
                        break;
                    case TestCaseExecution.CONTROLSTATUS_CA:
                        nbca++;
                        break;
                    case TestCaseExecution.CONTROLSTATUS_PE:
                        nbpe++;
                        break;
                    case TestCaseExecution.CONTROLSTATUS_NE:
                        nbne++;
                        break;
                    case TestCaseExecution.CONTROLSTATUS_QU:
                        nbqu++;
                        break;
                }
                if (!curExe.getControlStatus().equals("OK") && !curExe.getControlStatus().equals("NE") && !curExe.getControlStatus().equals("PE") && !curExe.getControlStatus().equals("QU")) {
                    switch(curExe.getTestCaseObj().getPriority()) {
                        case 1:
                            nbkop1++;
                            break;
                        case 2:
                            nbkop2++;
                            break;
                        case 3:
                            nbkop3++;
                            break;
                        case 4:
                            nbkop4++;
                            break;
                    }
                }
            }
        } catch (CerberusException ex) {
            LOG.warn(ex);
        } catch (ParseException ex) {
            LOG.warn(ex);
        }
        float pond1 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio1", "", 0);
        float pond2 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio2", "", 0);
        float pond3 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio3", "", 0);
        float pond4 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio4", "", 0);
        String result;
        float resultCal = (nbkop1 * pond1) + (nbkop2 * pond2) + (nbkop3 * pond3) + (nbkop4 * pond4);
        if ((nbtotal > 0) && nbqu + nbne + nbpe > 0) {
            result = "PE";
        } else if ((resultCal < 1) && (nbtotal > 0)) {
            result = "OK";
        } else {
            result = "KO";
        }
        jsonResponse.put("messageType", "OK");
        jsonResponse.put("message", "CI result calculated with success.");
        jsonResponse.put("tag", tag);
        jsonResponse.put("CI_OK_prio1", pond1);
        jsonResponse.put("CI_OK_prio2", pond2);
        jsonResponse.put("CI_OK_prio3", pond3);
        jsonResponse.put("CI_OK_prio4", pond4);
        jsonResponse.put("CI_finalResult", resultCal);
        jsonResponse.put("NonOK_prio1_nbOfExecution", nbkop1);
        jsonResponse.put("NonOK_prio2_nbOfExecution", nbkop2);
        jsonResponse.put("NonOK_prio3_nbOfExecution", nbkop3);
        jsonResponse.put("NonOK_prio4_nbOfExecution", nbkop4);
        jsonResponse.put("status_OK_nbOfExecution", nbok);
        jsonResponse.put("status_KO_nbOfExecution", nbko);
        jsonResponse.put("status_FA_nbOfExecution", nbfa);
        jsonResponse.put("status_PE_nbOfExecution", nbpe);
        jsonResponse.put("status_NA_nbOfExecution", nbna);
        jsonResponse.put("status_CA_nbOfExecution", nbca);
        jsonResponse.put("status_NE_nbOfExecution", nbne);
        jsonResponse.put("status_QU_nbOfExecution", nbqu);
        jsonResponse.put("TOTAL_nbOfExecution", nbtotal);
        jsonResponse.put("result", result);
        jsonResponse.put("ExecutionStart", String.valueOf(new Timestamp(longStart)));
        jsonResponse.put("ExecutionEnd", String.valueOf(new Timestamp(longEnd)));
        return jsonResponse;
    } catch (JSONException ex) {
        LOG.error(ex);
    }
    return null;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CerberusException(org.cerberus.exception.CerberusException) JSONObject(org.json.JSONObject) JSONException(org.json.JSONException) ParseException(java.text.ParseException) Timestamp(java.sql.Timestamp)

Aggregations

TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)55 ArrayList (java.util.ArrayList)24 IFactoryTestCaseExecution (org.cerberus.crud.factory.IFactoryTestCaseExecution)20 MessageEvent (org.cerberus.engine.entity.MessageEvent)19 JSONObject (org.json.JSONObject)17 AnswerItem (org.cerberus.util.answer.AnswerItem)15 AnswerList (org.cerberus.util.answer.AnswerList)14 Connection (java.sql.Connection)13 PreparedStatement (java.sql.PreparedStatement)13 ResultSet (java.sql.ResultSet)13 SQLException (java.sql.SQLException)13 LinkedHashMap (java.util.LinkedHashMap)13 ITestCaseExecutionService (org.cerberus.crud.service.ITestCaseExecutionService)12 CerberusException (org.cerberus.exception.CerberusException)11 List (java.util.List)10 HashMap (java.util.HashMap)9 TestCaseExecutionQueue (org.cerberus.crud.entity.TestCaseExecutionQueue)9 JSONArray (org.json.JSONArray)9 JSONException (org.json.JSONException)9 ApplicationContext (org.springframework.context.ApplicationContext)9