How to use processRequest method of org.cerberus.servlet.crud.test.testcase.DeleteTestCase class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.test.testcase.DeleteTestCase.processRequest

Source:DeleteTestCase.java Github

copy

Full Screen

...63 * @param response servlet response64 * @throws ServletException if a servlet-specific error occurs65 * @throws IOException if an I/O error occurs66 */67 protected void processRequest(HttpServletRequest request, HttpServletResponse response)68 throws ServletException, IOException, JSONException, CerberusException {69 JSONObject jsonResponse = new JSONObject();70 Answer ans = new Answer();71 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);72 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));73 ans.setResultMessage(msg);74 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);75 response.setContentType("application/json");76 // Calling Servlet Transversal Util.77 ServletUtil.servletStart(request);78 79 /**80 * Parsing and securing all required parameters.81 */82 String test = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("test"), "");83 String testCase = ParameterParserUtil.parseStringParamAndSanitize(request.getParameter("testCase"), null);84 /**85 * Checking all constrains before calling the services.86 */87 if (StringUtil.isNullOrEmpty(test) || testCase == null) {88 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);89 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")90 .replace("%OPERATION%", "Delete")91 .replace("%REASON%", "mendatory fields is missing!"));92 ans.setResultMessage(msg);93 } else {94 /**95 * All data seems cleans so we can call the services.96 */97 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());98 ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);99 ITestCaseStepService testCaseStepService = appContext.getBean(ITestCaseStepService.class);100 AnswerItem resp = testCaseService.readByKey(test, testCase);101 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem()!=null)) {102 /**103 * Object could not be found. We stop here and report the error.104 */105 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);106 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")107 .replace("%OPERATION%", "Delete")108 .replace("%REASON%", "TestCase does not exist."));109 ans.setResultMessage(msg);110 } else {111 /**112 * The service was able to perform the query and confirm the113 * object exist, then we can delete it.114 */115 TestCase testCaseData = (TestCase) resp.getItem();116 List<TestCaseStep> tcsList = testCaseStepService.getTestCaseStepUsingTestCaseInParamter(testCaseData.getTest(), testCaseData.getTestCase());117 if (tcsList != null && !tcsList.isEmpty()) {118 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);119 msg.setDescription(msg.getDescription().replace("%ITEM%", "TestCase")120 .replace("%OPERATION%", "Delete")121 .replace("%REASON%", "You're trying to delete a testcase which have some step used in other tests. Please remove the link before deleting this testcase."));122 ans.setResultMessage(msg);123 } else {124 ans = testCaseService.delete(testCaseData);125 }126 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {127 /**128 * Delete was successful. Adding Log entry.129 */130 ILogEventService logEventService = appContext.getBean(LogEventService.class);131 logEventService.createForPrivateCalls("/DeleteTestCase", "DELETE", "Delete TestCase : ['" + testCase + "']", request);132 }133 }134 }135 /**136 * Formating and returning the json result.137 */138 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());139 jsonResponse.put("message", ans.getResultMessage().getDescription());140 response.getWriter().print(jsonResponse.toString());141 response.getWriter().flush();142 }143 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">144 /**145 * Handles the HTTP <code>GET</code> method.146 *147 * @param request servlet request148 * @param response servlet response149 * @throws ServletException if a servlet-specific error occurs150 * @throws IOException if an I/O error occurs151 */152 @Override153 protected void doGet(HttpServletRequest request, HttpServletResponse response)154 throws ServletException, IOException {155 try {156 processRequest(request, response);157 } catch (JSONException ex) {158 LOG.warn(ex);159 } catch (CerberusException ex) {160 LOG.warn(ex);161 }162 }163 /**164 * Handles the HTTP <code>POST</code> method.165 *166 * @param request servlet request167 * @param response servlet response168 * @throws ServletException if a servlet-specific error occurs169 * @throws IOException if an I/O error occurs170 */171 @Override172 protected void doPost(HttpServletRequest request, HttpServletResponse response)173 throws ServletException, IOException {174 try {175 processRequest(request, response);176 } catch (JSONException ex) {177 LOG.warn(ex);178 } catch (CerberusException ex) {179 LOG.warn(ex);180 }181 }182 /**183 * Returns a short description of the servlet.184 *185 * @return a String containing servlet description186 */187 @Override188 public String getServletInfo() {189 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 DeleteTestCase

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful