Search in sources :

Example 21 with TestCaseExecution

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

the class ReadTestCaseExecution 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, ParseException {
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    try {
        JSONObject jsonResponse = new JSONObject();
        AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
        // Data/Filter Parameters.
        String Tag = ParameterParserUtil.parseStringParam(request.getParameter("Tag"), "");
        String value = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
        String test = ParameterParserUtil.parseStringParam(request.getParameter("test"), "");
        String testCase = ParameterParserUtil.parseStringParam(request.getParameter("testCase"), "");
        String system = ParameterParserUtil.parseStringParam(request.getParameter("system"), "");
        long executionId = ParameterParserUtil.parseLongParam(request.getParameter("executionId"), 0);
        boolean likeColumn = ParameterParserUtil.parseBooleanParam(request.getParameter("likeColumn"), false);
        // Switch Parameters.
        boolean executionWithDependency = ParameterParserUtil.parseBooleanParam("executionWithDependency", false);
        String columnName = ParameterParserUtil.parseStringParam(request.getParameter("columnName"), "");
        boolean byColumns = ParameterParserUtil.parseBooleanParam(request.getParameter("byColumns"), false);
        if (!Strings.isNullOrEmpty(columnName)) {
            // If columnName is present, then return the distinct value of this column.
            answer = findValuesForColumnFilter(system, test, appContext, request, columnName);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!Tag.equals("") && byColumns) {
            // Return the columns to display in the execution table
            answer = findExecutionColumns(appContext, request, Tag);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!Tag.equals("") && !byColumns) {
            // Return the list of execution for the execution table
            answer = findExecutionListByTag(appContext, request, Tag);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!system.isEmpty()) {
            // find execution by system, the remaining parameters are parsed after avoiding the extra processing
            answer = findExecutionListBySystem(system, appContext, request);
            jsonResponse = (JSONObject) answer.getItem();
        } else if (!test.equals("") && !testCase.equals("")) {
            TestCaseExecution lastExec = testCaseExecutionService.findLastTestCaseExecutionNotPE(test, testCase);
            JSONObject result = new JSONObject();
            if (lastExec != null) {
                result.put("id", lastExec.getId());
                result.put("queueId", lastExec.getQueueID());
                result.put("controlStatus", lastExec.getControlStatus());
                result.put("env", lastExec.getEnvironment());
                result.put("country", lastExec.getCountry());
                result.put("end", new Date(lastExec.getEnd())).toString();
            }
            jsonResponse.put("contentTable", result);
        } else if (executionId != 0 && !executionWithDependency) {
            answer = testCaseExecutionService.readByKeyWithDependency(executionId);
            TestCaseExecution tce = (TestCaseExecution) answer.getItem();
            jsonResponse.put("testCaseExecution", tce.toJson(true));
        } else if (executionId != 0 && executionWithDependency) {
        } else {
            answer = findTestCaseExecutionList(appContext, true, request);
            jsonResponse = (JSONObject) answer.getItem();
        }
        jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());
        jsonResponse.put("message", answer.getResultMessage().getDescription());
        response.getWriter().print(jsonResponse.toString());
    } 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 : ApplicationContext(org.springframework.context.ApplicationContext) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) JSONObject(org.json.JSONObject) MessageEvent(org.cerberus.engine.entity.MessageEvent) JSONException(org.json.JSONException) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) AnswerItem(org.cerberus.util.answer.AnswerItem) Date(java.util.Date)

Example 22 with TestCaseExecution

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

the class ReadTestCaseExecution method findTestCaseExecutionList.

private AnswerItem findTestCaseExecutionList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException, CerberusException {
    AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));
    AnswerList testCaseExecutionList = new AnswerList();
    JSONObject object = new JSONObject();
    testCaseExecutionService = appContext.getBean(TestCaseExecutionService.class);
    int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));
    int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));
    String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");
    int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));
    String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,description,active,automated,tdatecrea");
    String[] columnToSort = sColumns.split(",");
    String columnName = columnToSort[columnToSortParameter];
    String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");
    Map<String, List<String>> individualSearch = new HashMap<>();
    List<String> individualLike = new ArrayList(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));
    for (int a = 0; a < columnToSort.length; a++) {
        if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {
            List<String> search = new ArrayList(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));
            if (individualLike.contains(columnToSort[a])) {
                individualSearch.put(columnToSort[a] + ":like", search);
            } else {
                individualSearch.put(columnToSort[a], search);
            }
        }
    }
    testCaseExecutionList = testCaseExecutionService.readByCriteria(startPosition, length, columnName.concat(" ").concat(sort), searchParameter, individualSearch, individualLike);
    JSONArray jsonArray = new JSONArray();
    if (testCaseExecutionList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {
        // the service was able to perform the query, then we should get all values
        for (TestCaseExecution testCaseExecution : (List<TestCaseExecution>) testCaseExecutionList.getDataList()) {
            jsonArray.put(testCaseExecution.toJson(true).put("hasPermissions", userHasPermissions));
        }
    }
    object.put("contentTable", jsonArray);
    object.put("hasPermissions", userHasPermissions);
    object.put("iTotalRecords", testCaseExecutionList.getTotalRows());
    object.put("iTotalDisplayRecords", testCaseExecutionList.getTotalRows());
    answer.setItem(object);
    answer.setResultMessage(testCaseExecutionList.getResultMessage());
    return answer;
}
Also used : TestCaseExecutionService(org.cerberus.crud.service.impl.TestCaseExecutionService) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) AnswerList(org.cerberus.util.answer.AnswerList) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) JSONArray(org.json.JSONArray) AnswerItem(org.cerberus.util.answer.AnswerItem) JSONObject(org.json.JSONObject) AnswerList(org.cerberus.util.answer.AnswerList) List(java.util.List) ArrayList(java.util.ArrayList)

Example 23 with TestCaseExecution

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

the class ReadTestCaseExecutionByTag method generateBugStats.

private JSONObject generateBugStats(HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {
    JSONObject jsonResult = new JSONObject();
    SummaryStatisticsBugTrackerDTO stat = new SummaryStatisticsBugTrackerDTO();
    String bugsToReport = "KO,FA";
    stat.setNbExe(1);
    int totalBugReported = 0;
    int totalBugToReport = 0;
    int totalBugToReportReported = 0;
    int totalBugToClean = 0;
    HashMap<String, SummaryStatisticsBugTrackerDTO> statMap = new HashMap<String, SummaryStatisticsBugTrackerDTO>();
    for (TestCaseExecution testCaseExecution : testCaseExecutions) {
        String controlStatus = testCaseExecution.getControlStatus();
        if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
            String key = "";
            if (bugsToReport.contains(testCaseExecution.getControlStatus())) {
                totalBugToReport++;
            }
            if ((testCaseExecution.getTestCaseObj() != null) && (!StringUtil.isNullOrEmpty(testCaseExecution.getTestCaseObj().getBugID()))) {
                key = testCaseExecution.getTestCaseObj().getBugID();
                stat = statMap.get(key);
                totalBugReported++;
                if (stat == null) {
                    stat = new SummaryStatisticsBugTrackerDTO();
                    stat.setNbExe(1);
                    stat.setBugId(testCaseExecution.getTestCaseObj().getBugID());
                    stat.setBugIdURL(testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID()));
                    stat.setExeIdLastStatus(testCaseExecution.getControlStatus());
                    stat.setExeIdFirst(testCaseExecution.getId());
                    stat.setExeIdLast(testCaseExecution.getId());
                    stat.setTestFirst(testCaseExecution.getTest());
                    stat.setTestLast(testCaseExecution.getTest());
                    stat.setTestCaseFirst(testCaseExecution.getTestCase());
                    stat.setTestCaseLast(testCaseExecution.getTestCase());
                } else {
                    stat.setNbExe(stat.getNbExe() + 1);
                    stat.setExeIdLastStatus(testCaseExecution.getControlStatus());
                    stat.setExeIdLast(testCaseExecution.getId());
                    stat.setTestLast(testCaseExecution.getTest());
                    stat.setTestCaseLast(testCaseExecution.getTestCase());
                }
                if (!(bugsToReport.contains(testCaseExecution.getControlStatus()))) {
                    totalBugToClean++;
                    stat.setToClean(true);
                } else {
                    totalBugToReportReported++;
                }
                statMap.put(key, stat);
            }
        }
    }
    Gson gson = new Gson();
    JSONArray dataArray = new JSONArray();
    for (String key : statMap.keySet()) {
        SummaryStatisticsBugTrackerDTO sumStats = statMap.get(key);
        dataArray.put(new JSONObject(gson.toJson(sumStats)));
    }
    jsonResult.put("BugTrackerStat", dataArray);
    jsonResult.put("totalBugToReport", totalBugToReport);
    jsonResult.put("totalBugToReportReported", totalBugToReportReported);
    jsonResult.put("totalBugReported", totalBugReported);
    jsonResult.put("totalBugToClean", totalBugToClean);
    return jsonResult;
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) JSONObject(org.json.JSONObject) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) SummaryStatisticsBugTrackerDTO(org.cerberus.dto.SummaryStatisticsBugTrackerDTO)

Example 24 with TestCaseExecution

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

the class ReadTestCaseExecutionByTag 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 {
    // Calling Servlet Transversal Util.
    ServletUtil.servletStart(request);
    ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());
    response.setContentType("application/json");
    response.setCharacterEncoding("utf8");
    String echo = request.getParameter("sEcho");
    AnswerItem answer = new AnswerItem(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));
    testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);
    tagService = appContext.getBean(ITagService.class);
    testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);
    try {
        // Data/Filter Parameters.
        String Tag = ParameterParserUtil.parseStringParam(request.getParameter("Tag"), "");
        List<String> outputReport = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues("outputReport"), new ArrayList(), "UTF-8");
        JSONObject jsonResponse = new JSONObject();
        JSONObject statusFilter = getStatusList(request);
        JSONObject countryFilter = getCountryList(request, appContext);
        // Get Data from database
        List<TestCaseExecution> testCaseExecutions = testCaseExecutionService.readLastExecutionAndExecutionInQueueByTag(Tag);
        // Table that contain the list of testcases and corresponding executions
        if (outputReport.isEmpty() || outputReport.contains("table")) {
            jsonResponse.put("table", generateTestCaseExecutionTable(appContext, testCaseExecutions, statusFilter, countryFilter));
        }
        // Executions per Function (or Test).
        if (outputReport.isEmpty() || outputReport.contains("functionChart")) {
            jsonResponse.put("functionChart", generateFunctionChart(testCaseExecutions, Tag, statusFilter, countryFilter));
        }
        // Global executions stats per Status
        if (outputReport.isEmpty() || outputReport.contains("statsChart")) {
            jsonResponse.put("statsChart", generateStats(request, testCaseExecutions, statusFilter, countryFilter, true));
        }
        // BugTracker Recap
        if (outputReport.isEmpty() || outputReport.contains("bugTrackerStat")) {
            jsonResponse.put("bugTrackerStat", generateBugStats(request, testCaseExecutions, statusFilter, countryFilter));
        }
        // Labels Stats
        if (outputReport.isEmpty() || outputReport.contains("labelStat")) {
            jsonResponse.put("labelStat", generateLabelStats(appContext, request, testCaseExecutions, statusFilter, countryFilter));
        }
        if (!outputReport.isEmpty()) {
            // currently used to optimize the homePage
            if (outputReport.contains("totalStatsCharts") && !outputReport.contains("statsChart")) {
                jsonResponse.put("statsChart", generateStats(request, testCaseExecutions, statusFilter, countryFilter, false));
            }
            // currently used to optimize the homePage
            if (outputReport.contains("resendTag")) {
                jsonResponse.put("tag", Tag);
            }
        }
        Tag mytag = tagService.convert(tagService.readByKey(Tag));
        JSONObject tagJSON = convertTagToJSONObject(mytag);
        jsonResponse.put("tagObject", tagJSON);
        jsonResponse.put("tagDuration", (mytag.getDateEndQueue().getTime() - mytag.getDateCreated().getTime()) / 60000);
        answer.setItem(jsonResponse);
        answer.setResultMessage(answer.getResultMessage().resolveDescription("ITEM", "Tag Statistics").resolveDescription("OPERATION", "Read"));
        jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());
        jsonResponse.put("message", answer.getResultMessage().getDescription());
        jsonResponse.put("sEcho", echo);
        response.getWriter().print(jsonResponse.toString());
    } catch (ParseException ex) {
        LOG.error("Error on main call : " + ex);
    } catch (CerberusException ex) {
        LOG.error("Error on main call : " + ex);
    } catch (JSONException ex) {
        LOG.error("Error on main call : " + ex);
    } catch (Exception ex) {
        LOG.error("Error on main call : " + ex);
    }
}
Also used : TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) CerberusException(org.cerberus.exception.CerberusException) MessageEvent(org.cerberus.engine.entity.MessageEvent) ArrayList(java.util.ArrayList) JSONException(org.json.JSONException) AnswerItem(org.cerberus.util.answer.AnswerItem) ITestCaseExecutionService(org.cerberus.crud.service.ITestCaseExecutionService) ServletException(javax.servlet.ServletException) JSONException(org.json.JSONException) ParseException(java.text.ParseException) IOException(java.io.IOException) CerberusException(org.cerberus.exception.CerberusException) ApplicationContext(org.springframework.context.ApplicationContext) JSONObject(org.json.JSONObject) ITagService(org.cerberus.crud.service.ITagService) Tag(org.cerberus.crud.entity.Tag) ParseException(java.text.ParseException) ITestCaseExecutionQueueService(org.cerberus.crud.service.ITestCaseExecutionQueueService)

Example 25 with TestCaseExecution

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

the class ReadTestCaseExecutionByTag method generateLabelStats.

private JSONObject generateLabelStats(ApplicationContext appContext, HttpServletRequest request, List<TestCaseExecution> testCaseExecutions, JSONObject statusFilter, JSONObject countryFilter) throws JSONException {
    JSONObject jsonResult = new JSONObject();
    boolean stickers = request.getParameter("stickers") != null;
    boolean requirement = request.getParameter("requirement") != null;
    if (stickers || requirement) {
        testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);
        AnswerList testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null);
        SummaryStatisticsDTO total = new SummaryStatisticsDTO();
        total.setEnvironment("Total");
        /**
         * Iterate on the label retrieved and generate HashMap based on the
         * key Test_TestCase
         */
        LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap();
        for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList.getDataList()) {
            if ((Label.TYPE_STICKER.equals(label.getLabel().getType()) && stickers) || (Label.TYPE_REQUIREMENT.equals(label.getLabel().getType()) && requirement)) {
                String key = label.getTest() + "_" + label.getTestcase();
                JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());
                if (testCaseWithLabel.containsKey(key)) {
                    testCaseWithLabel.get(key).put(jo);
                } else {
                    testCaseWithLabel.put(key, new JSONArray().put(jo));
                }
            }
        }
        /**
         * For All execution, get all label and generate statistics
         */
        LinkedHashMap<String, SummaryStatisticsDTO> labelPerTestcaseExecution = new LinkedHashMap();
        for (TestCaseExecution testCaseExecution : testCaseExecutions) {
            String controlStatus = testCaseExecution.getControlStatus();
            if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {
                // Get label for current test_testcase
                JSONArray labelsForTestCase = testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase());
                if (labelsForTestCase != null) {
                    for (int index = 0; index < labelsForTestCase.length(); index++) {
                        JSONObject j = labelsForTestCase.getJSONObject(index);
                        if (labelPerTestcaseExecution.containsKey(j.get("name"))) {
                            labelPerTestcaseExecution.get(j.get("name").toString()).updateStatisticByStatus(controlStatus);
                        } else {
                            SummaryStatisticsDTO stat = new SummaryStatisticsDTO();
                            stat.setLabel(j);
                            stat.updateStatisticByStatus(controlStatus);
                            labelPerTestcaseExecution.put(j.get("name").toString(), stat);
                        }
                        total.updateStatisticByStatus(controlStatus);
                    }
                }
            }
        }
        jsonResult.put("labelStats", extractSummaryData(labelPerTestcaseExecution, total, true));
    }
    return jsonResult;
}
Also used : AnswerList(org.cerberus.util.answer.AnswerList) TestCaseExecution(org.cerberus.crud.entity.TestCaseExecution) TestCaseLabel(org.cerberus.crud.entity.TestCaseLabel) JSONArray(org.json.JSONArray) LinkedHashMap(java.util.LinkedHashMap) JSONObject(org.json.JSONObject) SummaryStatisticsDTO(org.cerberus.dto.SummaryStatisticsDTO) AnswerList(org.cerberus.util.answer.AnswerList) ArrayList(java.util.ArrayList) List(java.util.List) ITestCaseLabelService(org.cerberus.crud.service.ITestCaseLabelService)

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