How to use ParamRequestMaker class of org.cerberus.util package

Best Cerberus-source code snippet using org.cerberus.util.ParamRequestMaker

Source:ExecutionQueueWorkerThread.java Github

copy

Full Screen

...36import org.cerberus.crud.service.ITestCaseExecutionQueueDepService;37import org.cerberus.engine.execution.IRetriesService;38import org.cerberus.exception.CerberusException;39import org.cerberus.servlet.zzpublic.RunTestCaseV001;40import org.cerberus.util.ParamRequestMaker;41import org.cerberus.util.ParameterParserUtil;42import org.cerberus.util.StringUtil;43/**44 *45 * @author bcivel46 */47public class ExecutionQueueWorkerThread implements Runnable {48 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(ExecutionQueueWorkerThread.class);49 private ITestCaseExecutionQueueService queueService;50 private IRetriesService retriesService;51 private ITestCaseExecutionQueueDepService queueDepService;52 private ExecutionQueueThreadPool execThreadPool;53 private long queueId;54 private String robotExecutor;55 private String selectedRobotHost;56 private String selectedRobotExtHost;57 private TestCaseExecutionQueue toExecute;58 private String cerberusExecutionUrl;59 private int toExecuteTimeout;60 private Future<?> future;61 private static final Pattern EXECUTION_ID_FROM_ANSWER_PATTERN = Pattern.compile("^id = (\\d+)$", Pattern.MULTILINE);62 private static final Pattern RETURN_CODE_DESCRIPTION_FROM_ANSWER_PATTERN = Pattern.compile("^controlMessage = (.*)$", Pattern.MULTILINE);63 public static String PARAMETER_OUTPUT_FORMAT_VALUE = "verbose-txt";64 private ParamRequestMaker makeParamRequest() {65 ParamRequestMaker paramRequestMaker = new ParamRequestMaker();66 try {67 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TEST, URLEncoder.encode(getToExecute().getTest(), "UTF-8"));68 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TEST_CASE, URLEncoder.encode(getToExecute().getTestCase(), "UTF-8"));69 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_COUNTRY, getToExecute().getCountry());70 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ENVIRONMENT, getToExecute().getEnvironment());71 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOT, getToExecute().getRobot());72 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOTEXECUTOR, getRobotExecutor());73 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOT_IP, getToExecute().getRobotIP());74 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_ROBOT_PORT, getToExecute().getRobotPort());75 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_BROWSER, getToExecute().getBrowser());76 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_BROWSER_VERSION, getToExecute().getBrowserVersion());77 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_PLATFORM, getToExecute().getPlatform());78 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SCREEN_SIZE, getToExecute().getScreenSize());79 if (getToExecute().getManualURL() >= 1) { // 1 (Activate) or 2 (Override)80 if (getToExecute().getManualURL() == 1) { // set manual url only if 1. if 2, manual url == false and, we ovveride host, contextroot, login and env data if attributs available81 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_MANUAL_URL, ParameterParserUtil.DEFAULT_BOOLEAN_TRUE_VALUE);82 }83 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_HOST, getToExecute().getManualHost(), true);84 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_CONTEXT_ROOT, getToExecute().getManualContextRoot(), true);85 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_LOGIN_RELATIVE_URL, getToExecute().getManualLoginRelativeURL(), true);86 addIfNotNullOrEmpty(paramRequestMaker, RunTestCaseV001.PARAMETER_MANUAL_ENV_DATA, getToExecute().getManualEnvData(), false);87 }88 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TAG, URLEncoder.encode(getToExecute().getTag(), "UTF-8"));89 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SCREENSHOT, Integer.toString(getToExecute().getScreenshot()));90 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_VERBOSE, Integer.toString(getToExecute().getVerbose()));91 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_TIMEOUT, getToExecute().getTimeout());92 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_PAGE_SOURCE, Integer.toString(getToExecute().getPageSource()));93 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SELENIUM_LOG, Integer.toString(getToExecute().getSeleniumLog()));94 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_EXECUTION_QUEUE_ID, Long.toString(getToExecute().getId()));95 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_NUMBER_OF_RETRIES, Long.toString(getToExecute().getRetries()));96 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_EXECUTOR, getToExecute().getUsrCreated());97 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_MANUAL_EXECUTION, getToExecute().getManualExecution());98 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_OUTPUT_FORMAT, PARAMETER_OUTPUT_FORMAT_VALUE);99 paramRequestMaker.addParam(RunTestCaseV001.PARAMETER_SYNCHRONEOUS, ParameterParserUtil.DEFAULT_BOOLEAN_TRUE_VALUE);100 } catch (UnsupportedEncodingException ex) {101 LOG.error("Error when encoding string in URL : ", ex);102 }103 return paramRequestMaker;104 }105 /**106 * The associated {@link RuntimeException} for any errors during the run107 * process108 */109 public static class RunQueueProcessException extends RuntimeException {110 public RunQueueProcessException(String message) {111 super(message);112 }113 public RunQueueProcessException(String message, Throwable cause) {114 super(message, cause);115 }116 }117 public ITestCaseExecutionQueueDepService getQueueDepService() {118 return queueDepService;119 }120 public void setQueueDepService(ITestCaseExecutionQueueDepService queueDepService) {121 this.queueDepService = queueDepService;122 }123 public String getRobotExecutor() {124 return robotExecutor;125 }126 public void setRobotExecutor(String robotExecutor) {127 this.robotExecutor = robotExecutor;128 }129 public String getSelectedRobotHost() {130 return selectedRobotHost;131 }132 public void setSelectedRobotHost(String selectedRobotHost) {133 this.selectedRobotHost = selectedRobotHost;134 }135 public String getSelectedRobotExtHost() {136 return selectedRobotExtHost;137 }138 public void setSelectedRobotExtHost(String selectedRobotExtHost) {139 this.selectedRobotExtHost = selectedRobotExtHost;140 }141 public TestCaseExecutionQueue getToExecute() {142 return toExecute;143 }144 private void setToExecute(TestCaseExecutionQueue toExecute) {145 this.toExecute = toExecute;146 }147 public ITestCaseExecutionQueueService getQueueService() {148 return queueService;149 }150 public void setQueueService(ITestCaseExecutionQueueService queueService) {151 this.queueService = queueService;152 }153 public void setRetriesService(IRetriesService retriesService) {154 this.retriesService = retriesService;155 }156 public void setCerberusExecutionUrl(String url) {157 this.cerberusExecutionUrl = url;158 }159 public void setQueueId(long queueId) {160 this.queueId = queueId;161 }162 public void setExecThreadPool(ExecutionQueueThreadPool etp) {163 this.execThreadPool = etp;164 }165 public void setFuture(Future<?> future) {166 this.future = future;167 }168 public int getToExecuteTimeout() {169 return toExecuteTimeout;170 }171 public void setToExecuteTimeout(int toExecuteTimeout) {172 this.toExecuteTimeout = toExecuteTimeout;173 }174 @Override175 public void run() {176 try {177 LOG.debug("Start to execute : " + queueId + " with RobotHost : " + selectedRobotHost+ " with RobotExtensionHost : " + selectedRobotExtHost);178 // Flag the queue entry to STARTING179 queueService.updateToStarting(queueId, selectedRobotHost, selectedRobotExtHost);180 LOG.debug("Get queue exe to execute : " + queueId);181 // Getting the queue full object.182 setToExecute(queueService.convert(queueService.readByKey(queueId, false)));183 StringBuilder url = new StringBuilder();184 url.append(cerberusExecutionUrl);185 url.append(RunTestCaseV001.SERVLET_URL);186 url.append("?");187 url.append(makeParamRequest().mkString().replace(" ", "+"));188 LOG.debug("Make http call : " + queueId);189 // Make the http call and parse the output.190 runParseAnswer(runExecution(url), cerberusExecutionUrl + RunTestCaseV001.SERVLET_URL, url.toString());191 } catch (Exception e) {192 LOG.warn("Execution in queue " + queueId + " has finished with error");193 try {194 queueService.updateToError(queueId, e.getMessage());195 queueDepService.manageDependenciesEndOfQueueExecution(queueId);196 } catch (CerberusException again) {197 LOG.error("Unable to mark execution in queue " + queueId + " as in error", again);198 }199 }200 }201 /**202 * Request execution of the inner {@link TestCaseExecutionQueue} to the203 * {@link RunTestCase} servlet204 *205 * @return the execution answer from the {@link RunTestCase} servlet206 * @throws RunQueueProcessException if an error occurred during request207 * execution208 * @see #run()209 */210 private String runExecution(StringBuilder url) {211 try {212 LOG.debug("Trigger Execution to URL : " + url.toString());213 LOG.debug("Trigger Execution with TimeOut : " + toExecuteTimeout);214 CloseableHttpClient httpclient = HttpClientBuilder.create().disableAutomaticRetries().build();215 RequestConfig requestConfig = RequestConfig.custom()216 .setConnectTimeout(toExecuteTimeout)217 .setConnectionRequestTimeout(toExecuteTimeout)218 .setSocketTimeout(toExecuteTimeout)219 .build();220 HttpGet httpGet = new HttpGet(url.toString());221 httpGet.setConfig(requestConfig);222 CloseableHttpResponse response = httpclient.execute(httpGet);223 HttpEntity entity = response.getEntity();224 String responseContent = EntityUtils.toString(entity);225 return responseContent;226 } catch (Exception e) {227 final StringBuilder errorMessage = new StringBuilder("An unexpected error occurred during test case execution: ");228 if (e instanceof HttpResponseException) {229 errorMessage.append(String.format("%d (%s)", ((HttpResponseException) e).getStatusCode(), e.getMessage()));230 } else {231 errorMessage.append(e.getMessage());232 errorMessage.append(". Check server logs");233 }234 LOG.error(errorMessage.toString(), e);235 throw new RunQueueProcessException(errorMessage.toString(), e);236 }237 }238 /**239 * Parse the answer given by the {@link RunTestCase}240 * <p>241 * @param answer the {@link RunTestCase}'s answer242 * @throws RunQueueProcessException if an error occurred if execution was on243 * failure or if answer cannot be parsed244 * @see #run()245 */246 private void runParseAnswer(String answer, String cerberusUrl, String cerberusFullUrl) {247 // Check answer format248 Matcher matcher = EXECUTION_ID_FROM_ANSWER_PATTERN.matcher(answer);249 if (!matcher.find()) {250 LOG.error("Bad answer format (could not find 'RunID = '). URL Called: " + cerberusFullUrl);251 LOG.error("Bad answer format (could not find 'RunID = '). Answer: " + answer);252 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 + "'.");253 }254 // Extract the return code255 Long executionID;256 try {257 executionID = Long.parseLong(matcher.group(1));258 } catch (NumberFormatException e) {259 LOG.error("Bad answer format (executionId is not numeric). Answer: " + answer);260 throw new RunQueueProcessException("Bad return code format: " + matcher.group(1));261 }262 // Check if return code is in error263 if (executionID == 0) {264 Matcher descriptionMatcher = RETURN_CODE_DESCRIPTION_FROM_ANSWER_PATTERN.matcher(answer);265 if (!descriptionMatcher.find()) {266 LOG.error("Bad answer format (could not find 'ReturnCodeDescription = '). URL Called: " + cerberusFullUrl);267 LOG.error("Bad answer format (could not find 'ReturnCodeDescription = '). Answer: " + answer);268 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 + "'.");269 }270 throw new RunQueueProcessException(descriptionMatcher.group(1));271 }272 }273 @Override274 public String toString() {275 return this.cerberusExecutionUrl;276 }277 private void addIfNotNullOrEmpty(ParamRequestMaker paramRequestMaker, String key, String value, boolean encode) throws UnsupportedEncodingException {278 if (!StringUtil.isNullOrEmpty(value)) {279 paramRequestMaker.addParam(key, encode ? URLEncoder.encode(value, "UTF-8") : value);280 }281 }282}...

Full Screen

Full Screen

ParamRequestMaker

Using AI Code Generation

copy

Full Screen

1package org.cerberus.sikulixapi;2import org.cerberus.util.ParamRequestMaker;3import org.cerberus.util.ParameterParser;4import org.sikuli.script.App;5import org.sikuli.script.FindFailed;6import org.sikuli.script.Key;7import org.sikuli.script.Screen;8import org.sikuli.script.SikulixForJython;9public class SikulixApi {10 private static final Screen SCREEN = new Screen();11 private static final String PARAMETER_FILE = "C:\\Users\\Jenkins\\Documents\\NetBeansProjects\\Cerberus\\Cerberus-Parameter.json";12 private static final String PARAMETER_NAME = "sikuli";13 private static final String PARAMETER_KEY = "url";14 public static void main(String[] args) throws FindFailed {15 String url = ParameterParser.parseStringParam(PARAMETER_FILE, PARAMETER_NAME, PARAMETER_KEY);16 String request = ParamRequestMaker.makeRequest(url, "login", "admin", "password", "admin");17 App.open("C:\\Program Files (x86)\\Google\\Chrome\\Application\\chrome.exe");18 SCREEN.wait("1401698528227.png", 10);19 SCREEN.type("1401698528227.png", request);20 SCREEN.type(Key.ENTER);21 }22}23package org.cerberus.sikulixapi;24import org.cerberus.util.ParamRequestMaker;25import org.cerberus.util.ParameterParser;26import org.sikuli.script.App;27import org.sikuli.script.FindFailed;28import org.sikuli.script.Key;29import org.sikuli.script.Screen;30import org.sikuli.script.SikulixForJython;31public class SikulixApi {32 private static final Screen SCREEN = new Screen();33 private static final String PARAMETER_FILE = "C:\\Users\\Jenkins\\Documents\\NetBeansProjects\\Cerberus\\Cerberus-Parameter.json";34 private static final String PARAMETER_NAME = "sikuli";35 private static final String PARAMETER_KEY = "url";

Full Screen

Full Screen

ParamRequestMaker

Using AI Code Generation

copy

Full Screen

1import org.cerberus.util.*;2ParamRequestMaker prm = new ParamRequestMaker();3prm.addParam("name", "John");4println(response);5prm = new ParamRequestMaker();6prm.addParam("name", "Peter");7println(response);8prm = new ParamRequestMaker();9prm.addParam("name", "Paul");10println(response);11prm = new ParamRequestMaker();

Full Screen

Full Screen

ParamRequestMaker

Using AI Code Generation

copy

Full Screen

1import groovy.json.JsonSlurper2import org.cerberus.util.ParamRequestMaker3import org.cerberus.util.HttpRequest4import org.cerberus.util.HttpResponse5def http = new HttpRequest()6def pm = new ParamRequestMaker()7def response = new HttpResponse()8def params = pm.createRequestParameters()9params.addStringParam("name", "John")10params.addStringParam("age", "99")11params.addStringParam("country", "USA")12params.addStringParam("state", "California")13def resp = http.post(url, params)14def json = response.getJson(resp)15def jsonSlurper = new JsonSlurper()16def jsonObj = jsonSlurper.parseText(json)17log("Name: " + name)18log("Age: " + age)19log("Country: " + country)20log("State: "

Full Screen

Full Screen

ParamRequestMaker

Using AI Code Generation

copy

Full Screen

1ParamRequestMaker prm = new ParamRequestMaker(request);2String myParam = prm.getParameter("myParam");3String sql = "select * from application where system = '"+myParam+"'";4ResultSet rs = appService.getData(sql);5request.setAttribute("rs", rs);6request.getRequestDispatcher("list.jsp").forward(request, response);7rs.close();8appService.closeConnection();9appService.closeConnection();

Full Screen

Full Screen

ParamRequestMaker

Using AI Code Generation

copy

Full Screen

1import org.cerberus.util.*;2import org.cerberus.util.parameter.*;3import org.cerberus.util.parameter.generator.*;4import org.cerberus.util.parameter.generator.impl.*;5import org.cerberus.util.parameter.generator.impl.numeric.*;6import org.cerberus.util.parameter.generator.impl.text.*;7import org.cerberus.util.parameter.generator.impl.time.*;8import org.cerberus.util.parameter.generator.impl.time.impl.*;9import org.cerberus.util.parameter.generator.impl.time.impl.date.*;10import org.cerberus.util.parameter.generator.impl.time.impl.time.*;11ParamRequestMaker prm = new ParamRequestMaker();12prm.setMethod("GET");13prm.setPath("/ReadTestCase");14prm.addParam("test", "TEST");15prm.addParam("testcase", "TC1");16prm.setAccept("application/json");17prm.setAcceptCharset("UTF-8");18prm.setAcceptEncoding("gzip, deflate");19prm.setAcceptLanguage("en-US,en;q=0.8");20prm.setConnection("keep-alive");21prm.setHost("localhost:8080");22prm.setUserAgent("Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/52.0.2743.116 Safari/537.36");23String script = prm.generateTestScript("jmeter", "testName", "testDescription", "testAuthor");24log.info(script);25prm.execute();26Response response = prm.getResponse();27String responseBody = response.getBody().asString();28int responseCode = response.getStatusCode();29long responseTime = response.getTime();

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 ParamRequestMaker

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