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;
}
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);
}
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;
}
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;
}
Aggregations