How to use RunTestCase class of org.cerberus.servlet.zzpublic package

Best Cerberus-source code snippet using org.cerberus.servlet.zzpublic.RunTestCase

Source:ExecutionQueueWorkerThread.java Github

copy

Full Screen

...33import org.apache.http.util.EntityUtils;34import org.cerberus.crud.entity.TestCaseExecutionQueue;35import org.cerberus.crud.service.ITestCaseExecutionQueueService;36import org.cerberus.exception.CerberusException;37import org.cerberus.servlet.zzpublic.RunTestCase;38import org.cerberus.util.ParamRequestMaker;39import org.cerberus.util.ParameterParserUtil;40/**41 *42 * @author bcivel43 */44public class ExecutionQueueWorkerThread implements Runnable {45 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(ExecutionQueueWorkerThread.class);46 private ITestCaseExecutionQueueService queueService;47 private ExecutionQueueThreadPool execThreadPool;48 private long queueId;49 private TestCaseExecutionQueue toExecute;50 private String cerberusExecutionUrl;51 private int toExecuteTimeout;52 private Future<?> future;53 private static final Pattern EXECUTION_ID_FROM_ANSWER_PATTERN = Pattern.compile("^RunID = (\\d+)$", Pattern.MULTILINE);54 private static final Pattern RETURN_CODE_DESCRIPTION_FROM_ANSWER_PATTERN = Pattern.compile("^ReturnCodeDescription = (.*)$", Pattern.MULTILINE);55 public static String PARAMETER_OUTPUT_FORMAT_VALUE = "verbose-txt";56 private ParamRequestMaker makeParamRequest() {57 ParamRequestMaker paramRequestMaker = new ParamRequestMaker();58 try {59 paramRequestMaker.addParam(RunTestCase.PARAMETER_TEST, URLEncoder.encode(getToExecute().getTest(), "UTF-8"));60 paramRequestMaker.addParam(RunTestCase.PARAMETER_TEST_CASE, URLEncoder.encode(getToExecute().getTestCase(), "UTF-8"));61 paramRequestMaker.addParam(RunTestCase.PARAMETER_COUNTRY, getToExecute().getCountry());62 paramRequestMaker.addParam(RunTestCase.PARAMETER_ENVIRONMENT, getToExecute().getEnvironment());63 paramRequestMaker.addParam(RunTestCase.PARAMETER_ROBOT, getToExecute().getRobot());64 paramRequestMaker.addParam(RunTestCase.PARAMETER_ROBOT_IP, getToExecute().getRobotIP());65 paramRequestMaker.addParam(RunTestCase.PARAMETER_ROBOT_PORT, getToExecute().getRobotPort());66 paramRequestMaker.addParam(RunTestCase.PARAMETER_BROWSER, getToExecute().getBrowser());67 paramRequestMaker.addParam(RunTestCase.PARAMETER_BROWSER_VERSION, getToExecute().getBrowserVersion());68 paramRequestMaker.addParam(RunTestCase.PARAMETER_PLATFORM, getToExecute().getPlatform());69 paramRequestMaker.addParam(RunTestCase.PARAMETER_SCREEN_SIZE, getToExecute().getScreenSize());70 if (getToExecute().getManualURL() >= 1) {71 paramRequestMaker.addParam(RunTestCase.PARAMETER_MANUAL_URL, ParameterParserUtil.DEFAULT_BOOLEAN_TRUE_VALUE);72 paramRequestMaker.addParam(RunTestCase.PARAMETER_MANUAL_HOST, URLEncoder.encode(getToExecute().getManualHost(), "UTF-8"));73 paramRequestMaker.addParam(RunTestCase.PARAMETER_MANUAL_CONTEXT_ROOT, URLEncoder.encode(getToExecute().getManualContextRoot(), "UTF-8"));74 paramRequestMaker.addParam(RunTestCase.PARAMETER_MANUAL_LOGIN_RELATIVE_URL, URLEncoder.encode(getToExecute().getManualLoginRelativeURL(), "UTF-8"));75 paramRequestMaker.addParam(RunTestCase.PARAMETER_MANUAL_ENV_DATA, getToExecute().getManualEnvData());76 }77 paramRequestMaker.addParam(RunTestCase.PARAMETER_TAG, URLEncoder.encode(getToExecute().getTag(), "UTF-8"));78 paramRequestMaker.addParam(RunTestCase.PARAMETER_SCREENSHOT, Integer.toString(getToExecute().getScreenshot()));79 paramRequestMaker.addParam(RunTestCase.PARAMETER_VERBOSE, Integer.toString(getToExecute().getVerbose()));80 paramRequestMaker.addParam(RunTestCase.PARAMETER_TIMEOUT, getToExecute().getTimeout());81 paramRequestMaker.addParam(RunTestCase.PARAMETER_PAGE_SOURCE, Integer.toString(getToExecute().getPageSource()));82 paramRequestMaker.addParam(RunTestCase.PARAMETER_SELENIUM_LOG, Integer.toString(getToExecute().getSeleniumLog()));83 paramRequestMaker.addParam(RunTestCase.PARAMETER_EXECUTION_QUEUE_ID, Long.toString(getToExecute().getId()));84 paramRequestMaker.addParam(RunTestCase.PARAMETER_NUMBER_OF_RETRIES, Long.toString(getToExecute().getRetries()));85 paramRequestMaker.addParam(RunTestCase.PARAMETER_EXECUTOR, getToExecute().getUsrCreated());86 paramRequestMaker.addParam(RunTestCase.PARAMETER_MANUAL_EXECUTION, getToExecute().getManualExecution());87 paramRequestMaker.addParam(RunTestCase.PARAMETER_OUTPUT_FORMAT, PARAMETER_OUTPUT_FORMAT_VALUE);88 paramRequestMaker.addParam(RunTestCase.PARAMETER_SYNCHRONEOUS, ParameterParserUtil.DEFAULT_BOOLEAN_TRUE_VALUE);89 } catch (UnsupportedEncodingException ex) {90 LOG.error("Error when encoding string in URL : ", ex);91 }92 return paramRequestMaker;93 }94 /**95 * The associated {@link RuntimeException} for any errors during the run96 * process97 */98 public static class RunQueueProcessException extends RuntimeException {99 public RunQueueProcessException(String message) {100 super(message);101 }102 public RunQueueProcessException(String message, Throwable cause) {103 super(message, cause);104 }105 }106 public TestCaseExecutionQueue getToExecute() {107 return toExecute;108 }109 private void setToExecute(TestCaseExecutionQueue toExecute) {110 this.toExecute = toExecute;111 }112 public ITestCaseExecutionQueueService getQueueService() {113 return queueService;114 }115 public void setQueueService(ITestCaseExecutionQueueService queueService) {116 this.queueService = queueService;117 }118 public void setCerberusExecutionUrl(String url) {119 this.cerberusExecutionUrl = url;120 }121 public void setQueueId(long queueId) {122 this.queueId = queueId;123 }124 public void setExecThreadPool(ExecutionQueueThreadPool etp) {125 this.execThreadPool = etp;126 }127 public void setFuture(Future<?> future) {128 this.future = future;129 }130 public int getToExecuteTimeout() {131 return toExecuteTimeout;132 }133 public void setToExecuteTimeout(int toExecuteTimeout) {134 this.toExecuteTimeout = toExecuteTimeout;135 }136 @Override137 public void run() {138 try {139 LOG.debug("Start to execute : " + queueId);140 // Flag the queue entry to STARTING141 queueService.updateToStarting(queueId);142 LOG.debug("Get queue exe to execute : " + queueId);143 // Getting the queue full object.144 setToExecute(queueService.convert(queueService.readByKey(queueId)));145 StringBuilder url = new StringBuilder();146 url.append(cerberusExecutionUrl);147 url.append(RunTestCase.SERVLET_URL);148 url.append("?");149 url.append(makeParamRequest().mkString().replace(" ", "+"));150 LOG.debug("Make http call : " + queueId);151 // Make the http call and parse the output.152 runParseAnswer(runExecution(url), cerberusExecutionUrl + RunTestCase.SERVLET_URL, url.toString());153 } catch (RunQueueProcessException e) {154 LOG.warn("Execution in queue " + queueId + " has finished with error");155 try {156 queueService.updateToError(queueId, e.getMessage());157 } catch (CerberusException again) {158 LOG.error("Unable to mark execution in queue " + queueId + " as in error", again);159 }160 } catch (Exception ex) {161 LOG.error(ex);162 } finally {163 }164 }165 /**166 * Request execution of the inner {@link TestCaseExecutionQueue} to the167 * {@link RunTestCase} servlet168 *169 * @return the execution answer from the {@link RunTestCase} servlet170 * @throws RunProcessException if an error occurred during request execution171 * @see #run()172 */173 private String runExecution(StringBuilder url) {174 try {175 LOG.debug("Trigger Execution to URL : " + url.toString());176 LOG.debug("Trigger Execution with TimeOut : " + toExecuteTimeout);177 CloseableHttpClient httpclient = HttpClientBuilder.create().disableAutomaticRetries().build();178 RequestConfig requestConfig = RequestConfig.custom()179 .setConnectTimeout(toExecuteTimeout)180 .setConnectionRequestTimeout(toExecuteTimeout)181 .setSocketTimeout(toExecuteTimeout)182 .build();183 HttpGet httpGet = new HttpGet(url.toString());184 httpGet.setConfig(requestConfig);185 CloseableHttpResponse response = httpclient.execute(httpGet);186 HttpEntity entity = response.getEntity();187 String responseContent = EntityUtils.toString(entity);188 return responseContent;189 } catch (Exception e) {190 final StringBuilder errorMessage = new StringBuilder("An unexpected error occurred during test case execution: ");191 if (e instanceof HttpResponseException) {192 errorMessage.append(String.format("%d (%s)", ((HttpResponseException) e).getStatusCode(), e.getMessage()));193 } else {194 errorMessage.append(e.getMessage());195 errorMessage.append(". Check server logs");196 }197 LOG.error(errorMessage.toString(), e);198 throw new RunQueueProcessException(errorMessage.toString(), e);199 }200 }201 /**202 * Parse the answer given by the {@link RunTestCase}203 * <p>204 * @param answer the {@link RunTestCase}'s answer205 * @throws RunProcessException if an error occurred if execution was on206 * failure or if answer cannot be parsed207 * @see #run()208 */209 private void runParseAnswer(String answer, String cerberusUrl, String cerberusFullUrl) {210 // Check answer format211 Matcher matcher = EXECUTION_ID_FROM_ANSWER_PATTERN.matcher(answer);212 if (!matcher.find()) {213 LOG.error("Bad answer format (could not find 'RunID = '). URL Called: " + cerberusFullUrl);214 LOG.error("Bad answer format (could not find 'RunID = '). Answer: " + answer);215 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 + "'.");216 }217 // Extract the return code218 Long executionID;...

Full Screen

Full Screen

RunTestCase

Using AI Code Generation

copy

Full Screen

1import org.cerberus.servlet.zzpublic.RunTestCase;2import org.cerberus.servlet.zzpublic.RunTestCaseException;3import org.cerberus.servlet.zzpublic.RunTestCaseResponse;4RunTestCaseResponse response = RunTestCase.runTestCase("Test", "TestCase");5if (response.getResultCode() == RunTestCaseResponse.ResultCode.OK) {6 String result = response.getResult();7} else {8 throw new RunTestCaseException(response.getResultCode(), response.getResult());9}10RunTestCaseResponse response = RunTestCase.runTestCase("Test", "TestCase", "Environment", "Country");11if (response.getResultCode() == RunTestCaseResponse.ResultCode.OK) {12 String result = response.getResult();13} else {14 throw new RunTestCaseException(response.getResultCode(), response.getResult());15}16RunTestCaseResponse response = RunTestCase.runTestCase("Test", "TestCase", "Environment", "Country");17if (response.getResultCode() == RunTestCaseResponse.ResultCode.OK) {18 String result = response.getResult();19} else {

Full Screen

Full Screen

RunTestCase

Using AI Code Generation

copy

Full Screen

1package org.cerberus.servlet.zzpublic;2import java.util.logging.Level;3import java.util.logging.Logger;4import org.cerberus.engine.entity.MessageEvent;5import org.cerberus.engine.entity.MessageGeneral;6import org.cerberus.engine.execution.IExecutionManagerService;7import org.cerberus.engine.execution.impl.ExecutionManagerService;8import org.cerberus.engine.queuemanagement.entity.MessageEventBatch;9import org.cerberus.exception.CerberusException;10import org.cerberus.factory.IFactoryMessageEvent;11import org.cerberus.factory.IFactoryMessageEventBatch;12import org.cerberus.factory.impl.FactoryMessageEvent;13import org.cerberus.factory.impl.FactoryMessageEventBatch;14import org.cerberus.log.MyLogger;15import org.cerberus.service.ILogEventService;16import org.cerberus.service.impl.LogEventService;17import org.cerberus.util.answer.AnswerItem;18import org.springframework.context.ApplicationContext;19import org.springframework.context.support.ClassPathXmlApplicationContext;20public class RunTestCase {21 private final ApplicationContext appContext = new ClassPathXmlApplicationContext("classpath:/org/cerberus/applicationContext.xml");22 private final IExecutionManagerService executionManagerService = appContext.getBean(ExecutionManagerService.class);23 private final ILogEventService logEventService = appContext.getBean(LogEventService.class);24 private final IFactoryMessageEventBatch factoryMessageEventBatch = appContext.getBean(FactoryMessageEventBatch.class);25 private final IFactoryMessageEvent factoryMessageEvent = appContext.getBean(FactoryMessageEvent.class);26 public MessageEventBatch runTestCase(String test, String testCase) throws CerberusException {27 MessageEventBatch messageEventBatch = factoryMessageEventBatch.create(null, null, null, null, null, null);28 try {29 AnswerItem<MessageEventBatch> answer = executionManagerService.executeTestCase(test, testCase, null, null, null, null, null, null

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 methods in RunTestCase

Test Your Web Or Mobile Apps On 3000+ Browsers

Signup for free

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful