Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecutionQueue
Source:UpdateTestCaseExecutionQueue.java
...50/**51 *52 * @author bcivel53 */54@WebServlet(name = "UpdateTestCaseExecutionQueue", urlPatterns = {"/UpdateTestCaseExecutionQueue"})55public class UpdateTestCaseExecutionQueue extends HttpServlet {56 private static final Logger LOG = LogManager.getLogger(UpdateTestCaseExecutionQueue.class);57 /**58 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>59 * methods.60 *61 * @param request servlet request62 * @param response servlet response63 * @throws ServletException if a servlet-specific error occurs64 * @throws IOException if an I/O error occurs65 */66 protected void processRequest(HttpServletRequest request, HttpServletResponse response)67 throws ServletException, IOException, CerberusException, JSONException {68 JSONObject jsonResponse = new JSONObject();69 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());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 String charset = request.getCharacterEncoding();76 response.setContentType("application/json");77 // Calling Servlet Transversal Util.78 ServletUtil.servletStart(request);79 /**80 * Parsing and securing all required parameters.81 */82 // Parameter that are already controled by GUI (no need to decode) --> We SECURE them83 String actionState = policy.sanitize(request.getParameter("actionState"));84 String actionSave = policy.sanitize(request.getParameter("actionSave"));85 String environment = policy.sanitize(request.getParameter("environment"));86 String country = policy.sanitize(request.getParameter("country"));87 String manualEnvData = policy.sanitize(request.getParameter("manualEnvData"));88 // Parameter that needs to be secured --> We SECURE+DECODE them89 String test = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("test"), null, charset);90 String testcase = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("testCase"), null, charset);91 int manualURL = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("manualURL"), 0, charset);92 String manualHost = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualHost"), null, charset);93 String manualContextRoot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualContextRoot"), "", charset);94 String manualLoginRelativeURL = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualLoginRelativeURL"), "", charset);95 String tag = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("tag"), null, charset);96 String robot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robot"), null, charset);97 String robotIP = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robotIP"), null, charset);98 String robotPort = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("robotPort"), null, charset);99 String browser = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browser"), null, charset);100 String browserVersion = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("browserVersion"), null, charset);101 String platform = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("platform"), null, charset);102 String screenSize = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("screenSize"), null, charset);103 int verbose = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("verbose"), 1, charset);104 int screenshot = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("screenshot"), 0, charset);105 int pageSource = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("pageSource"), 0, charset);106 int seleniumLog = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("seleniumLog"), 0, charset);107 String timeout = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("timeout"), "", charset);108 int retries = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter("retries"), 0, charset);109 String manualExecution = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("manualExecution"), "", charset);110 String debugFlag = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter("debugFlag"), "N", charset);111 Integer priority = TestCaseExecutionQueue.PRIORITY_DEFAULT;112 boolean prio_error = false;113 try {114 if (request.getParameter("priority") != null && !request.getParameter("priority").equals("")) {115 priority = Integer.valueOf(policy.sanitize(request.getParameter("priority")));116 }117 } catch (Exception ex) {118 prio_error = true;119 }120 // Parameter that we cannot secure as we need the html --> We DECODE them121 String[] myIds = request.getParameterValues("id");122 long id = 0;123 // Create Tag when exist.124 if (!StringUtil.isNullOrEmpty(tag)) {125 // We create or update it.126 ITagService tagService = appContext.getBean(ITagService.class);127 tagService.createAuto(tag, "", request.getRemoteUser());128 }129 // Prepare the final answer.130 MessageEvent msg1 = new MessageEvent(MessageEventEnum.GENERIC_OK);131 Answer finalAnswer = new Answer(msg1);132 boolean id_error = false;133 for (String myId : myIds) {134 id_error = false;135 try {136 id = Long.valueOf(myId);137 } catch (NumberFormatException ex) {138 id_error = true;139 }140 /**141 * Checking all constrains before calling the services.142 */143 if (id_error) {144 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);145 msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution Queue")146 .replace("%OPERATION%", "Update")147 .replace("%REASON%", "Could not manage to convert id to an integer value."));148 ans.setResultMessage(msg);149 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);150 } else if (prio_error || priority > 2147483647 || priority < -2147483648) {151 msg = new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_EXPECTED);152 msg.setDescription(msg.getDescription().replace("%ITEM%", "Execution Queue")153 .replace("%OPERATION%", "Update")154 .replace("%REASON%", "Could not manage to convert priority to an integer value."));155 ans.setResultMessage(msg);156 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);157 } else {158 /**159 * All data seems cleans so we can call the services.160 */161 ITestCaseExecutionQueueService executionQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);162 IExecutionThreadPoolService executionThreadPoolService = appContext.getBean(IExecutionThreadPoolService.class);163 AnswerItem resp = executionQueueService.readByKey(id);164 if (!(resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && resp.getItem() != null)) {165 /**166 * Object could not be found. We stop here and report the167 * error.168 */169 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) resp);170 } else {171 TestCaseExecutionQueue executionQueueData = (TestCaseExecutionQueue) resp.getItem();172 if (actionSave.equals("save")) {173 /**174 * The service was able to perform the query and confirm175 * the object exist, then we can update it.176 */177 executionQueueData.setTest(ParameterParserUtil.parseStringParam(test, executionQueueData.getTest()));178 executionQueueData.setTestCase(ParameterParserUtil.parseStringParam(testcase, executionQueueData.getTestCase()));179 executionQueueData.setTag(ParameterParserUtil.parseStringParam(tag, executionQueueData.getTag()));180 executionQueueData.setEnvironment(ParameterParserUtil.parseStringParam(environment, executionQueueData.getEnvironment()));181 executionQueueData.setCountry(ParameterParserUtil.parseStringParam(country, executionQueueData.getCountry()));182 executionQueueData.setManualURL(ParameterParserUtil.parseIntegerParam(manualURL, executionQueueData.getManualURL()));183 executionQueueData.setManualHost(ParameterParserUtil.parseStringParam(manualHost, executionQueueData.getManualHost()));184 executionQueueData.setManualContextRoot(ParameterParserUtil.parseStringParam(manualContextRoot, executionQueueData.getManualContextRoot()));185 executionQueueData.setManualLoginRelativeURL(ParameterParserUtil.parseStringParam(manualLoginRelativeURL, executionQueueData.getManualLoginRelativeURL()));186 executionQueueData.setManualEnvData(ParameterParserUtil.parseStringParam(manualEnvData, executionQueueData.getManualEnvData()));187 executionQueueData.setRobot(ParameterParserUtil.parseStringParam(robot, executionQueueData.getRobot()));188 executionQueueData.setRobotIP(ParameterParserUtil.parseStringParam(robotIP, executionQueueData.getRobotIP()));189 executionQueueData.setRobotPort(ParameterParserUtil.parseStringParam(robotPort, executionQueueData.getRobotPort()));190 executionQueueData.setBrowser(ParameterParserUtil.parseStringParam(browser, executionQueueData.getBrowser()));191 executionQueueData.setBrowserVersion(ParameterParserUtil.parseStringParam(browserVersion, executionQueueData.getBrowserVersion()));192 executionQueueData.setPlatform(ParameterParserUtil.parseStringParam(platform, executionQueueData.getPlatform()));193 executionQueueData.setScreenSize(ParameterParserUtil.parseStringParam(screenSize, executionQueueData.getScreenSize()));194 executionQueueData.setVerbose(ParameterParserUtil.parseIntegerParam(verbose, executionQueueData.getVerbose()));195 executionQueueData.setScreenshot(screenshot);196 executionQueueData.setPageSource(pageSource);197 executionQueueData.setSeleniumLog(seleniumLog);198 executionQueueData.setTimeout(timeout);199 executionQueueData.setRetries(retries);200 executionQueueData.setManualExecution(manualExecution);201 executionQueueData.setDebugFlag(debugFlag);202 executionQueueData.setPriority(priority);203 executionQueueData.setUsrModif(request.getRemoteUser());204 ans = executionQueueService.update(executionQueueData);205 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);206 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {207 /**208 * Update was successfull. Adding Log entry.209 */210 ILogEventService logEventService = appContext.getBean(LogEventService.class);211 logEventService.createForPrivateCalls("/UpdateTestCaseExecutionQueue", "UPDATE", "Updated ExecutionQueue : ['" + id + "']", request);212 }213 }214 // Update is done, we now check what action needs to be performed.215 if (actionState.equals("toQUEUED")) {216 LOG.debug("toQUEUED");217 ans = executionQueueService.updateToQueued(id, "Trigered by user " + request.getRemoteUser() + ".");218 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);219 executionThreadPoolService.executeNextInQueueAsynchroneously(false);220 }221 // Priority Update.222 if (actionSave.equals("priority")) {223 executionQueueData.setPriority(priority);224 ans = executionQueueService.update(executionQueueData);225 finalAnswer = AnswerUtil.agregateAnswer(finalAnswer, (Answer) ans);...
UpdateTestCaseExecutionQueue
Using AI Code Generation
1import org.cerberus.servlet.crud.testexecution.UpdateTestCaseExecutionQueue;2UpdateTestCaseExecutionQueue updateTestCaseExecutionQueue = new UpdateTestCaseExecutionQueue();3updateTestCaseExecutionQueue.doPost(request, response);4import org.cerberus.servlet.crud.testexecution.GetTestCaseExecutionQueue;5GetTestCaseExecutionQueue getTestCaseExecutionQueue = new GetTestCaseExecutionQueue();6getTestCaseExecutionQueue.doGet(request, response);7import org.cerberus.servlet.crud.testexecution.DeleteTestCaseExecutionQueue;8DeleteTestCaseExecutionQueue deleteTestCaseExecutionQueue = new DeleteTestCaseExecutionQueue();9deleteTestCaseExecutionQueue.doPost(request, response);10import org.cerberus.servlet.crud.testexecution.GetTestCaseExecutionQueue;11GetTestCaseExecutionQueue getTestCaseExecutionQueue = new GetTestCaseExecutionQueue();12getTestCaseExecutionQueue.doGet(request, response);13import org.cerberus.servlet.crud.testexecution.DeleteTestCaseExecutionQueue;14DeleteTestCaseExecutionQueue deleteTestCaseExecutionQueue = new DeleteTestCaseExecutionQueue();15deleteTestCaseExecutionQueue.doPost(request, response);16import org.cerberus.servlet.crud.testexecution.DeleteTestCaseExecutionQueue;17DeleteTestCaseExecutionQueue deleteTestCaseExecutionQueue = new DeleteTestCaseExecutionQueue();18deleteTestCaseExecutionQueue.doPost(request, response);19import org.cerberus.servlet.crud.testexecution.GetTestCaseExecutionQueue;20GetTestCaseExecutionQueue getTestCaseExecutionQueue = new GetTestCaseExecutionQueue();21getTestCaseExecutionQueue.doGet(request, response);
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!