Best Cerberus-source code snippet using org.cerberus.service.ciresult.impl.CIService.generateStats
Source:CIService.java
...65 campaign = myTag.getCampaign();66 }67 List<TestCaseExecution> myList = testExecutionService.readLastExecutionAndExecutionInQueueByTag(tag);68 JSONObject jsonResponse = CIService.this.getCIResult(tag, campaign, myList);69 jsonResponse.put("detail_by_declinaison", generateStats(myList));70 jsonResponse.put("environment_List", generateEnvList(myList));71 jsonResponse.put("country_list", generateCountryList(myList));72 jsonResponse.put("robotdecli_list", generateRobotDecliList(myList));73 jsonResponse.put("system_list", generateSystemList(myList));74 jsonResponse.put("application_list", generateApplicationList(myList));75 jsonResponse.put("nb_of_retry", myList.stream().mapToInt(it -> it.getNbExecutions() - 1).sum());76 return jsonResponse;77 } catch (CerberusException | ParseException | JSONException ex) {78 LOG.error(ex, ex);79 }80 return null;81 }82 private JSONObject getCIResult(String tag, String campaign, List<TestCaseExecution> myList) {83 try {84 JSONObject jsonResponse = new JSONObject();85 int nbok = 0;86 int nbko = 0;87 int nbfa = 0;88 int nbpe = 0;89 int nbne = 0;90 int nbwe = 0;91 int nbna = 0;92 int nbca = 0;93 int nbqu = 0;94 int nbqe = 0;95 int nbtotal = 0;96 int nbkop1 = 0;97 int nbkop2 = 0;98 int nbkop3 = 0;99 int nbkop4 = 0;100 int nbkop5 = 0;101 long longStart = 0;102 long longEnd = 0;103 for (TestCaseExecution curExe : myList) {104 if (longStart == 0) {105 longStart = curExe.getStart();106 }107 if (curExe.getStart() < longStart) {108 longStart = curExe.getStart();109 }110 if (longEnd == 0) {111 longEnd = curExe.getEnd();112 }113 if (curExe.getEnd() > longEnd) {114 longEnd = curExe.getEnd();115 }116 nbtotal++;117 switch (curExe.getControlStatus()) {118 case TestCaseExecution.CONTROLSTATUS_KO:119 nbko++;120 break;121 case TestCaseExecution.CONTROLSTATUS_OK:122 nbok++;123 break;124 case TestCaseExecution.CONTROLSTATUS_FA:125 nbfa++;126 break;127 case TestCaseExecution.CONTROLSTATUS_NA:128 nbna++;129 break;130 case TestCaseExecution.CONTROLSTATUS_CA:131 nbca++;132 break;133 case TestCaseExecution.CONTROLSTATUS_PE:134 nbpe++;135 break;136 case TestCaseExecution.CONTROLSTATUS_NE:137 nbne++;138 break;139 case TestCaseExecution.CONTROLSTATUS_WE:140 nbwe++;141 break;142 case TestCaseExecution.CONTROLSTATUS_QU:143 nbqu++;144 break;145 case TestCaseExecution.CONTROLSTATUS_QE:146 nbqe++;147 break;148 }149 if (!curExe.getControlStatus().equals("OK") && !curExe.getControlStatus().equals("NE")150 && !curExe.getControlStatus().equals("PE") && !curExe.getControlStatus().equals("QU")) {151 switch (curExe.getTestCaseObj().getPriority()) {152 case 1:153 nbkop1++;154 break;155 case 2:156 nbkop2++;157 break;158 case 3:159 nbkop3++;160 break;161 case 4:162 nbkop4++;163 break;164 case 5:165 nbkop5++;166 break;167 }168 }169 }170 int pond1 = parameterService.getParameterIntegerByKey("cerberus_ci_okcoefprio1", "", 0);171 int pond2 = parameterService.getParameterIntegerByKey("cerberus_ci_okcoefprio2", "", 0);172 int pond3 = parameterService.getParameterIntegerByKey("cerberus_ci_okcoefprio3", "", 0);173 int pond4 = parameterService.getParameterIntegerByKey("cerberus_ci_okcoefprio4", "", 0);174 int pond5 = parameterService.getParameterIntegerByKey("cerberus_ci_okcoefprio5", "", 0);175 String result;176 // Getting threshold from parameter.177 int resultCalThreshold = parameterService.getParameterIntegerByKey("cerberus_ci_threshold", "", 100);178 // If tag is linked to campaign, we get the threshold from the campaign definition (if exist and can be converted to integer).179 if (!StringUtil.isNullOrEmpty(campaign)) {180 try {181 LOG.debug("Trying to get CIScoreThreshold from campaign : '" + campaign + "'");182 // Check campaign score here.183 Campaign mycampaign = campaignService.convert(campaignService.readByKey(campaign));184 if (!StringUtil.isNullOrEmpty(mycampaign.getCIScoreThreshold())) {185 try {186 resultCalThreshold = Integer.valueOf(mycampaign.getCIScoreThreshold());187 } catch (NumberFormatException ex) {188 LOG.error("Could not convert campaign CIScoreThreshold '" + mycampaign.getCIScoreThreshold() + "' to integer.", ex);189 }190 }191 } catch (CerberusException ex) {192 LOG.error("Could not find campaign when calculating CIScore.", ex);193 }194 }195 int resultCal = (nbkop1 * pond1) + (nbkop2 * pond2) + (nbkop3 * pond3) + (nbkop4 * pond4) + (nbkop5 * pond5);196 if ((nbtotal > 0) && nbqu + nbpe > 0) {197 result = "PE";198 } else {199 result = getFinalResult(resultCal, resultCalThreshold, nbtotal, nbok);200 }201 jsonResponse.put("messageType", "OK");202 jsonResponse.put("message", "CI result calculated with success.");203 jsonResponse.put("tag", tag);204 jsonResponse.put("CI_OK_prio1", pond1);205 jsonResponse.put("CI_OK_prio2", pond2);206 jsonResponse.put("CI_OK_prio3", pond3);207 jsonResponse.put("CI_OK_prio4", pond4);208 jsonResponse.put("CI_OK_prio5", pond5);209 jsonResponse.put("CI_finalResult", resultCal);210 jsonResponse.put("CI_finalResultThreshold", resultCalThreshold);211 jsonResponse.put("NonOK_prio1_nbOfExecution", nbkop1);212 jsonResponse.put("NonOK_prio2_nbOfExecution", nbkop2);213 jsonResponse.put("NonOK_prio3_nbOfExecution", nbkop3);214 jsonResponse.put("NonOK_prio4_nbOfExecution", nbkop4);215 jsonResponse.put("NonOK_prio5_nbOfExecution", nbkop5);216 jsonResponse.put("status_OK_nbOfExecution", nbok);217 jsonResponse.put("status_KO_nbOfExecution", nbko);218 jsonResponse.put("status_FA_nbOfExecution", nbfa);219 jsonResponse.put("status_PE_nbOfExecution", nbpe);220 jsonResponse.put("status_NA_nbOfExecution", nbna);221 jsonResponse.put("status_CA_nbOfExecution", nbca);222 jsonResponse.put("status_NE_nbOfExecution", nbne);223 jsonResponse.put("status_WE_nbOfExecution", nbwe);224 jsonResponse.put("status_QU_nbOfExecution", nbqu);225 jsonResponse.put("status_QE_nbOfExecution", nbqe);226 jsonResponse.put("TOTAL_nbOfExecution", nbtotal);227 jsonResponse.put("result", result);228 jsonResponse.put("ExecutionStart", String.valueOf(new Timestamp(longStart)));229 jsonResponse.put("ExecutionEnd", String.valueOf(new Timestamp(longEnd)));230 return jsonResponse;231 } catch (JSONException ex) {232 LOG.error(ex, ex);233 }234 return null;235 }236 @Override237 public String getFinalResult(int resultCal, int resultCalThreshold, int nbtotal, int nbok) {238 if ((resultCal < resultCalThreshold) && (nbtotal > 0) && nbok > 0) {239 return "OK";240 } else {241 return "KO";242 }243 }244 private JSONArray generateEnvList(List<TestCaseExecution> testCaseExecutions) throws JSONException {245 JSONArray jsonResult = new JSONArray();246 HashMap<String, String> statMap = new HashMap<String, String>();247 for (TestCaseExecution testCaseExecution : testCaseExecutions) {248 if (!StringUtil.isNullOrEmpty(testCaseExecution.getEnvironment())) {249 statMap.put(testCaseExecution.getEnvironment(), null);250 }251 }252 for (Map.Entry<String, String> entry : statMap.entrySet()) {253 String key = entry.getKey();254 String value = entry.getValue();255 jsonResult.put(key);256 }257 return jsonResult;258 }259 private JSONArray generateCountryList(List<TestCaseExecution> testCaseExecutions) throws JSONException {260 JSONArray jsonResult = new JSONArray();261 HashMap<String, String> statMap = new HashMap<String, String>();262 for (TestCaseExecution testCaseExecution : testCaseExecutions) {263 if (!StringUtil.isNullOrEmpty(testCaseExecution.getCountry())) {264 statMap.put(testCaseExecution.getCountry(), null);265 }266 }267 for (Map.Entry<String, String> entry : statMap.entrySet()) {268 String key = entry.getKey();269 String value = entry.getValue();270 jsonResult.put(key);271 }272 return jsonResult;273 }274 private JSONArray generateRobotDecliList(List<TestCaseExecution> testCaseExecutions) throws JSONException {275 JSONArray jsonResult = new JSONArray();276 HashMap<String, String> statMap = new HashMap<String, String>();277 for (TestCaseExecution testCaseExecution : testCaseExecutions) {278 if (!StringUtil.isNullOrEmpty(testCaseExecution.getRobotDecli())) {279 statMap.put(testCaseExecution.getRobotDecli(), null);280 }281 }282 for (Map.Entry<String, String> entry : statMap.entrySet()) {283 String key = entry.getKey();284 String value = entry.getValue();285 jsonResult.put(key);286 }287 return jsonResult;288 }289 private JSONArray generateSystemList(List<TestCaseExecution> testCaseExecutions) throws JSONException {290 JSONArray jsonResult = new JSONArray();291 HashMap<String, String> statMap = new HashMap<String, String>();292 for (TestCaseExecution testCaseExecution : testCaseExecutions) {293 if (!StringUtil.isNullOrEmpty(testCaseExecution.getSystem())) {294 statMap.put(testCaseExecution.getSystem(), null);295 }296 }297 for (Map.Entry<String, String> entry : statMap.entrySet()) {298 String key = entry.getKey();299 String value = entry.getValue();300 jsonResult.put(key);301 }302 return jsonResult;303 }304 private JSONArray generateApplicationList(List<TestCaseExecution> testCaseExecutions) throws JSONException {305 JSONArray jsonResult = new JSONArray();306 HashMap<String, String> statMap = new HashMap<String, String>();307 for (TestCaseExecution testCaseExecution : testCaseExecutions) {308 if (!StringUtil.isNullOrEmpty(testCaseExecution.getApplication())) {309 statMap.put(testCaseExecution.getApplication(), null);310 }311 }312 for (Map.Entry<String, String> entry : statMap.entrySet()) {313 String key = entry.getKey();314 String value = entry.getValue();315 jsonResult.put(key);316 }317 return jsonResult;318 }319 private JSONArray generateStats(List<TestCaseExecution> testCaseExecutions) throws JSONException {320 JSONObject jsonResult = new JSONObject();321 HashMap<String, SummaryStatisticsDTO> statMap = new HashMap<String, SummaryStatisticsDTO>();322 for (TestCaseExecution testCaseExecution : testCaseExecutions) {323 StringBuilder key = new StringBuilder();324 key.append(testCaseExecution.getEnvironment());325 key.append("_");326 key.append(testCaseExecution.getCountry());327 key.append("_");328 key.append(testCaseExecution.getRobotDecli());329 key.append("_");330 key.append(testCaseExecution.getApplication());331 SummaryStatisticsDTO stat = new SummaryStatisticsDTO();332 stat.setEnvironment(testCaseExecution.getEnvironment());333 stat.setCountry(testCaseExecution.getCountry());...
generateStats
Using AI Code Generation
1import org.cerberus.service.ciresult.impl.CIService;2import org.cerberus.service.ciresult.impl.CIService;3import org.cerberus.service.ciresult.impl.CIService;4def ciService = new CIService();5ciService.generateStats();6ciService.generateStats('APP1');7ciService.generateStats('APP1','CAMPAIGN1');8ciService.generateStats('APP1','CAMPAIGN1','TEST1');9ciService.generateStats('APP1','CAMPAIGN1','TEST1','FR');10ciService.generateStats('APP1','CAMPAIGN1','TEST1','FR','QA');11ciService.generateStats('APP1','CAMPAIGN1','TEST1','FR','QA','Chrome');
generateStats
Using AI Code Generation
1CIService ciService = new CIService();2ciService.generateStats("TC1");3CIService ciService = new CIService();4ciService.generateStats("TC1");5CIService ciService = new CIService();6ciService.generateStats("TC1");7CIService ciService = new CIService();8ciService.generateStats("TC1");9CIService ciService = new CIService();10ciService.generateStats("TC1");11CIService ciService = new CIService();12ciService.generateStats("TC1");13CIService ciService = new CIService();14ciService.generateStats("TC1");
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!