How to use processRequest method of org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecution class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecution.processRequest

Source:UpdateTestCaseExecution.java Github

copy

Full Screen

...64 * @param response servlet response65 * @throws ServletException if a servlet-specific error occurs66 * @throws IOException if an I/O error occurs67 */68 protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, JSONException, CerberusException {69 // Calling Servlet Transversal Util.70 ServletUtil.servletStart(request);71 //Parsing and securing all required parameters.72 StringBuilder sb = new StringBuilder();73 BufferedReader br = request.getReader();74 String str;75 try{76 while ((str = br.readLine()) != null) {77 sb.append(str);78 }79 JSONObject testCase = new JSONObject(sb.toString());80 //get all element from Json81 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());82 83 updateTestCaseExecutionFromJsonArray(testCase, appContext);84 response.getWriter().print( new MessageEvent(MessageEventEnum.GENERIC_OK) );85 } catch (JSONException e) {86 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());87 } catch (CerberusException e) {88 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());89 } catch (IOException e) {90 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());91 }92 }93 /**94 * update Test case execution with testCaseJson and all the parameter belonging to it (action, control, step)95 * @param JSONObject testCaseJson96 * @param ApplicationContext appContext97 * @throws JSONException 98 * @throws IOException99 * @throws CerberusException100 */101 void updateTestCaseExecutionFromJsonArray(JSONObject testCaseJson, ApplicationContext appContext) throws JSONException, IOException, CerberusException {102 JSONArray stepArray = testCaseJson.getJSONArray("stepArray");103 long executionId = testCaseJson.getLong("executionId");104 ITestCaseExecutionService testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);105 String returnCodeOfTestCase = updateTestCaseStepExecutionFromJsonArray(stepArray, appContext );106 107 String returnMessage;108 if ( returnCodeOfTestCase.equals("OK") )109 returnMessage = "The test case finished successfully";110 else if ( returnCodeOfTestCase.equals("FA") )111 returnMessage = "The test case failed to be executed because of an action.";112 else if ( returnCodeOfTestCase.equals("KO") )113 returnMessage = "The test case finished, but failed on validations.";114 else 115 returnMessage = "";116 //get testCaseExecution117 TestCaseExecution executionToUpdate = testCaseExecutionService.findTCExecutionByKey(executionId);118 executionToUpdate.setControlStatus(returnCodeOfTestCase);119 executionToUpdate.setControlMessage(returnMessage);120 testCaseExecutionService.updateTCExecution(executionToUpdate);121 }122 123 /**124 * update Step execution with stepArray and all the parameter belonging to it (action, control)125 * @param JSONObject testCaseJson126 * @param ApplicationContext appContext127 * @throws JSONException 128 * @throws IOException129 */130 String updateTestCaseStepExecutionFromJsonArray(JSONArray stepArray, ApplicationContext appContext) throws JSONException, IOException {131 String returnCodeOfTestCase = "OK";132 133 for (int i = 0; i < stepArray.length(); i++) {134 JSONObject currentStep = stepArray.getJSONObject(i);135 136 long id = currentStep.getLong("id");137 String test = currentStep.getString("test");138 String testCase = currentStep.getString("testcase");139 int step = currentStep.getInt("step");140 int index = currentStep.getInt("index");141 int sort = 0;142 String loop = currentStep.getString("loop");143 String conditionOper = currentStep.getString("conditionOper");144 String conditionVal1Init = currentStep.getString("conditionVal1Init");145 String conditionVal2Init = currentStep.getString("conditionVal2Init");146 String conditionVal1 = currentStep.getString("conditionVal1");147 String conditionVal2 = currentStep.getString("conditionVal2");148 String batNumExe = "NULL";149 long start = currentStep.getLong("start");150 long end = currentStep.getLong("end");151 long fullStart = currentStep.getLong("fullStart");152 long fullEnd = currentStep.getLong("fullEnd");153 BigDecimal timeElapsed = new BigDecimal(0);//to change154 String returnCode = currentStep.getString("returnCode");155 //update return code if needed156 if ( returnCode.equals("KO") )157 returnCodeOfTestCase ="KO";158 else if ( returnCode.equals("FA") && !returnCodeOfTestCase.equals("KO") )159 returnCodeOfTestCase ="FA";160 String description = currentStep.getString("description");161 //String possibly wrote by the user162 String returnMessage = StringUtil.sanitize( currentStep.getString("returnMessage") );163 if (returnMessage == "Step not executed")//default message unchanged164 returnMessage = "Step executed manually";165 //create this testCaseStepExecution and update the bdd with it166 TestCaseStepExecution currentTestCaseStepExecution = createTestCaseStepExecution(id, test, testCase, step, index, sort, loop, conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, batNumExe, start, end, fullStart, fullEnd, timeElapsed, returnCode, returnMessage, description);167 ITestCaseStepExecutionService testCaseStepExecutionService = appContext.getBean(ITestCaseStepExecutionService.class);168 testCaseStepExecutionService.updateTestCaseStepExecution(currentTestCaseStepExecution);169 //update action list belonging to the current Step170 updateTestCaseStepActionFromJsonArray( currentStep.getJSONArray("actionArr"), appContext);171 }172 return returnCodeOfTestCase;173 }174 /**175 * update action execution with testCaseStepActionJson and all the parameter belonging to it (control)176 * @param JSONObject testCaseJson177 * @param ApplicationContext appContext178 * @throws JSONException 179 * @throws IOException180 */181 void updateTestCaseStepActionFromJsonArray(JSONArray testCaseStepActionJson, ApplicationContext appContext) throws JSONException, IOException {182 for (int i = 0; i < testCaseStepActionJson.length(); i++) {183 JSONObject currentAction = testCaseStepActionJson.getJSONObject(i);184 long id = currentAction.getLong("id");185 String test = currentAction.getString("test");186 String testCase = currentAction.getString("testcase");187 int step = currentAction.getInt("step");188 int index = currentAction.getInt("index");189 int sort = currentAction.getInt("sort");190 int sequence = currentAction.getInt("sequence");191 String conditionOper = currentAction.getString("conditionOper");192 String conditionVal1Init = currentAction.getString("conditionVal1Init");193 String conditionVal2Init = currentAction.getString("conditionVal2Init");194 String conditionVal1 = currentAction.getString("conditionVal1");195 String conditionVal2 = currentAction.getString("conditionVal2");196 String action = currentAction.getString("action");197 String value1Init = currentAction.getString("value1init");198 String value2Init = currentAction.getString("value2init");199 String value1 = currentAction.getString("value1");200 String value2 = currentAction.getString("value2");201 String forceExeStatus = currentAction.getString("forceExeStatus");202 String description = currentAction.getString("description");203 String returnCode = currentAction.getString("returnCode");204 205 //String wrote by the user206 String returnMessage = StringUtil.sanitize( currentAction.getString("returnMessage") );207 //default message unchanged208 if ( returnMessage.equals("Action not executed") )209 returnMessage = "Action executed manually";210 211 long start = currentAction.getLong("start");212 long end = currentAction.getLong("end");213 long fullStart = 0;//currentAction.getLong("fullStart");214 long fullEnd = 0;//currentAction.getLong("fullEnd");215 //create this testCaseStepActionExecution and update the bdd with it216 TestCaseStepActionExecution currentTestCaseStepActionExecution = createTestCaseStepActionExecution(id, test, testCase, step, index, sequence, sort, returnCode, returnMessage, conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, action, value1Init, value2Init, value1, value2, forceExeStatus, start, end, fullStart, fullEnd, null, description, null, null);217 ITestCaseStepActionExecutionService testCaseStepActionExecutionService = appContext.getBean(ITestCaseStepActionExecutionService.class);218 219 testCaseStepActionExecutionService.updateTestCaseStepActionExecution(currentTestCaseStepActionExecution);220 //update the control list belonging to the current Action221 updateTestCaseStepActionControlExecutionFromJsonArray( currentAction.getJSONArray("controlArr"), appContext);222 }223 }224 225 /**226 * update control execution with testCaseStepActionControlJson227 * @param JSONObject testCaseJson228 * @param ApplicationContext appContext229 * @throws JSONException 230 * @throws IOException231 */232 void updateTestCaseStepActionControlExecutionFromJsonArray( JSONArray controlArray, ApplicationContext appContext) throws JSONException, IOException {233 for (int i = 0; i < controlArray.length(); i++) {234 JSONObject currentControl = controlArray.getJSONObject(i);235 long id = currentControl.getLong("id");236 String test = currentControl.getString("test");237 String testCase = currentControl.getString("testcase");238 int step = currentControl.getInt("step");239 int index = currentControl.getInt("index");240 int sort = currentControl.getInt("sort");241 int sequence = currentControl.getInt("sequence");242 int controlSequence = currentControl.getInt("control");243 String conditionOper = currentControl.getString("conditionOper");244 String conditionVal1Init = currentControl.getString("conditionVal1Init");245 String conditionVal2Init = currentControl.getString("conditionVal2Init");246 String conditionVal1 = currentControl.getString("conditionVal1");247 String conditionVal2 = currentControl.getString("conditionVal2");248 String control = currentControl.getString("controlType");249 String value1Init = currentControl.getString("value1init");250 String value2Init = currentControl.getString("value2init");251 String value1 = currentControl.getString("value1");252 String value2 = currentControl.getString("value2");253 String fatal = currentControl.getString("fatal");254 String description = currentControl.getString("description");255 String returnCode = currentControl.getString("returnCode");256 //String wrote by the user257 String returnMessage = StringUtil.sanitize( currentControl.getString("returnMessage") );258 if ( returnMessage.equals("Control executed manually") )//default message unchanged259 returnMessage = "Control executed manually";260 261 long start = currentControl.getLong("start");262 long end = currentControl.getLong("end");263 long fullStart = 0;//currentAction.getLong("fullStart");264 long fullEnd = 0;//currentAction.getLong("fullEnd");265 //create this TestCaseStepActionControlExecution and update the bdd with it266 TestCaseStepActionControlExecution currentTestCaseStepActionControlExecution = createTestCaseStepActionControlExecution(id, test, testCase, step, index,sequence, controlSequence, sort, returnCode, returnMessage, conditionOper, conditionVal1Init, conditionVal2Init, conditionVal1, conditionVal2, control, value1Init, value2Init, value1, value2, fatal, start, end, fullStart, fullEnd, description, null, null);267 ITestCaseStepActionControlExecutionService testCaseStepActionControlExecutionService = appContext.getBean(ITestCaseStepActionControlExecutionService.class);268 testCaseStepActionControlExecutionService.updateTestCaseStepActionControlExecution(currentTestCaseStepActionControlExecution);269 }270 }271 272 //create a TestCaseStepExecution with the parameters273 private TestCaseStepExecution createTestCaseStepExecution(long id, String test, String testCase, int step, int index, int sort, String loop, String conditionOper, String conditionVal1Init,274 String conditionVal2Init, String conditionVal1, String conditionVal2, String batNumExe, long start, long end, long fullStart, long fullEnd, BigDecimal timeElapsed,275 String returnCode, String returnMessage, String description) { 276 277 TestCaseStepExecution testCaseStepExecution = new TestCaseStepExecution();278 testCaseStepExecution.setBatNumExe(batNumExe);279 testCaseStepExecution.setEnd(end);280 testCaseStepExecution.setFullEnd(fullEnd);281 testCaseStepExecution.setFullStart(fullStart);282 testCaseStepExecution.setId(id);283 testCaseStepExecution.setReturnCode(returnCode);284 testCaseStepExecution.setStart(start);285 testCaseStepExecution.setStep(step);286 testCaseStepExecution.setIndex(index);287 testCaseStepExecution.setSort(sort);288 testCaseStepExecution.setLoop(loop);289 testCaseStepExecution.setConditionOper(conditionOper);290 testCaseStepExecution.setConditionVal1Init(conditionVal1Init);291 testCaseStepExecution.setConditionVal2Init(conditionVal2Init);292 testCaseStepExecution.setConditionVal1(conditionVal1);293 testCaseStepExecution.setConditionVal2(conditionVal2);294 testCaseStepExecution.setTest(test);295 testCaseStepExecution.setTestCase(testCase);296 testCaseStepExecution.setTimeElapsed(timeElapsed);297 testCaseStepExecution.setDescription(description);298 testCaseStepExecution.setReturnMessage(returnMessage);299 return testCaseStepExecution;300 }301 //create a TestCaseStepActionExecution with the parameters302 private TestCaseStepActionExecution createTestCaseStepActionExecution(long id, String test, String testCase, int step, int index, int sequence, int sort, String returnCode, String returnMessage, 303 String conditionOper, String conditionVal1Init, String conditionVal2Init, String conditionVal1, String conditionVal2, String action, String value1Init, String value2Init, String value1, String value2, 304 String forceExeStatus, long start, long end, long startLong, long endLong, MessageEvent resultMessage, String description, TestCaseStepAction testCaseStepAction, 305 TestCaseStepExecution testCaseStepExecution) {306 307 TestCaseStepActionExecution testCaseStepActionExecution = new TestCaseStepActionExecution();308 testCaseStepActionExecution.setAction(action);309 testCaseStepActionExecution.setEnd(end);310 testCaseStepActionExecution.setEndLong(endLong);311 testCaseStepActionExecution.setId(id);312 testCaseStepActionExecution.setConditionOper(conditionOper);313 testCaseStepActionExecution.setConditionVal1Init(conditionVal1Init);314 testCaseStepActionExecution.setConditionVal2Init(conditionVal2Init);315 testCaseStepActionExecution.setConditionVal1(conditionVal1);316 testCaseStepActionExecution.setConditionVal2(conditionVal2);317 testCaseStepActionExecution.setValue1(value1);318 testCaseStepActionExecution.setValue2(value2);319 testCaseStepActionExecution.setValue1Init(value1Init);320 testCaseStepActionExecution.setValue2Init(value2Init);321 testCaseStepActionExecution.setForceExeStatus(forceExeStatus);322 testCaseStepActionExecution.setReturnCode(returnCode);323 testCaseStepActionExecution.setReturnMessage(returnMessage);324 testCaseStepActionExecution.setSequence(sequence);325 testCaseStepActionExecution.setSort(sort);326 testCaseStepActionExecution.setStart(start);327 testCaseStepActionExecution.setStartLong(startLong);328 testCaseStepActionExecution.setStep(step);329 testCaseStepActionExecution.setIndex(index);330 testCaseStepActionExecution.setTest(test);331 testCaseStepActionExecution.setTestCase(testCase);332 testCaseStepActionExecution.setActionResultMessage(resultMessage);333 testCaseStepActionExecution.setTestCaseStepAction(testCaseStepAction);334 testCaseStepActionExecution.setTestCaseStepExecution(testCaseStepExecution);335 testCaseStepActionExecution.setDescription(description);336 return testCaseStepActionExecution;337 }338 //create a TestCaseStepActionControlExecution with the parameters339 private TestCaseStepActionControlExecution createTestCaseStepActionControlExecution(long id, String test, String testCase, int step, int index, int sequence, int controlSequence, int sort,340 String returnCode, String returnMessage,341 String conditionOper, String conditionVal1Init, String conditionVal2Init, String conditionVal1, String conditionVal2,342 String control, String value1Init, String value2Init, String value1, String value2,343 String fatal, long start, long end, long startLong, long endLong,344 String description, TestCaseStepActionExecution testCaseStepActionExecution, MessageEvent resultMessage) {345 346 TestCaseStepActionControlExecution testCaseStepActionControlExecution = new TestCaseStepActionControlExecution();347 testCaseStepActionControlExecution.setId(id);348 testCaseStepActionControlExecution.setTest(test);349 testCaseStepActionControlExecution.setTestCase(testCase);350 testCaseStepActionControlExecution.setStep(step);351 testCaseStepActionControlExecution.setIndex(index);352 testCaseStepActionControlExecution.setSequence(sequence);353 testCaseStepActionControlExecution.setControlSequence(controlSequence);354 testCaseStepActionControlExecution.setSort(sort);355 testCaseStepActionControlExecution.setReturnCode(returnCode);356 testCaseStepActionControlExecution.setReturnMessage(returnMessage);357 testCaseStepActionControlExecution.setConditionOper(conditionOper);358 testCaseStepActionControlExecution.setConditionVal1Init(conditionVal1Init);359 testCaseStepActionControlExecution.setConditionVal2Init(conditionVal2Init);360 testCaseStepActionControlExecution.setConditionVal1(conditionVal1);361 testCaseStepActionControlExecution.setConditionVal2(conditionVal2);362 testCaseStepActionControlExecution.setControl(control);363 testCaseStepActionControlExecution.setValue1(value1);364 testCaseStepActionControlExecution.setValue2(value2);365 testCaseStepActionControlExecution.setValue1Init(value1Init);366 testCaseStepActionControlExecution.setValue2Init(value2Init);367 testCaseStepActionControlExecution.setFatal(fatal);368 testCaseStepActionControlExecution.setStart(start);369 testCaseStepActionControlExecution.setEnd(end);370 testCaseStepActionControlExecution.setStartLong(startLong);371 testCaseStepActionControlExecution.setEndLong(endLong);372 testCaseStepActionControlExecution.setTestCaseStepActionExecution(testCaseStepActionExecution);373 testCaseStepActionControlExecution.setControlResultMessage(resultMessage);374 testCaseStepActionControlExecution.setDescription(description);375 376 return testCaseStepActionControlExecution;377 } 378 379 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">380 /**381 * Handles the HTTP <code>GET</code> method.382 *383 * @param request servlet request384 * @param response servlet response385 * @throws ServletException if a servlet-specific error occurs386 * @throws IOException if an I/O error occurs387 */388 @Override389 protected void doGet(HttpServletRequest request, HttpServletResponse response)390 throws ServletException, IOException {391 try {392 processRequest(request, response);393 } catch (JSONException ex) {394 LOG.warn(ex);395 } catch (CerberusException ex) {396 LOG.warn(ex);397 }398 }399 /**400 * Handles the HTTP <code>POST</code> method.401 *402 * @param request servlet request403 * @param response servlet response404 * @throws ServletException if a servlet-specific error occurs405 * @throws IOException if an I/O error occurs406 */407 @Override408 protected void doPost(HttpServletRequest request, HttpServletResponse response)409 throws ServletException, IOException {410 try {411 processRequest(request, response);412 } catch (JSONException ex) {413 LOG.warn(ex);414 } catch (CerberusException ex) {415 LOG.warn(ex);416 }417 }418 /**419 * Returns a short description of the servlet.420 *421 * @return a String containing servlet description422 */423 @Override424 public String getServletInfo() {425 return "Short description";...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1import groovy.json.JsonSlurper2import org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecution3import org.cerberus.util.answer.AnswerItem4import org.cerberus.util.answer.AnswerUtil5import org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecution6import org.cerberus.ut

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1String data = "test=TEST&testcase=TC&country=FR&environment=QA";2String contentType = "application/x-www-form-urlencoded";3String charset = "UTF-8";4String response = http.post(url, data, contentType, charset);5String data = "test=TEST&testcase=TC&country=FR&environment=QA";6String contentType = "application/x-www-form-urlencoded";7String charset = "UTF-8";8String response = http.post(url, data, contentType, charset);

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