Search in sources :

Example 6 with SummaryStatisticsDTO

use of org.cerberus.dto.SummaryStatisticsDTO 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)

Example 7 with SummaryStatisticsDTO

use of org.cerberus.dto.SummaryStatisticsDTO 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 8 with SummaryStatisticsDTO

use of org.cerberus.dto.SummaryStatisticsDTO 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 9 with SummaryStatisticsDTO

use of org.cerberus.dto.SummaryStatisticsDTO in project cerberus-source by cerberustesting.

the class ReadTestCaseExecutionByTag method extractSummaryData.

private JSONObject extractSummaryData(HashMap<String, SummaryStatisticsDTO> summaryMap, SummaryStatisticsDTO total, boolean splitStats) throws JSONException {
    JSONObject extract = new JSONObject();
    Gson gson = new Gson();
    if (splitStats) {
        JSONArray dataArray = new JSONArray();
        // sort keys
        TreeMap<String, SummaryStatisticsDTO> sortedKeys = new TreeMap<String, SummaryStatisticsDTO>(summaryMap);
        for (String key : sortedKeys.keySet()) {
            SummaryStatisticsDTO sumStats = summaryMap.get(key);
            // percentage values
            sumStats.updatePercentageStatistics();
            dataArray.put(new JSONObject(gson.toJson(sumStats)));
        }
        extract.put("split", dataArray);
    }
    total.updatePercentageStatistics();
    extract.put("total", new JSONObject(gson.toJson(total)));
    return extract;
}
Also used : JSONObject(org.json.JSONObject) SummaryStatisticsDTO(org.cerberus.dto.SummaryStatisticsDTO) JSONArray(org.json.JSONArray) Gson(com.google.gson.Gson) TreeMap(java.util.TreeMap)

Aggregations

SummaryStatisticsDTO (org.cerberus.dto.SummaryStatisticsDTO)9 TestCaseExecution (org.cerberus.crud.entity.TestCaseExecution)6 JSONObject (org.json.JSONObject)5 TreeMap (java.util.TreeMap)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 LinkedHashMap (java.util.LinkedHashMap)3 List (java.util.List)3 JSONArray (org.json.JSONArray)3 Gson (com.google.gson.Gson)2 AnswerList (org.cerberus.util.answer.AnswerList)2 IOException (java.io.IOException)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 HSSFPalette (org.apache.poi.hssf.usermodel.HSSFPalette)1 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)1 HSSFColor (org.apache.poi.hssf.util.HSSFColor)1 Cell (org.apache.poi.ss.usermodel.Cell)1 CellStyle (org.apache.poi.ss.usermodel.CellStyle)1