Best Cerberus-source code snippet using org.cerberus.crud.entity.RobotExecutor.toString
Source:ExecutionQueueWorkerThread.java
...98 if (getToExecute().getManualEnvData() != null) {99 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_MANUAL_ENV_DATA, URLEncoder.encode(getToExecute().getManualEnvData(), "UTF-8"));100 }101 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_TAG, URLEncoder.encode(getToExecute().getTag(), "UTF-8"));102 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_SCREENSHOT, Integer.toString(getToExecute().getScreenshot()));103 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_VIDEO, Integer.toString(getToExecute().getVideo()));104 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_VERBOSE, Integer.toString(getToExecute().getVerbose()));105 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_TIMEOUT, getToExecute().getTimeout());106 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_PAGE_SOURCE, Integer.toString(getToExecute().getPageSource()));107 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_ROBOT_LOG, Integer.toString(getToExecute().getRobotLog()));108 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_CONSOLE_LOG, Integer.toString(getToExecute().getConsoleLog()));109 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_EXECUTION_QUEUE_ID, Long.toString(getToExecute().getId()));110 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_NUMBER_OF_RETRIES, Long.toString(getToExecute().getRetries()));111 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_EXECUTOR, getToExecute().getUsrCreated());112 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_MANUAL_EXECUTION, getToExecute().getManualExecution());113 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_OUTPUT_FORMAT, PARAMETER_OUTPUT_FORMAT_VALUE);114 paramRequestMaker.addParam(RunTestCaseV002.PARAMETER_SYNCHRONEOUS, ParameterParserUtil.DEFAULT_BOOLEAN_TRUE_VALUE);115 } catch (UnsupportedEncodingException ex) {116 LOG.error("Error when encoding string in URL : ", ex);117 }118 return paramRequestMaker;119 }120 /**121 * The associated {@link RuntimeException} for any errors during the run122 * process123 */124 public static class RunQueueProcessException extends RuntimeException {125 public RunQueueProcessException(String message) {126 super(message);127 }128 public RunQueueProcessException(String message, Throwable cause) {129 super(message, cause);130 }131 }132 public SessionCounter getSessionCounter() {133 return sessionCounter;134 }135 public void setSessionCounter(SessionCounter sessionCounter) {136 this.sessionCounter = sessionCounter;137 }138 public IParameterService getParameterService() {139 return parameterService;140 }141 public void setParameterService(IParameterService parameterService) {142 this.parameterService = parameterService;143 }144 public ITestCaseExecutionQueueDepService getQueueDepService() {145 return queueDepService;146 }147 public void setQueueDepService(ITestCaseExecutionQueueDepService queueDepService) {148 this.queueDepService = queueDepService;149 }150 public String getRobotExecutor() {151 return robotExecutor;152 }153 public void setRobotExecutor(String robotExecutor) {154 this.robotExecutor = robotExecutor;155 }156 public String getSelectedRobotHost() {157 return selectedRobotHost;158 }159 public void setSelectedRobotHost(String selectedRobotHost) {160 this.selectedRobotHost = selectedRobotHost;161 }162 public String getSelectedRobotExtHost() {163 return selectedRobotExtHost;164 }165 public void setSelectedRobotExtHost(String selectedRobotExtHost) {166 this.selectedRobotExtHost = selectedRobotExtHost;167 }168 public TestCaseExecutionQueue getToExecute() {169 return toExecute;170 }171 private void setToExecute(TestCaseExecutionQueue toExecute) {172 this.toExecute = toExecute;173 }174 public ITestCaseExecutionQueueService getQueueService() {175 return queueService;176 }177 public void setQueueService(ITestCaseExecutionQueueService queueService) {178 this.queueService = queueService;179 }180 public void setRetriesService(IRetriesService retriesService) {181 this.retriesService = retriesService;182 }183 public APIKeyService getApiKeyService() {184 return apiKeyService;185 }186 public void setApiKeyService(APIKeyService apiKeyService) {187 this.apiKeyService = apiKeyService;188 }189 public ITagService getTagService() {190 return tagService;191 }192 public void setTagService(ITagService tagService) {193 this.tagService = tagService;194 }195 public void setCerberusExecutionUrl(String url) {196 this.cerberusExecutionUrl = url;197 }198 public String getCerberusTriggerQueueJobUrl() {199 return cerberusTriggerQueueJobUrl;200 }201 public void setCerberusTriggerQueueJobUrl(String cerberusTriggerQueueJobUrl) {202 this.cerberusTriggerQueueJobUrl = cerberusTriggerQueueJobUrl;203 }204 public void setQueueId(long queueId) {205 this.queueId = queueId;206 }207 public void setExecThreadPool(ExecutionQueueThreadPool etp) {208 this.execThreadPool = etp;209 }210 public void setFuture(Future<?> future) {211 this.future = future;212 }213 public int getToExecuteTimeout() {214 return toExecuteTimeout;215 }216 public void setToExecuteTimeout(int toExecuteTimeout) {217 this.toExecuteTimeout = toExecuteTimeout;218 }219 @Override220 public void run() {221 try {222 LOG.debug("Checking credit limit on : " + queueId + " with RobotHost : " + selectedRobotHost + " with RobotExtensionHost : " + selectedRobotExtHost);223 checkCreditLimit();224 LOG.debug("Start to execute : " + queueId + " with RobotHost : " + selectedRobotHost + " with RobotExtensionHost : " + selectedRobotExtHost);225 LOG.debug("Get queue exe to execute : " + queueId);226 // Getting the queue full object.227 setToExecute(queueService.convert(queueService.readByKey(queueId, false)));228 StringBuilder url = new StringBuilder();229 url.append(cerberusExecutionUrl);230 url.append(RunTestCaseV002.SERVLET_URL);231 url.append("?");232 url.append(makeParamRequest().mkString().replace(" ", "+"));233 LOG.debug("Make http call : " + queueId);234 // Make the http call and parse the output.235 runParseAnswer(runExecution(url), cerberusExecutionUrl + RunTestCaseV002.SERVLET_URL, url.toString());236 } catch (Exception e) {237 LOG.warn("Execution in queue " + queueId + " has finished with error");238 LOG.error(e, e);239 try {240 queueService.updateToError(queueId, e.getMessage());241 queueDepService.manageDependenciesEndOfQueueExecution(queueId);242 // If error, we check that campaign is finished.243 tagService.manageCampaignEndOfExecution(getToExecute().getTag());244 // Trigger Queue Job245 LOG.debug("trigger extra job.");246 triggerQueueJob(cerberusTriggerQueueJobUrl);247 } catch (CerberusException again) {248 LOG.error("Unable to mark execution in queue " + queueId + " as in error", again);249 }250 }251 }252 /**253 * Request the queue job to be executed calling the corresponding servlet.254 *255 * @return the execution answer from the {@link RunTestCase} servlet256 * @throws RunQueueProcessException if an error occurred during request257 * execution258 * @see #run()259 */260 private String triggerQueueJob(String url) {261 try {262 LOG.debug("Trigger Job Queue calling Service URL : " + url);263 LOG.debug("Trigger Execution with TimeOut : " + toExecuteTimeout);264 CloseableHttpClient httpclient = HttpClientBuilder.create().disableAutomaticRetries().build();265 RequestConfig requestConfig = RequestConfig.custom()266 .setConnectTimeout(toExecuteTimeout)267 .setConnectionRequestTimeout(toExecuteTimeout)268 .setSocketTimeout(toExecuteTimeout)269 .build();270 HttpGet httpGet = new HttpGet(url);271 httpGet.setConfig(requestConfig);272 CloseableHttpResponse response = httpclient.execute(httpGet);273 HttpEntity entity = response.getEntity();274 String responseContent = EntityUtils.toString(entity);275 return responseContent;276 } catch (Exception e) {277 final StringBuilder errorMessage = new StringBuilder("An unexpected error occurred trigering Queue Job: ");278 if (e instanceof HttpResponseException) {279 errorMessage.append(String.format("%d (%s)", ((HttpResponseException) e).getStatusCode(), e.getMessage()));280 } else {281 errorMessage.append(e.getMessage());282 errorMessage.append(". Check server logs");283 }284 LOG.error(errorMessage.toString(), e);285 throw new RunQueueProcessException(errorMessage.toString(), e);286 }287 }288 /**289 * Request execution of the inner {@link TestCaseExecutionQueue} to the290 * {@link RunTestCase} servlet291 *292 * @return the execution answer from the {@link RunTestCase} servlet293 * @throws RunQueueProcessException if an error occurred during request294 * execution295 * @see #run()296 */297 private String runExecution(StringBuilder url) {298 try {299 LOG.debug("Trigger Execution to URL : " + url.toString());300 LOG.debug("Trigger Execution with TimeOut : " + toExecuteTimeout);301 CloseableHttpClient httpclient = HttpClientBuilder.create().disableAutomaticRetries().build();302 RequestConfig requestConfig = RequestConfig.custom()303 .setConnectTimeout(toExecuteTimeout)304 .setConnectionRequestTimeout(toExecuteTimeout)305 .setSocketTimeout(toExecuteTimeout)306 .build();307 HttpGet httpGet = new HttpGet(url.toString());308 httpGet.setConfig(requestConfig);309 httpGet.setHeader("apikey", apiKeyService.getServiceAccountAPIKey());310 CloseableHttpResponse response = httpclient.execute(httpGet);311 HttpEntity entity = response.getEntity();312 String responseContent = EntityUtils.toString(entity);313 return responseContent;314 } catch (Exception e) {315 final StringBuilder errorMessage = new StringBuilder("An unexpected error occurred during test case execution: ");316 if (e instanceof HttpResponseException) {317 errorMessage.append(String.format("%d (%s)", ((HttpResponseException) e).getStatusCode(), e.getMessage()));318 } else {319 errorMessage.append(e.getMessage());320 errorMessage.append(". Check server logs");321 }322 LOG.error(errorMessage.toString(), e);323 throw new RunQueueProcessException(errorMessage.toString(), e);324 }325 }326 /**327 * Parse the answer given by the {@link RunTestCase}328 * <p>329 * @param answer the {@link RunTestCase}'s answer330 * @throws RunQueueProcessException if an error occurred if execution was on331 * failure or if answer cannot be parsed332 * @see #run()333 */334 private void runParseAnswer(String answer, String cerberusUrl, String cerberusFullUrl) {335 // Check answer format336 Matcher matcher = EXECUTION_ID_FROM_ANSWER_PATTERN.matcher(answer);337 if (!matcher.find()) {338 LOG.error("Bad answer format (could not find 'RunID = '). URL Called: " + cerberusFullUrl);339 LOG.error("Bad answer format (could not find 'RunID = '). Answer: " + answer);340 throw new RunQueueProcessException("Error occured when calling the service to run the testcase. Service answer did not have the expected format (missing 'RunID = '). Probably due to bad cerberus_url value. URL Called: '" + cerberusUrl + "'.");341 }342 // Extract the return code343 Long executionID;344 try {345 executionID = Long.parseLong(matcher.group(1));346 } catch (NumberFormatException e) {347 LOG.error("Bad answer format (executionId is not numeric). Answer: " + answer);348 throw new RunQueueProcessException("Bad return code format: " + matcher.group(1));349 }350 // Check if return code is in error351 if (executionID == 0) {352 Matcher descriptionMatcher = RETURN_CODE_DESCRIPTION_FROM_ANSWER_PATTERN.matcher(answer);353 if (!descriptionMatcher.find()) {354 LOG.error("Bad answer format (could not find 'ReturnCodeDescription = '). URL Called: " + cerberusFullUrl);355 LOG.error("Bad answer format (could not find 'ReturnCodeDescription = '). Answer: " + answer);356 throw new RunQueueProcessException("Error occured when calling the service to run the testcase. Service answer did not have the expected format (missing 'ReturnCodeDescription = '). Probably due to bad cerberus_url value. URL Called: '" + cerberusUrl + "'.");357 }358 throw new RunQueueProcessException(descriptionMatcher.group(1));359 }360 }361 /**362 * Control is execution can be executed following consumption constrains.363 * <p>364 * @throws RunQueueProcessException if either daily duration of nb of365 * execution limit has been reached.366 * @see #run()367 */368 private void checkCreditLimit() {369 int maxNbExe = parameterService.getParameterIntegerByKey(Parameter.VALUE_cerberus_creditlimit_nbexeperday, "", 0);370 int maxSecondExe = parameterService.getParameterIntegerByKey(Parameter.VALUE_cerberus_creditlimit_secondexeperday, "", 0);371 if ((maxNbExe != 0) && (sessionCounter.getCreditLimitNbExe() >= maxNbExe)) {372 throw new RunQueueProcessException("Your Number of Execution Credit Limit (" + maxNbExe + ") was been reached !!!");373 }374 if ((maxSecondExe != 0) && (sessionCounter.getCreditLimitSecondExe() >= maxSecondExe)) {375 throw new RunQueueProcessException("Your Execution Time Credit Limit (" + maxSecondExe + " min) was been reached !!!");376 }377 }378 @Override379 public String toString() {380 return this.cerberusExecutionUrl;381 }382}...
toString
Using AI Code Generation
1String robotExecutorAsString = robotExecutor.toString();2RobotExecutor robotExecutorFromString = new RobotExecutor(robotExecutorAsString);3assertThat(robotExecutor).isEqualTo(robotExecutorFromString);4assertThat(robotExecutor).isNotSameAs(robotExecutorFromString);5assertThat(robotExecutorFromString).isNotSameAs(new RobotExecutor(robotExecutorAsString));6assertThat(robotExecutorFromString).isEqualTo(new RobotExecutor(robotExecutorAsString));7assertThat(new RobotExecutor(robotExecutorAsString)).isEqualTo(new RobotExecutor(robotExecutorAsString));8assertThat(new RobotExecutor(robotExecutorAsString)).isNotSameAs(new RobotExecutor(robotExecutorAsString));9assertThat(new RobotExecutor(robotExecutorAsString)).isNotSameAs(robotExecutor);10assertThat(new RobotExecutor(robotExecutorAsString)).isEqualTo(robotExecutor);11assertThat(robotExecutor).isNotSameAs(new RobotExecutor(robotExecutorAsString));12assertThat(robotExecutor).isEqualTo(new RobotExecutor(robotExecutorAsString));13assertThat(robotExecutorFromString).isNotSameAs(new RobotExecutor(robotExecutorAsString));14assertThat(robotExecutorFromString).isEqualTo(new RobotExecutor(robotExecutorAsString));15assertThat(new RobotExecutor(robotExecutorAsString)).isEqualTo(new RobotExecutor(robotExecutorAsString));
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!!