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

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

Source:UpdateTestCaseMass.java Github

copy

Full Screen

...59 * @param response servlet response60 * @throws ServletException if a servlet-specific error occurs61 * @throws IOException if an I/O error occurs62 */63 protected void processRequest(HttpServletRequest request, HttpServletResponse response)64 throws ServletException, IOException, CerberusException, JSONException {65 JSONObject jsonResponse = new JSONObject();66 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());67 ILogEventService logEventService = appContext.getBean(LogEventService.class);68 Answer ans = new Answer();69 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);70 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));71 ans.setResultMessage(msg);72 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);73 String charset = request.getCharacterEncoding();74 response.setContentType("application/json");75 // Calling Servlet Transversal Util.76 ServletUtil.servletStart(request);77 ITestCaseService testCaseService = appContext.getBean(ITestCaseService.class);78 /**79 * Parsing and securing all required parameters.80 */81 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them82 // Parameter that needs to be secured --> We SECURE+DECODE them83 String function = request.getParameter("massFunction");84 String status = request.getParameter("massStatus");85 String application = request.getParameter("massApplication");86 // Parameter that we cannot secure as we need the html --> We DECODE them87 String[] myTest = request.getParameterValues("test");88 String[] myTestCase = request.getParameterValues("testcase");89 StringBuilder output_message = new StringBuilder();90 int massErrorCounter = 0;91 int tcCounter = 0;92 for (String myTest1 : myTest) {93 String cur_test = myTest1;94 String cur_testcase = myTestCase[tcCounter];95 /**96 * All data seems cleans so we can call the services.97 */98 AnswerItem resp = testCaseService.readByKey(cur_test, cur_testcase);99 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {100 /**101 * Object could not be found. We stop here and report the error.102 */103 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);104 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)105 .replace("%OPERATION%", "Update")106 .replace("%REASON%", "TestCase does not exist."));107 ans.setResultMessage(msg);108 massErrorCounter++;109 output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());110 } else {111 /**112 * The service was able to perform the query and confirm the113 * object exist, then we can update it.114 */115 TestCase tcData = (TestCase) resp.getItem();116 /**117 * Before updating, we check that the old entry can be modified.118 * If old entry point to a build/revision that already been119 * deployed, we cannot update it.120 */121 if (!testCaseService.hasPermissionsUpdate(tcData, request)) {122 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);123 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)124 .replace("%OPERATION%", "Update")125 .replace("%REASON%", "Not enought privilege to update the testcase. You must belong to Test Privilege or even TestAdmin in case the test is in WORKING status."));126 ans.setResultMessage(msg);127 massErrorCounter++;128 output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(msg.getDescription());129 } else // We test that at least a data to update has been defined.130 if ((function != null) || (status != null) || (application != null)) {131 tcData.setUsrModif(request.getRemoteUser());132 tcData.setFunction(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(function, tcData.getFunction(), charset));133 tcData.setStatus(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(status, tcData.getStatus(), charset));134 tcData.setApplication(ParameterParserUtil.parseStringParamAndDecodeAndSanitize(application, tcData.getApplication(), charset));135 ans = testCaseService.update(tcData.getTest(), tcData.getTestCase(), tcData);136 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {137 /**138 * Update was successful. Adding Log entry.139 */140 logEventService.createForPrivateCalls("/UpdateTestCaseMass", "UPDATE", "Updated TestCase : ['" + tcData.getTest() + "'|'" + tcData.getTestCase() + "']", request);141 } else {142 massErrorCounter++;143 output_message.append("<br>id : ").append(cur_test).append("|").append(cur_testcase).append(" - ").append(ans.getResultMessage().getDescription());144 }145 }146 }147 tcCounter++;148 }149 if (myTest.length > 1) {150 if (massErrorCounter == myTest.length) { // All updates are in ERROR.151 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);152 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)153 .replace("%OPERATION%", "Mass Update")154 .replace("%REASON%", massErrorCounter + " objects(s) out of " + myTest.length + " failed to update due to an issue.<br>") + output_message.toString());155 ans.setResultMessage(msg);156 } else if (massErrorCounter > 0) { // At least 1 update in error157 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_WARNING);158 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)159 .replace("%OPERATION%", "Mass Update")160 .replace("%REASON%", massErrorCounter + " objects(s) out of " + myTest.length + " failed to update due to an issue.<br>") + output_message.toString());161 ans.setResultMessage(msg);162 } else { // No error detected.163 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_OK);164 msg.setDescription(msg.getDescription().replace("%ITEM%", OBJECT_NAME)165 .replace("%OPERATION%", "Mass Update") + "\n\nAll " + myTest.length + " object(s) updated successfuly.");166 ans.setResultMessage(msg);167 }168 logEventService.createForPrivateCalls("/UpdateTestCaseMass", "MASSUPDATE", msg.getDescription(), request);169 }170 /**171 * Formating and returning the json result.172 */173 jsonResponse.put("messageType", ans.getResultMessage().getMessage().getCodeString());174 jsonResponse.put("message", ans.getResultMessage().getDescription());175 response.getWriter().print(jsonResponse);176 response.getWriter().flush();177 }178 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">179 /**180 * Handles the HTTP <code>GET</code> method.181 *182 * @param request servlet request183 * @param response servlet response184 * @throws ServletException if a servlet-specific error occurs185 * @throws IOException if an I/O error occurs186 */187 @Override188 protected void doGet(HttpServletRequest request, HttpServletResponse response)189 throws ServletException, IOException {190 try {191 processRequest(request, response);192 } catch (CerberusException ex) {193 LOG.warn(ex);194 } catch (JSONException ex) {195 LOG.warn(ex);196 }197 }198 /**199 * Handles the HTTP <code>POST</code> method.200 *201 * @param request servlet request202 * @param response servlet response203 * @throws ServletException if a servlet-specific error occurs204 * @throws IOException if an I/O error occurs205 */206 @Override207 protected void doPost(HttpServletRequest request, HttpServletResponse response)208 throws ServletException, IOException {209 try {210 processRequest(request, response);211 } catch (CerberusException ex) {212 LOG.warn(ex);213 } catch (JSONException ex) {214 LOG.warn(ex);215 }216 }217 /**218 * Returns a short description of the servlet.219 *220 * @return a String containing servlet description221 */222 @Override223 public String getServletInfo() {224 return "Short description";...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.crud.test;2import java.io.IOException;3import java.io.PrintWriter;4import java.util.ArrayList;5import java.util.HashMap;6import java.util.List;7import java.util.Map;8import java.util.logging.Level;9import java.util.logging.Logger;10import javax.servlet.ServletException;11import javax.servlet.http.HttpServlet;12import javax.servlet.http.HttpServletRequest;13import javax.servlet.http.HttpServletResponse;14import org.cerberus.crud.entity.TestCase;15import org.cerberus.crud.service.ITestCaseService;16import org.cerberus.crud.service.impl.TestCaseService;17import org.cerberus.engine.entity.MessageEvent;18import org.cerberus.engine.entity.MessageGeneral;19import org.cerberus.engine.entity.MessageGeneralEnum;20import org.cerberus.engine.entity.MessageEventEnum;21import org.cerberus.exception.CerberusException;22import org.cerberus.servlet.api.IHttpServlet;23import org.cerberus.servlet.crud.test.UpdateTestCaseMass;24import org.cerberus.util.answer.AnswerItem;25import org.cerberus.util.answer.AnswerList;26import org.cerberus.util.answer.AnswerUtil;27import org.springframework.context.ApplicationContext;28import org.springframework.web.context.support.WebApplicationContextUtils;29public class GetTestCaseList extends HttpServlet implements IHttpServlet {30 private static final long serialVersionUID = 1L;31 private static final Logger LOG = Logger.getLogger(GetTestCaseList.class.getName());32 private ITestCaseService testCaseService;33 * @see HttpServlet#HttpServlet()34 public GetTestCaseList() {35 super();36 }37 public void init() throws ServletException {38 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());39 testCaseService = appContext.getBean(TestCaseService.class);40 }41 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse42 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {43 processRequest(request, response);44 }45 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse46 protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {47 processRequest(request, response);48 }49 public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException,

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.crud.test.UpdateTestCaseMass;2import org.cerberus.util.ParameterParserUtil;3import org.cerberus.util.StringUtil;4import org.cerberus.util.answer.AnswerItem;5import java.io.BufferedReader;6import java.io.File;7import java.io.FileReader;8import java.util.HashMap;9import java.util.Map;10String test = "TEST";11File testCasesFile = new File("/Users/ivand/testcases.csv");12UpdateTestCaseMass updateTestCaseMass = new UpdateTestCaseMass();13BufferedReader br = new BufferedReader(new FileReader(testCasesFile));14String line = br.readLine();15while (line != null) {16 String[] fields = line.split(";");17 if (fields.length > 7) {18 String tcid = fields[0];19 String testcase = fields[2];20 String description = fields[3];21 String active = fields[4];22 String status = fields[5];23 String priority = fields[6];24 String comment = fields[7];25 Map<String, String[]> parameters = new HashMap<>();26 parameters.put("test", new String[]{test});27 parameters.put("testcase", new String[]{testcase});28 parameters.put("description", new String[]{description});29 parameters.put("active", new String[]{active});30 parameters.put("status", new String[]{status});31 parameters.put("priority", new String[]{priority});32 parameters.put("comment", new String[]{comment});33 parameters.put("tcid", new String[]{tcid});

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 UpdateTestCaseMass

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful