Best Cerberus-source code snippet using org.cerberus.servlet.zzpublic.AddToExecutionQueue.ParameterException
Source:AddToExecutionQueue.java
...63 * Exception thrown when the parameter scanning process goes wrong.64 *65 * @author abourdon66 */67 private static class ParameterException extends Exception {68 private static final long serialVersionUID = 1L;69 public ParameterException(String message) {70 super(message);71 }72 public ParameterException(String message, Throwable cause) {73 super(message, cause);74 }75 }76 private static final long serialVersionUID = 1L;77 private static final Logger LOG = LogManager.getLogger(AddToExecutionQueue.class);78 private static final String PARAMETER_SELECTED_TEST = "SelectedTest";79 private static final String PARAMETER_SELECTED_TEST_TEST = "Test";80 private static final String PARAMETER_SELECTED_TEST_TEST_CASE = "TestCase";81 private static final String PARAMETER_COUNTRY = "Country";82 private static final String PARAMETER_ENVIRONMENT = "Environment";83 private static final String PARAMETER_ROBOT = "Robot";84 private static final String PARAMETER_ROBOT_IP = "ss_ip";85 private static final String PARAMETER_ROBOT_PORT = "ss_p";86 private static final String PARAMETER_BROWSER = "Browser";87 private static final String PARAMETER_BROWSER_VERSION = "BrowserVersion";88 private static final String PARAMETER_PLATFORM = "Platform";89 private static final String PARAMETER_MANUAL_URL = "ManualURL";90 private static final String PARAMETER_MANUAL_HOST = "ManualHost";91 private static final String PARAMETER_MANUAL_CONTEXT_ROOT = "ManualContextRoot";92 private static final String PARAMETER_MANUAL_LOGIN_RELATIVE_URL = "ManualLoginRelativeURL";93 private static final String PARAMETER_MANUAL_ENV_DATA = "ManualEnvData";94 private static final String PARAMETER_TAG = "Tag";95 private static final String PARAMETER_OUTPUT_FORMAT = "OutputFormat";96 private static final String PARAMETER_SCREENSHOT = "Screenshot";97 private static final String PARAMETER_VERBOSE = "Verbose";98 private static final String PARAMETER_TIMEOUT = "timeout";99 private static final String PARAMETER_SYNCHRONEOUS = "Synchroneous";100 private static final String PARAMETER_PAGE_SOURCE = "PageSource";101 private static final String PARAMETER_SELENIUM_LOG = "SeleniumLog";102 private static final String PARAMETER_CAMPAIGN = "SelectedCampaign";103 private static final String PARAMETER_RETRIES = "retries";104 private static final String PARAMETER_MANUAL_EXECUTION = "manualExecution";105 private static final int DEFAULT_VALUE_SCREENSHOT = 0;106 private static final int DEFAULT_VALUE_MANUAL_URL = 0;107 private static final int DEFAULT_VALUE_VERBOSE = 0;108 private static final long DEFAULT_VALUE_TIMEOUT = 300;109 private static final int DEFAULT_VALUE_PAGE_SOURCE = 1;110 private static final int DEFAULT_VALUE_SELENIUM_LOG = 1;111 private static final int DEFAULT_VALUE_RETRIES = 0;112 private static final String DEFAULT_VALUE_MANUAL_EXECUTION = "N";113 private static final String LINE_SEPARATOR = "\n";114 private ITestCaseExecutionQueueService inQueueService;115 private IFactoryTestCaseExecutionQueue inQueueFactoryService;116 private IExecutionThreadPoolService executionThreadService;117 private ITestCaseService testCaseService;118 private ICampaignParameterService campaignParameterService;119 @Override120 public void init() throws ServletException {121 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());122 inQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);123 inQueueFactoryService = appContext.getBean(IFactoryTestCaseExecutionQueue.class);124 executionThreadService = appContext.getBean(IExecutionThreadPoolService.class);125 testCaseService = appContext.getBean(ITestCaseService.class);126 campaignParameterService = appContext.getBean(ICampaignParameterService.class);127 }128 @Override129 protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {130 processRequest(req, resp);131 }132 @Override133 protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {134 processRequest(req, resp);135 }136 /**137 * Process request for both GET and POST method.138 *139 * <p>140 * Request processing is divided in two parts:141 * <ol>142 * <li>Getting all test cases which have been sent to this servlet;</li>143 * <li>Try to insert all these test cases to the execution queue.</li>144 * </ol>145 * </p>146 *147 * @param request148 * @param response149 * @throws ServletException150 * @throws IOException151 */152 private void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {153 PrintWriter out = response.getWriter();154 // Loading Services.155 ApplicationContext appContext = WebApplicationContextUtils.getWebApplicationContext(this.getServletContext());156 // Calling Servlet Transversal Util.157 ServletUtil.servletStart(request);158 /**159 * Adding Log entry.160 */161 ILogEventService logEventService = appContext.getBean(ILogEventService.class);162 logEventService.createForPublicCalls("/AddToExecutionQueue", "CALL", "AddToExecutionQueue called : " + request.getRequestURL(), request);163 // Parsing all parameters.164 String tag = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_TAG), "");165// TO BE IMPLEMENTED...166 // Defining help message.167 String helpMessage = "\nThis servlet is used to add to Cerberus execution queue a list of execution specified by various parameters:\n"168 + "- " + PARAMETER_TAG + " [mandatory] : Tag that will be used for every execution triggered. [" + tag + "]\n";169// TO BE IMPLEMENTED...170 // Checking the parameter validity.171 boolean error = false;172 if (tag == null || tag.isEmpty()) {173 out.println("Error - Parameter " + PARAMETER_TAG + " is mandatory.");174 error = true;175 } else if (tag.length() > 255) {176 out.println("Error - Parameter " + PARAMETER_TAG + " is too big. Maximum size is 255. Current size is : " + tag.length());177 error = true;178 }179 // Starting the request only if previous parameters exist.180 if (!error) {181 // Create Tag when exist.182 if (!StringUtil.isNullOrEmpty(tag)) {183 // We create or update it.184 ITagService tagService = appContext.getBean(ITagService.class);185 tagService.createAuto(tag, "", "");186 }187 // Part 1: Getting all test cases which have been sent to this servlet.188 List<TestCaseExecutionQueue> toInserts = null;189 try {190 toInserts = getTestCasesToInsert(request);191 } catch (ParameterException pe) {192 response.sendError(HttpServletResponse.SC_BAD_REQUEST, pe.getMessage());193 return;194 } catch (CerberusException ex) {195 LOG.warn(ex);196 }197 // Part 2: Try to insert all these test cases to the execution queue.198 List<String> errorMessages = new ArrayList<String>();199 for (TestCaseExecutionQueue toInsert : toInserts) {200 try {201 inQueueService.convert(inQueueService.create(toInsert));202 } catch (CerberusException e) {203 String errorMessage = "Unable to insert " + toInsert.toString() + " due to " + e.getMessage();204 LOG.warn(errorMessage);205 errorMessages.add(errorMessage);206 continue;207 }208 }209 // Part 3 : Put these tests in the queue in memory210 try {211 executionThreadService.executeNextInQueueAsynchroneously(false);212 } catch (CerberusException ex) {213 String errorMessage = "Unable to feed the execution queue due to " + ex.getMessage();214 LOG.warn(errorMessage);215 errorMessages.add(errorMessage);216 }217 if (!errorMessages.isEmpty()) {218 StringBuilder errorMessage = new StringBuilder();219 for (String item : errorMessages) {220 errorMessage.append(item);221 errorMessage.append(LINE_SEPARATOR);222 }223 response.sendError(HttpServletResponse.SC_BAD_REQUEST, errorMessage.toString());224 }225 response.sendRedirect("ReportingExecutionByTag.jsp?enc=1&Tag=" + StringUtil.encodeAsJavaScriptURIComponent(request.getParameter(PARAMETER_TAG)));226 } else {227 // In case of errors, we displayu the help message.228 out.println(helpMessage);229 }230 }231 /**232 * Gets all test cases requested to be inserted into the execution queue233 *234 * @param request235 * @return a {@link List} of {@link TestCaseExecutionQueue} which have been236 * defined into the request.237 * @throws ParameterException238 */239 private List<TestCaseExecutionQueue> getTestCasesToInsert(HttpServletRequest request) throws ParameterException, CerberusException {240 final String charset = request.getCharacterEncoding();241 // Select test cases and associated parameters to run242 List<Map<String, String>> selectedTests;243 List<String> countries;244 List<String> environments;245 List<String> browsers;246 final String campaign = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_CAMPAIGN), null, charset);247 if (campaign == null || campaign.isEmpty()) {248 selectedTests = ParameterParserUtil.parseListMapParamAndDecode(request.getParameterValues(PARAMETER_SELECTED_TEST), null, charset);249 if (selectedTests == null || selectedTests.isEmpty()) {250 throw new ParameterException("Selected tests are not defined");251 }252 countries = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues(PARAMETER_COUNTRY), null, charset);253 if (countries == null || countries.isEmpty()) {254 throw new ParameterException("Countries are not defined");255 }256 environments = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues(PARAMETER_ENVIRONMENT), null, charset);257 if (environments == null || environments.isEmpty()) {258 throw new ParameterException("Environment are not defined");259 }260 browsers = ParameterParserUtil.parseListParamAndDecode(request.getParameterValues(PARAMETER_BROWSER), null, charset);261 if (browsers == null || browsers.isEmpty()) {262 throw new ParameterException("Browsers are not defined");263 }264 } else {265 final AnswerItem<Map<String, List<String>>> parsedCampaignParameters = campaignParameterService.parseParametersByCampaign(campaign);266 if (!parsedCampaignParameters.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {267 throw new ParameterException("Unable to get selected campaign or associated parameters");268 }269 countries = parsedCampaignParameters.getItem().get(CampaignParameter.COUNTRY_PARAMETER);270 if (countries == null || countries.isEmpty()) {271 throw new ParameterException("Selected campaign does not defined any country");272 }273 environments = parsedCampaignParameters.getItem().get(CampaignParameter.ENVIRONMENT_PARAMETER);274 if (environments == null || environments.isEmpty()) {275 throw new ParameterException("Selected campaign does not defined any environment");276 }277 browsers = parsedCampaignParameters.getItem().get(CampaignParameter.BROWSER_PARAMETER);278 if (browsers == null || browsers.isEmpty()) {279 throw new ParameterException("Selected campaign does not defined any browser");280 }281 selectedTests = new ArrayList<>();282 for (final TestCase testCase : testCaseService.findTestCaseByCampaignNameAndCountries(campaign, countries.toArray(new String[countries.size()])).getItem()) {283 selectedTests.add(new HashMap<String, String>() {284 {285 put(PARAMETER_SELECTED_TEST_TEST, testCase.getTest());286 put(PARAMETER_SELECTED_TEST_TEST_CASE, testCase.getTestCase());287 }288 });289 }290 if (selectedTests.isEmpty()) {291 throw new ParameterException("Selected campaign does not defined any test case");292 }293 }294 final String tag = ParameterParserUtil.parseStringParam(request.getParameter(PARAMETER_TAG), "");295 if (tag == null || tag.isEmpty()) {296 throw new ParameterException("Tag is not defined");297 }298 Date requestDate = new Date();299 String robot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_ROBOT), null, charset);300 String robotIP = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_ROBOT_IP), null, charset);301 String robotPort = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_ROBOT_PORT), null, charset);302 String browserVersion = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_BROWSER_VERSION), null, charset);303 String platform = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_PLATFORM), null, charset);304 int manualURL = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter(PARAMETER_MANUAL_URL), DEFAULT_VALUE_MANUAL_URL, charset);305 String manualHost = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_MANUAL_HOST), null, charset);306 String manualContextRoot = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_MANUAL_CONTEXT_ROOT), null, charset);307 String manualLoginRelativeURL = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_MANUAL_LOGIN_RELATIVE_URL), null, charset);308 String manualEnvData = ParameterParserUtil.parseStringParamAndDecodeAndSanitize(request.getParameter(PARAMETER_MANUAL_ENV_DATA), null, charset);309 int screenshot = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter(PARAMETER_SCREENSHOT), DEFAULT_VALUE_SCREENSHOT, charset);310 int verbose = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter(PARAMETER_VERBOSE), DEFAULT_VALUE_VERBOSE, charset);311 String timeout = request.getParameter(PARAMETER_TIMEOUT);312 int pageSource = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter(PARAMETER_PAGE_SOURCE), DEFAULT_VALUE_PAGE_SOURCE, charset);313 int seleniumLog = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter(PARAMETER_SELENIUM_LOG), DEFAULT_VALUE_SELENIUM_LOG, charset);314 int retries = ParameterParserUtil.parseIntegerParamAndDecode(request.getParameter(PARAMETER_RETRIES), DEFAULT_VALUE_RETRIES, charset);315 String manualExecution = ParameterParserUtil.parseStringParamAndDecode(request.getParameter(PARAMETER_MANUAL_EXECUTION), DEFAULT_VALUE_MANUAL_EXECUTION, charset);316 List<TestCaseExecutionQueue> inQueues = new ArrayList<TestCaseExecutionQueue>();317 for (Map<String, String> selectedTest : selectedTests) {318 String test = selectedTest.get(PARAMETER_SELECTED_TEST_TEST);319 String testCase = selectedTest.get(PARAMETER_SELECTED_TEST_TEST_CASE);320 for (String country : countries) {321 for (String environment : environments) {322 for (String browser : browsers) {323 try {324 String user = request.getRemoteUser() == null ? "" : request.getRemoteUser();325 inQueues.add(inQueueFactoryService.create(test, testCase, country, environment, robot, robotIP, robotPort, browser, browserVersion,326 platform, "", manualURL, manualHost, manualContextRoot, manualLoginRelativeURL, manualEnvData, tag, screenshot, verbose, timeout, pageSource,327 seleniumLog, 0, retries, manualExecution, 1000, user, null, null, null));328 } catch (FactoryCreationException e) {329 throw new ParameterException("Unable to insert record due to: " + e.getMessage(), e);330 }331 }332 }333 }334 }335 return inQueues;336 }337}...
ParameterException
Using AI Code Generation
1import org.cerberus.servlet.zzpublic.AddToExecutionQueue;2AddToExecutionQueue p = new AddToExecutionQueue();3p.setParameterException("test","test","test","test","test","test","test");4import org.cerberus.servlet.zzpublic.AddToExecutionQueue;5AddToExecutionQueue p = new AddToExecutionQueue();6p.setParameterException("test","test","test","test","test","test","test");7import org.cerberus.servlet.zzpublic.AddToExecutionQueue;8AddToExecutionQueue p = new AddToExecutionQueue();9p.setParameterException("test","test","test","test","test","test","test");10import org.cerberus.servlet.zzpublic.AddToExecutionQueue;11AddToExecutionQueue p = new AddToExecutionQueue();12p.setParameterException("test","test","test","test","test","test","test");13import org.cerberus.servlet.zzpublic.AddToExecutionQueue;14AddToExecutionQueue p = new AddToExecutionQueue();15p.setParameterException("test","test","test","test","test","test","test");16import org.cerberus.servlet.zzpublic.AddToExecutionQueue;17AddToExecutionQueue p = new AddToExecutionQueue();18p.setParameterException("test","test","test","test","test","test","test");19import org.cerberus.servlet.zzpublic.AddToExecutionQueue;20AddToExecutionQueue p = new AddToExecutionQueue();21p.setParameterException("test","test","test","test","test","test","test");22import org.cerberus.servlet.zzpublic.AddToExecutionQueue;23AddToExecutionQueue p = new AddToExecutionQueue();24p.setParameterException("test","test","test","
ParameterException
Using AI Code Generation
1import org.cerberus.servlet.zzpublic.AddToExecutionQueue;2import org.cerberus.servlet.zzpublic.ParameterException;3String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");4import org.cerberus.servlet.zzpublic.AddToExecutionQueue;5import org.cerberus.servlet.zzpublic.ParameterException;6String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");7import org.cerberus.servlet.zzpublic.AddToExecutionQueue;8import org.cerberus.servlet.zzpublic.ParameterException;9String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");10import org.cerberus.servlet.zzpublic.AddToExecutionQueue;11import org.cerberus.servlet.zzpublic.ParameterException;12String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");13import org.cerberus.servlet.zzpublic.AddToExecutionQueue;14import org.cerberus.servlet.zzpublic.ParameterException;15String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");16import org.cerberus.servlet.zzpublic.AddToExecutionQueue;17import org.cerberus.servlet.zzpublic.ParameterException;18String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");19import org.cerberus.servlet.zzpublic.AddToExecutionQueue;20import org.cerberus.servlet.zzpublic.ParameterException;21String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");22import org.cerberus.servlet.zzpublic.AddToExecutionQueue;23import org.cerberus.servlet.zzpublic.ParameterException;24String testcaseName = AddToExecutionQueue.getTestCaseName("testcase");25import org.cerberus.servlet.zzpublic
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!!