How to use processRequest method of org.cerberus.servlet.zzpublic.ResultCIV002 class

Best Cerberus-source code snippet using org.cerberus.servlet.zzpublic.ResultCIV002.processRequest

Source:ResultCIV002.java Github

copy

Full Screen

...51@WebServlet(name = "ResultCIV002", urlPatterns = {"/ResultCIV002"})52public class ResultCIV002 extends HttpServlet {53 54 private static Logger LOG = LogManager.getLogger(ResultCIV002.class);55 protected void processRequest(HttpServletRequest request,56 HttpServletResponse response) throws ServletException, IOException {57 58 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());59 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);60 // Calling Servlet Transversal Util.61 ServletUtil.servletStart(request);62 /**63 * Adding Log entry.64 */65 ILogEventService logEventService = appContext.getBean(ILogEventService.class);66 logEventService.createForPublicCalls("/ResultCIV002", "CALL", "ResultCIV002 called : " + request.getRequestURL(), request);67 try {68 JSONObject jsonResponse = new JSONObject();69 String tag = policy.sanitize(request.getParameter("tag"));70 String outputFormat = policy.sanitize(request.getParameter("outputFormat"));71 String helpMessage = "This servlet is used to provide various execution counters as well as a global OK or KO status based on the number and status of the execution done on a specific tag. "72 + "The number of executions are ponderated by parameters by priority from cerberus_ci_okcoefprio1 to cerberus_ci_okcoefprio4. "73 + "Formula used is the following : "74 + "Nb Exe Prio 1 testcases * cerberus_ci_okcoefprio1 + Nb Exe Prio 2 testcases * cerberus_ci_okcoefprio2 + "75 + "Nb Exe Prio 3 testcases * cerberus_ci_okcoefprio3 + Nb Exe Prio 4 testcases * cerberus_ci_okcoefprio4."76 + "If no executions are found, the result is KO."77 + "With at least 1 execution, if result is < 1 then global servlet result is OK. If not, it is KO."78 + "All execution needs to have a status equal to KO, FA, NA, PE or NE."79 + "If at least 1 PE or 1 NE if found, global status will be PE"80 + "Output format is json by default, or SVG if outputFormat=svg is defined"81 + "Parameter list :"82 + "- tag [mandatory] : Execution Tag to filter the test cases execution. [" + tag + "]"83 + "- outputFormat : ['json', 'svg']. Output format of the result. [" + outputFormat + "]";84 boolean error = false;85 String error_message = "";86 // Checking the parameter validity. Tag is a mandatory parameter87 if (StringUtils.isBlank(tag)) {88 error_message = "Error - Parameter tag is mandatory.";89 error = true;90 }91 // Checking the parameter validity. outputFormat can be empty, or equals to json or svg92 if (!StringUtils.isBlank(outputFormat) && !outputFormat.equals("json")93 && !outputFormat.equals("svg")) {94 error_message = "Error - Value of parameter outputFormat is not recognized.";95 error = true;96 }97 if (!error) {98 ITestCaseExecutionService testExecutionService = appContext.getBean(TestCaseExecutionService.class);99 List<TestCaseExecution> myList;100 int nbok = 0;101 int nbko = 0;102 int nbfa = 0;103 int nbpe = 0;104 int nbne = 0;105 int nbna = 0;106 int nbca = 0;107 int nbqu = 0;108 int nbtotal = 0;109 int nbkop1 = 0;110 int nbkop2 = 0;111 int nbkop3 = 0;112 int nbkop4 = 0;113 long longStart = 0;114 long longEnd = 0;115 try {116 myList = testExecutionService.readLastExecutionAndExecutionInQueueByTag(tag);117 for (TestCaseExecution curExe : myList) {118 if (longStart == 0) {119 longStart = curExe.getStart();120 }121 if (curExe.getStart() < longStart) {122 longStart = curExe.getStart();123 }124 if (longEnd == 0) {125 longEnd = curExe.getEnd();126 }127 if (curExe.getEnd() > longEnd) {128 longEnd = curExe.getEnd();129 }130 nbtotal++;131 switch (curExe.getControlStatus()) {132 case TestCaseExecution.CONTROLSTATUS_KO:133 nbko++;134 break;135 case TestCaseExecution.CONTROLSTATUS_OK:136 nbok++;137 break;138 case TestCaseExecution.CONTROLSTATUS_FA:139 nbfa++;140 break;141 case TestCaseExecution.CONTROLSTATUS_NA:142 nbna++;143 break;144 case TestCaseExecution.CONTROLSTATUS_CA:145 nbca++;146 break;147 case TestCaseExecution.CONTROLSTATUS_PE:148 nbpe++;149 break;150 case TestCaseExecution.CONTROLSTATUS_NE:151 nbne++;152 break;153 case TestCaseExecution.CONTROLSTATUS_QU:154 nbqu++;155 break;156 }157 if (!curExe.getControlStatus().equals("OK") && !curExe.getControlStatus().equals("NE")158 && !curExe.getControlStatus().equals("PE") && !curExe.getControlStatus().equals("QU")) {159 switch (curExe.getTestCaseObj().getPriority()) {160 case 1:161 nbkop1++;162 break;163 case 2:164 nbkop2++;165 break;166 case 3:167 nbkop3++;168 break;169 case 4:170 nbkop4++;171 break;172 }173 }174 }175 } catch (CerberusException ex) {176 LOG.warn(ex);177 } catch (ParseException ex) {178 LOG.warn(ex);179 }180 IParameterService parameterService = appContext.getBean(IParameterService.class);181 float pond1 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio1", "", 0);182 float pond2 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio2", "", 0);183 float pond3 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio3", "", 0);184 float pond4 = parameterService.getParameterFloatByKey("cerberus_ci_okcoefprio4", "", 0);185 String result;186 float resultCal = (nbkop1 * pond1) + (nbkop2 * pond2) + (nbkop3 * pond3) + (nbkop4 * pond4);187 if ((nbtotal > 0) && nbqu + nbne + nbpe > 0) {188 result = "PE";189 } else if ((resultCal < 1) && (nbtotal > 0)) {190 result = "OK";191 } else {192 result = "KO";193 }194 jsonResponse.put("messageType", "OK");195 jsonResponse.put("message", "CI result calculated with success.");196 jsonResponse.put("tag", tag);197 jsonResponse.put("CI_OK_prio1", pond1);198 jsonResponse.put("CI_OK_prio2", pond2);199 jsonResponse.put("CI_OK_prio3", pond3);200 jsonResponse.put("CI_OK_prio4", pond4);201 jsonResponse.put("CI_finalResult", resultCal);202 jsonResponse.put("NonOK_prio1_nbOfExecution", nbkop1);203 jsonResponse.put("NonOK_prio2_nbOfExecution", nbkop2);204 jsonResponse.put("NonOK_prio3_nbOfExecution", nbkop3);205 jsonResponse.put("NonOK_prio4_nbOfExecution", nbkop4);206 jsonResponse.put("status_OK_nbOfExecution", nbok);207 jsonResponse.put("status_KO_nbOfExecution", nbko);208 jsonResponse.put("status_FA_nbOfExecution", nbfa);209 jsonResponse.put("status_PE_nbOfExecution", nbpe);210 jsonResponse.put("status_NA_nbOfExecution", nbna);211 jsonResponse.put("status_CA_nbOfExecution", nbca);212 jsonResponse.put("status_NE_nbOfExecution", nbne);213 jsonResponse.put("status_QU_nbOfExecution", nbqu);214 jsonResponse.put("TOTAL_nbOfExecution", nbtotal);215 jsonResponse.put("result", result);216 jsonResponse.put("ExecutionStart", String.valueOf(new Timestamp(longStart)));217 jsonResponse.put("ExecutionEnd", String.valueOf(new Timestamp(longEnd)));218 generateResponse(response, outputFormat, jsonResponse, false);219 // Log the result with calculation detail.220 logEventService.createForPublicCalls("/ResultCIV002", "CALLRESULT", "ResultCIV002 calculated with result [" + result + "] : " + nbkop1 + "*" + pond1 + " + " + nbkop2 + "*" + pond2 + " + " + nbkop3 + "*" + pond3 + " + " + nbkop4 + "*" + pond4 + " = " + resultCal, request);221 } else {222 jsonResponse.put("messageType", "KO");223 jsonResponse.put("message", error_message);224 jsonResponse.put("helpMessage", helpMessage);225 generateResponse(response, outputFormat, jsonResponse, true);226 }227 } catch (JSONException e) {228 LOG.warn(e);229 //returns a default error message with the json format that is able to be parsed by the client-side230 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());231 }232 }233 // <editor-fold defaultstate="collapsed"234 // desc="HttpServlet methods. Click on the + sign on the left to edit the code.">235 /**236 * Handles the HTTP <code>GET</code> method.237 *238 * @param request servlet request239 * @param response servlet response240 * @throws ServletException if a servlet-specific error occurs241 * @throws IOException if an I/O error occurs242 */243 @Override244 protected void doGet(HttpServletRequest request,245 HttpServletResponse response) throws ServletException, IOException {246 processRequest(request, response);247 }248 /**249 * Handles the HTTP <code>POST</code> method.250 *251 * @param request servlet request252 * @param response servlet response253 * @throws ServletException if a servlet-specific error occurs254 * @throws IOException if an I/O error occurs255 */256 @Override257 protected void doPost(HttpServletRequest request,258 HttpServletResponse response) throws ServletException, IOException {259 processRequest(request, response);260 }261 /**262 * Returns a short description of the servlet.263 *264 * @return a String containing servlet description265 */266 @Override267 public String getServletInfo() {268 return "Short description";269 }// </editor-fold>270 private void generateResponse(HttpServletResponse response, String outputFormat, JSONObject jsonResponse, boolean error) throws IOException {271 if (StringUtils.isBlank(outputFormat) || outputFormat.equals("json") || error) {272 response.setContentType("application/json");273 response.setCharacterEncoding("utf8");...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1String result = org.cerberus.servlet.zzpublic.ResultCIV002.processRequest(request, response);2org.json.JSONObject json = new org.json.JSONObject(result);3org.json.JSONObject version = json.getJSONObject("version");4String appVersion = version.getString("version");5String appBuild = version.getString("build");6String appDate = version.getString("date");7org.json.JSONObject testcase = json.getJSONObject("testcase");8String test = testcase.getString("test");9String testcase = testcase.getString("testcase");10String description = testcase.getString("description");11String status = testcase.getString("status");12String country = testcase.getString("country");13String environment = testcase.getString("environment");14String browser = testcase.getString("browser");15String browserVersion = testcase.getString("version");16String platform = testcase.getString("platform");17String robot = testcase.getString("robot");18String robotIP = testcase.getString("robotIP");19String robotPort = testcase.getString("robotPort");20String application = testcase.getString("application");21String applicationObj = testcase.getString("applicationObj");22String applicationIP = testcase.getString("applicationIP");23String applicationPort = testcase.getString("applicationPort");24String applicationURL = testcase.getString("applicationURL");25String applicationPath = testcase.getString("applicationPath");26String screenshot = testcase.getString("screenshot");27String controlStatus = testcase.getString("controlStatus");28String controlMessage = testcase.getString("controlMessage");

Full Screen

Full Screen

Automation Testing Tutorials

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.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run Cerberus-source automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful