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

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

Source:CreateTestCaseExecutionQueue.java Github

copy

Full Screen

...67 * @param response servlet response68 * @throws ServletException if a servlet-specific error occurs69 * @throws IOException if an I/O error occurs70 */71 protected void processRequest(HttpServletRequest request, HttpServletResponse response)72 throws ServletException, IOException, CerberusException, JSONException {73 JSONObject jsonResponse = new JSONObject();74 JSONObject executionQueue = new JSONObject();75 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());76 Answer ans = new Answer();77 AnswerItem ansItem = new AnswerItem();78 MessageEvent msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED);79 msg.setDescription(msg.getDescription().replace("%DESCRIPTION%", ""));80 ans.setResultMessage(msg);81 PolicyFactory policy = Sanitizers.FORMATTING.and(Sanitizers.LINKS);82 String charset = request.getCharacterEncoding();83 response.setContentType("application/json");84 // Calling Servlet Transversal Util.85 ServletUtil.servletStart(request);86 /**87 * Parsing and securing all required parameters.88 */89 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them90 String actionState = policy.sanitize(request.getParameter("actionState"));91 String actionSave = policy.sanitize(request.getParameter("actionSave"));92 String environment = policy.sanitize(request.getParameter("environment"));93 String country = policy.sanitize(request.getParameter("country"));94 String manualEnvData = policy.sanitize(request.getParameter("manualEnvData"));95 // Parameter that needs to be secured --> We SECURE+DECODE them96 String test = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("test"), "", charset);97 String testcase = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testCase"), "", charset);98 int manualURL = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("manualURL"), 0, charset);99 String manualHost = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualHost"), "", charset);100 String manualContextRoot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualContextRoot"), "", charset);101 String manualLoginRelativeURL = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualLoginRelativeURL"), "", charset);102 String tag = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("tag"), "", charset);103 String robot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robot"), "", charset);104 String robotIP = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robotIP"), "", charset);105 String robotPort = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robotPort"), "", charset);106 String browser = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browser"), "", charset);107 String browserVersion = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browserVersion"), "", charset);108 String platform = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("platform"), "", charset);109 String screenSize = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("screenSize"), "", charset);110 int verbose = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("verbose"), 1, charset);111 int screenshot = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("screenshot"), 0, charset);112 int pageSource = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("pageSource"), 0, charset);113 int seleniumLog = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("seleniumLog"), 0, charset);114 String timeout = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("timeout"), "", charset);115 int retries = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("retries"), 0, charset);116 String manualExecution = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualExecution"), "", charset);117 String debugFlag = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("debugFlag"), "N", charset);118 // Parameter that we cannot secure as we need the html --> We DECODE them119 String[] myIds = request.getParameterValues("id");120 if (myIds == null) {121 myIds = new String[1];122 myIds[0] = "0";123 }124 long id = 0;125 Integer priority = TestCaseExecutionQueue.PRIORITY_DEFAULT;126 boolean prio_error = false;127 try {128 if (request.getParameter("priority") != null && !request.getParameter("priority").equals("")) {129 priority = Integer.valueOf(policy.sanitize(request.getParameter("priority")));130 }131 } catch (Exception ex) {132 prio_error = true;133 }134 boolean id_error = false;135 IExecutionThreadPoolService executionThreadPoolService = appContext.getBean(IExecutionThreadPoolService.class);136 // Create Tag when exist.137 if (!StringUtil.isNullOrEmpty(tag)) {138 // We create or update it.139 ITagService tagService = appContext.getBean(ITagService.class);140 tagService.createAuto(tag, "", request.getRemoteUser());141 }142 // Prepare the final answer.143 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);144 Answer finalAnswer = new Answer(msg1);145 List<TestCaseExecutionQueue> insertedList = new ArrayList();146 for (String myId : myIds) {147 id_error = false;148 id = 0;149 try {150 id = Long.valueOf(myId);151 } catch (NumberFormatException ex) {152 id_error = true;153 }154 /**155 * Checking all constrains before calling the services.156 */157 if (id_error) {158 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);159 msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution Queue")160 .replace("%OPERATION%", "Update")161 .replace("%REASON%", "Could not manage to convert id to an integer value."));162 ans.setResultMessage(msg);163 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);164 } else if (prio_error || priority > 2147483647 || priority < -2147483648) {165 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);166 msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution Queue")167 .replace("%OPERATION%", "Update")168 .replace("%REASON%", "Could not manage to convert priority to an integer value."));169 ans.setResultMessage(msg);170 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);171 } else {172 try {173 /**174 * All data seems cleans so we can call the services.175 */176 ITestCaseExecutionQueueService executionQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);177 IFactoryTestCaseExecutionQueue executionQueueFactory = appContext.getBean(IFactoryTestCaseExecutionQueue.class);178 if (actionSave.equals("save")) {179 /**180 * The service was able to perform the query and confirm181 * the object exist, then we can update it.182 */183 TestCaseExecutionQueue executionQueueData;184 if (id == 0) {185 // If id is not defined, we build the execution queue from all request datas.186 executionQueueData = executionQueueFactory.create(test, testcase, country, environment, robot, robotIP, robotPort, browser, browserVersion,187 platform, screenSize, manualURL, manualHost, manualContextRoot, manualLoginRelativeURL, manualEnvData, tag, screenshot, verbose, timeout,188 pageSource, seleniumLog, 0, retries, manualExecution, priority, request.getRemoteUser(), null, null, null);189 executionQueueData.setDebugFlag(debugFlag);190 } else {191 // If id is defined, we get the execution queue from database.192 executionQueueData = executionQueueService.convert(executionQueueService.readByKey(id));193 executionQueueData.setState(TestCaseExecutionQueue.State.QUEUED);194 executionQueueData.setComment("");195 executionQueueData.setDebugFlag("N");196 executionQueueData.setPriority(TestCaseExecutionQueue.PRIORITY_DEFAULT);197 executionQueueData.setUsrCreated(request.getRemoteUser());198 }199 ansItem = executionQueueService.create(executionQueueData);200 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ansItem);201 if (ansItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {202 TestCaseExecutionQueue addedExecution = (TestCaseExecutionQueue) ansItem.getItem();203 insertedList.add(addedExecution);204 }205 if (myIds.length <= 1) {206 if (ansItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {207 /**208 * Update was successful. Adding Log entry.209 */210 ILogEventService logEventService = appContext.getBean(LogEventService.class);211 logEventService.createForPrivateCalls("/CreateTestCaseExecutionQueue", "CREATE", "Created ExecutionQueue : ['" + id + "']", request);212 }213 }214 }215 } catch (FactoryCreationException ex) {216 LOG.warn(ex);217 }218 }219 }220 // Update is done, we now check what action needs to be performed.221 if (actionState.equals("toQUEUED")) {222 executionThreadPoolService.executeNextInQueueAsynchroneously(false);223 }224 /**225 * Formating and returning the json result.226 */227 jsonResponse.put("messageType", finalAnswer.getResultMessage().getMessage().getCodeString());228 jsonResponse.put("message", finalAnswer.getResultMessage().getDescription());229 if (insertedList.isEmpty()) {230 jsonResponse.put("addedEntries", 0);231 } else {232 JSONArray executionList = new JSONArray();233 for (TestCaseExecutionQueue testCaseExecutionQueue : insertedList) {234 JSONObject myExecution = new JSONObject();235 myExecution.append("id", testCaseExecutionQueue.getId());236 executionList.put(myExecution);237 }238 jsonResponse.put("testCaseExecutionQueueList", executionList);239 jsonResponse.put("addedEntries", insertedList.size());240 }241 response.getWriter().print(jsonResponse);242 response.getWriter().flush();243 }244 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">245 /**246 * Handles the HTTP <code>GET</code> method.247 *248 * @param request servlet request249 * @param response servlet response250 * @throws ServletException if a servlet-specific error occurs251 * @throws IOException if an I/O error occurs252 */253 @Override254 protected void doGet(HttpServletRequest request, HttpServletResponse response)255 throws ServletException, IOException {256 try {257 processRequest(request, response);258 } catch (CerberusException ex) {259 LOG.warn(ex);260 } catch (JSONException ex) {261 LOG.warn(ex);262 }263 }264 /**265 * Handles the HTTP <code>POST</code> method.266 *267 * @param request servlet request268 * @param response servlet response269 * @throws ServletException if a servlet-specific error occurs270 * @throws IOException if an I/O error occurs271 */272 @Override273 protected void doPost(HttpServletRequest request, HttpServletResponse response)274 throws ServletException, IOException {275 try {276 processRequest(request, response);277 } catch (CerberusException ex) {278 LOG.warn(ex);279 } catch (JSONException ex) {280 LOG.warn(ex);281 }282 }283 /**284 * Returns a short description of the servlet.285 *286 * @return a String containing servlet description287 */288 @Override289 public String getServletInfo() {290 return "Short description";...

Full Screen

Full Screen

processRequest

Using AI Code Generation

copy

Full Screen

1try {2 HttpClient client = new HttpClient();3 method.setRequestHeader("Content-Type", "application/json");4 method.setRequestHeader("Accept", "application/json");5 String json = "{\"test\":\"TEST\",\"testCase\":\"TESTCASE\"}";6 method.setRequestEntity(new StringRequestEntity(json, "application/json", "UTF-8"));7 client.executeMethod(method);8 String response = method.getResponseBodyAsString();9 System.out.println(response);10} catch (Exception e) {11 e.printStackTrace();12}

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 CreateTestCaseExecutionQueue

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful