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

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

Source:ResultCI.java Github

copy

Full Screen

...45@WebServlet(name = "ResultCI", urlPatterns = {"/ResultCI"})46public class ResultCI extends HttpServlet {47 48 private static final Logger LOG = LogManager.getLogger(ResultCI.class);49 protected void processRequest(HttpServletRequest request,50 HttpServletResponse response) throws ServletException, IOException {51 PrintWriter out = response.getWriter();52 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);53 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());54 /**55 * Adding Log entry.56 */57 ILogEventService logEventService = appContext.getBean(ILogEventService.class);58 logEventService.createForPublicCalls("/ResultCI", "CALL", "ResultCI called : " + request.getRequestURL(), request);59 String tag = policy.sanitize(request.getParameter("tag"));60 String helpMessage = "\nThis servlet is used to profide a global OK or KO based on the number and status of the execution done on a specific tag.\n"61 + "The number of executions are ponderated by parameters by priority from cerberus_ci_okcoefprio1 to cerberus_ci_okcoefprio4.\n"62 + "Formula used is the following :\n"63 + "Nb Exe Prio 1 testcases * cerberus_ci_okcoefprio1 + Nb Exe Prio 2 testcases * cerberus_ci_okcoefprio2 +\n"64 + " Nb Exe Prio 3 testcases * cerberus_ci_okcoefprio3 + Nb Exe Prio 4 testcases * cerberus_ci_okcoefprio4\n\n"65 + "If not executions are found, the result is KO.\n"66 + "With at least 1 execution, if result is < 1 then global servlet result is OK. If not, it is KO.\n"67 + "All execution needs to have a status equal to KO, FA, NA or PE.\n\n"68 + "Parameter list :\n"69 + "- tag [mandatory] : Execution Tag to filter the test cases execution. [" + tag + "]\n";70 DatabaseSpring database = appContext.getBean(DatabaseSpring.class);71 Connection connection = database.connect();72 try {73 boolean error = false;74 // Checking the parameter validity. Tag is a mandatory parameter75 if (StringUtils.isBlank(tag)) {76 out.println("Error - Parameter tag is mandatory.");77 error = true;78 }79 if (!error) {80 PreparedStatement prepStmt = connection.prepareStatement("SELECT count(*) AS NBKOP1 "81 + "FROM testcaseexecution t "82 + "JOIN "83 + "(SELECT Test,TestCase, Priority FROM testcase)b "84 + "ON b.test= t.test AND b.testcase=t.testcase "85 + "WHERE controlStatus not in ('OK') AND priority = '1' "86 + "AND tag = ?");87 int nbkop1 = 0;88 try {89 prepStmt.setString(1, tag);90 ResultSet rs_resultp1 = prepStmt.executeQuery();91 try {92 if (rs_resultp1.first()) {93 nbkop1 = Integer.valueOf(rs_resultp1.getString("NBKOP1"));94 }95 } finally {96 rs_resultp1.close();97 }98 } finally {99 prepStmt.close();100 }101 PreparedStatement prepStmt2 = connection.prepareStatement("SELECT count(*) AS NBKOP2 "102 + "FROM testcaseexecution t "103 + "JOIN "104 + "(SELECT Test,TestCase, Priority FROM testcase)b "105 + "ON b.test= t.test AND b.testcase=t.testcase "106 + "WHERE controlStatus not in ('OK') AND priority = '2' "107 + "AND tag = ?");108 int nbkop2 = 0;109 try {110 prepStmt2.setString(1, tag);111 ResultSet rs_resultp2 = prepStmt2.executeQuery();112 try {113 if (rs_resultp2.first()) {114 nbkop2 = Integer.valueOf(rs_resultp2.getString("NBKOP2"));115 }116 } finally {117 rs_resultp2.close();118 }119 } finally {120 prepStmt2.close();121 }122 PreparedStatement prepStmt3 = connection.prepareStatement("SELECT count(*) AS NBKOP3 "123 + "FROM testcaseexecution t "124 + "JOIN "125 + "(SELECT Test,TestCase, Priority FROM testcase)b "126 + "ON b.test= t.test AND b.testcase=t.testcase "127 + "WHERE controlStatus not in ('OK') AND priority = '3' "128 + "AND tag = ?");129 int nbkop3 = 0;130 try {131 prepStmt3.setString(1, tag);132 ResultSet rs_resultp3 = prepStmt3.executeQuery();133 try {134 if (rs_resultp3.first()) {135 nbkop3 = Integer.valueOf(rs_resultp3.getString("NBKOP3"));136 }137 } finally {138 rs_resultp3.close();139 }140 } finally {141 prepStmt3.close();142 }143 PreparedStatement prepStmt4 = connection.prepareStatement("SELECT count(*) AS NBKOP4 "144 + "FROM testcaseexecution t "145 + "JOIN "146 + "(SELECT Test,TestCase, Priority FROM testcase)b "147 + "ON b.test= t.test AND b.testcase=t.testcase "148 + "WHERE controlStatus not in ('OK') AND priority = '4' "149 + "AND tag = ?");150 int nbkop4 = 0;151 try {152 prepStmt4.setString(1, tag);153 ResultSet rs_resultp4 = prepStmt4.executeQuery();154 try {155 if (rs_resultp4.first()) {156 nbkop4 = Integer.valueOf(rs_resultp4.getString("NBKOP4"));157 }158 } finally {159 rs_resultp4.close();160 }161 } finally {162 prepStmt4.close();163 }164 IParameterService parameterService = appContext.getBean(IParameterService.class);165 float pond1 = Float.valueOf(parameterService.findParameterByKey("cerberus_ci_okcoefprio1", "").getValue());166 float pond2 = Float.valueOf(parameterService.findParameterByKey("cerberus_ci_okcoefprio2", "").getValue());167 float pond3 = Float.valueOf(parameterService.findParameterByKey("cerberus_ci_okcoefprio3", "").getValue());168 float pond4 = Float.valueOf(parameterService.findParameterByKey("cerberus_ci_okcoefprio4", "").getValue());169 String result;170 float resultCal = (nbkop1 * pond1) + (nbkop2 * pond2) + (nbkop3 * pond3) + (nbkop4 * pond4);171 if (resultCal < 1) {172 result = "OK";173 } else {174 result = "KO";175 }176 out.print(result);177 // Log the result with calculation detail.178 logEventService.createForPublicCalls("/ResultCI", "CALLRESULT", "ResultCI calculated with result [" + result + "] : " + nbkop1 + "*" + pond1 + " + " + nbkop2 + "*" + pond2 + " + " + nbkop3 + "*" + pond3 + " + " + nbkop4 + "*" + pond4 + " = " + resultCal, request);179 } else {180 // In case of errors, we display the help message.181 out.println(helpMessage);182 }183 } catch (Exception e) {184 out.println(e.getMessage());185 } finally {186 out.close();187 try {188 if (connection != null) {189 connection.close();190 }191 } catch (SQLException e) {192 LOG.warn(e.toString());193 }194 }195 }196 // <editor-fold defaultstate="collapsed"197 // desc="HttpServlet methods. Click on the + sign on the left to edit the code.">198 /**199 * Handles the HTTP200 * <code>GET</code> method.201 *202 * @param request servlet request203 * @param response servlet response204 * @throws ServletException if a servlet-specific error occurs205 * @throws IOException if an I/O error occurs206 */207 @Override208 protected void doGet(HttpServletRequest request,209 HttpServletResponse response) throws ServletException, IOException {210 processRequest(request, response);211 }212 /**213 * Handles the HTTP214 * <code>POST</code> method.215 *216 * @param request servlet request217 * @param response servlet response218 * @throws ServletException if a servlet-specific error occurs219 * @throws IOException if an I/O error occurs220 */221 @Override222 protected void doPost(HttpServletRequest request,223 HttpServletResponse response) throws ServletException, IOException {224 processRequest(request, response);225 }226 /**227 * Returns a short description of the servlet.228 *229 * @return a String containing servlet description230 */231 @Override232 public String getServletInfo() {233 return "Short description";234 }// </editor-fold>235}...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import groovy.json.JsonBuilder2import groovy.json.JsonSlurper3import org.cerberus.servlet.zzpublic.ResultCI4import org.cerberus.servlet.zzpublic.ResultCI5import org.cerberus.engine.entity.MessageEvent6def resultCI = new ResultCI()7def result = resultCI.processRequest(request, response)8if (result instanceof MessageEvent) {9 response.sendError(500, result.getDescription())10} else {11 def json = new JsonBuilder(result)12 response.writer << json.toString()13}

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.zzpublic.ResultCI;2import org.cerberus.servlet.zzpublic.ResultCIFactory;3String campaignName = request.getParameter("campaignName");4ResultCI result = ResultCIFactory.getResultCI(campaignName);5int nbExecuted = result.getNbExecuted();6int nbPassed = result.getNbPassed();7int nbFailed = result.getNbFailed();8int nbBlocked = result.getNbBlocked();9int nbNotExecuted = result.getNbNotExecuted();10int nbNotApplicable = result.getNbNotApplicable();11int nbTotal = result.getNbTotal();12int percentPassed = result.getPercentPassed();13int percentFailed = result.getPercentFailed();14int percentBlocked = result.getPercentBlocked();15int percentNotExecuted = result.getPercentNotExecuted();16int percentNotApplicable = result.getPercentNotApplicable();17int percentTotal = result.getPercentTotal();18String status = result.getStatus();19String statusHTML = result.getStatusHTML();20String statusHTMLColor = result.getStatusHTMLColor();21String statusHTMLColorSize = result.getStatusHTMLColorSize();

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.zzpublic.ResultCI;2String result = ResultCI.processRequest(request);3URL url = new URL(slackUrl);4HttpURLConnection http = (HttpURLConnection)url.openConnection();5http.setRequestMethod("POST");6http.setRequestProperty("Content-Type", "application/json");7http.setDoOutput(true);8String json = "{\"text\":\""+result+"\"}";9byte[] out = json.getBytes(StandardCharsets.UTF_8);10OutputStream stream = http.getOutputStream();11stream.write(out);12http.getResponseCode();13http.disconnect();

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.

Most used method in ResultCI

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful