How to use processRequest method of org.cerberus.servlet.manualtestcase.DeleteTestCaseExecutionFile class

Best Cerberus-source code snippet using org.cerberus.servlet.manualtestcase.DeleteTestCaseExecutionFile.processRequest

Source:DeleteTestCaseExecutionFile.java Github

copy

Full Screen

...69 * @param response servlet response70 * @throws ServletException if a servlet-specific error occurs71 * @throws IOException if an I/O error occurs72 */73 protected void processRequest(HttpServletRequest request, HttpServletResponse response)74 throws ServletException, IOException, JSONException, CerberusException {75 JSONObject jsonResponse = new JSONObject();76 Answer ans = new Answer();77 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);78 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));79 ans.setResultMessage(msg);80 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);81 82 response.setContentType("application/json");83 // Calling Servlet Transversal Util.84 ServletUtil.servletStart(request);85 86 /**87 * Parsing and securing all required parameters.88 */89 Long fileId = ParameterParserUtil.parseLongParam(request.getParameter("fileID"), 0);90 91 /**92 * Checking all constrains before calling the services.93 */94 if (fileId == null) {95 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);96 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionFile")97 .replace("%OPERATION%", "Delete")98 .replace("%REASON%", "field fileID is missing!"));99 ans.setResultMessage(msg);100 } else {101 /**102 * All data seems cleans so we can call the services.103 */104 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());105 ITestCaseExecutionFileService testCaseExecutionFileService = appContext.getBean(ITestCaseExecutionFileService.class);106 IParameterService parameterService = appContext.getBean(IParameterService.class);107 IRecorderService recorderService = appContext.getBean(IRecorderService.class);108 AnswerItem resp = testCaseExecutionFileService.readByKey(fileId);109 110 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem()!=null)) {111 /**112 * Object could not be found. We stop here and report the error.113 */114 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);115 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCaseExecutionFile")116 .replace("%OPERATION%", "Delete")117 .replace("%REASON%", "TestCaseExecutionFile with this ID does not exist."));118 ans.setResultMessage(msg);119 } else {120 /**121 * The service was able to perform the query and confirm the122 * object exist, then we can delete it.123 */124 TestCaseExecutionFile testCaseExecutionFile = (TestCaseExecutionFile) resp.getItem();125 String rootFolder = parameterService.getParameterStringByKey("cerberus_exemanualmedia_path", "", "");126 testCaseExecutionFileService.deleteFile(rootFolder,testCaseExecutionFile.getFileName());127 128 ans = testCaseExecutionFileService.delete(testCaseExecutionFile);129 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {130 /**131 * Delete was successful. Adding Log entry.132 */133 ILogEventService logEventService = appContext.getBean(LogEventService.class);134 logEventService.createForPrivateCalls("/DeleteTestCaseExecutionFile", "DELETE", "Delete TestCase Execution File : ['" + testCaseExecutionFile + "']", request);135 }136 }137 }138 /**139 * Formating and returning the json result.140 */141 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());142 jsonResponse.put("message", ans.getResultMessage().getDescription());143 response.getWriter().print(jsonResponse.toString());144 response.getWriter().flush();145 }146 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">147 /**148 * Handles the HTTP <code>GET</code> method.149 *150 * @param request servlet request151 * @param response servlet response152 * @throws ServletException if a servlet-specific error occurs153 * @throws IOException if an I/O error occurs154 */155 @Override156 protected void doGet(HttpServletRequest request, HttpServletResponse response)157 throws ServletException, IOException {158 try {159 processRequest(request, response);160 } catch (JSONException ex) {161 LOG.warn(ex);162 } catch (CerberusException ex) {163 LOG.warn(ex);164 }165 }166 /**167 * Handles the HTTP <code>POST</code> method.168 *169 * @param request servlet request170 * @param response servlet response171 * @throws ServletException if a servlet-specific error occurs172 * @throws IOException if an I/O error occurs173 */174 @Override175 protected void doPost(HttpServletRequest request, HttpServletResponse response)176 throws ServletException, IOException {177 try {178 processRequest(request, response);179 } catch (JSONException ex) {180 LOG.warn(ex);181 } catch (CerberusException ex) {182 LOG.warn(ex);183 }184 }185 /**186 * Returns a short description of the servlet.187 *188 * @return a String containing servlet description189 */190 @Override191 public String getServletInfo() {192 return "Short description";...

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 DeleteTestCaseExecutionFile

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful