Best Cerberus-source code snippet using org.cerberus.servlet.zzpublic.AddToExecutionQueueV003.getManualHostMap
Source:AddToExecutionQueueV003.java
...376 int nbenvnotexist = 0;377 int nbrobotmissing = 0;378 boolean tagAlreadyAdded = false;379 Map<String, String> myHostMap = new HashMap<>();380 myHostMap = getManualHostMap(manualHost);381 int nbrobot = 0;382 Map<String, Robot> robotsMap = new HashMap<>();383 if (StringUtil.isNullOrEmpty(robotIP)) {384 if (robots == null || robots.isEmpty()) {385 // RobotIP is not defined and no robot are provided so the content is probably testcases that does not require robot definition.386 if (manualExecution.equalsIgnoreCase("Y") || manualExecution.equalsIgnoreCase("A")) {387 robotIP = "manual";388 robotsMap.put("", robotFactory.create(0, "", platform, browser, "", "Y", "", "", "", screenSize, browser, ""));389 }390 nbrobot = 1;391 } else {392 // Not RobotIP defined but at least 1 robot has been found from servlet call or campaign definition.393 nbrobot = robots.size();394 try {395 // Load the map of robot from input.396 robotsMap = robotService.readToHashMapByRobotList(robots); // load Robots available for the campaign397 nbrobot = robotsMap.size();398 } catch (CerberusException ex) {399 LOG.warn(ex.toString(), ex);400 }401 }402 } else {403 // When RobotIP is feeded, we do not consider the robot definition.404 LOG.debug("Adding fake Robot.");405 nbrobot = 1;406 robots = new ArrayList<>();407 robots.add("");408 robotsMap.put("", robotFactory.create(0, "", platform, browser, "", "Y", "", "", "", screenSize, browser, ""));409 }410 HashMap<String, Application> appMap = new HashMap<>();411 // Starting the request only if previous parameters exist.412 if (!error) {413 int nbtescase = selectTest.size();414 if (environments == null) {415 environments = new ArrayList<>();416 environments.add("MANUAL");417 }418 int nbenv = environments.size();419 int nbcountries = countries.size();420 // Part 0: Load to memory Environments and robots.421 Map<String, String> invariantEnvMap = invariantService.readToHashMapGp1StringByIdname("ENVIRONMENT", "");422 invariantEnvMap.put("MANUAL", "");423 // Part 1: Getting all possible Execution from test cases + countries + environments + browsers which have been sent to this servlet.424 List<TestCaseExecutionQueue> toInserts = new ArrayList<TestCaseExecutionQueue>();425 try {426 HashMap<String, CountryEnvParam> envMap = new HashMap<>();427 LOG.debug("Loading all environments.");428 for (CountryEnvParam envParam : countryEnvParamService.convert(countryEnvParamService.readActiveBySystem(null))) {429 envMap.put(envParam.getSystem() + LOCAL_SEPARATOR + envParam.getCountry() + LOCAL_SEPARATOR + envParam.getEnvironment(), envParam);430 }431 LOG.debug("Nb of TestCase : " + selectTest.size());432 for (int i = 0; i < selectTest.size(); i++) {433// for (String localTest : selectTest) {434 String test = selectTest.get(i);435 String testCase = selectTestCase.get(i);436 TestCase tc = testCaseService.convert(testCaseService.readByKey(test, testCase));437 // TestCases that are not active are not inserted into queue.438 if (tc.getTcActive().equals("Y")) {439 // We only insert testcase that exist for the given country.440 for (TestCaseCountry country : testCaseCountryService.convert(testCaseCountryService.readByTestTestCase(null, test, testCase, null))) {441 if (countries.contains(country.getCountry())) {442 // for each environment we test that correspondng gp1 is compatible with testcase environment flag activation.443 for (String environment : environments) {444 String envGp1 = invariantEnvMap.get(environment);445 if (((envGp1.equals("PROD")) && (tc.getActivePROD().equalsIgnoreCase("Y")))446 || ((envGp1.equals("UAT")) && (tc.getActiveUAT().equalsIgnoreCase("Y")))447 || ((envGp1.equals("QA")) && (tc.getActiveQA().equalsIgnoreCase("Y")))448 || (envGp1.equals("DEV"))449 || (envGp1.equals(""))) {450 // Getting Application in order to check application type against browser.451 appMap = updateMapWithApplication(tc.getApplication(), appMap);452 Application app = appMap.get(tc.getApplication());453 if ((envMap.containsKey(app.getSystem() + LOCAL_SEPARATOR + country.getCountry() + LOCAL_SEPARATOR + environment))454 || (environment.equals("MANUAL"))) {455 // Create Tag only if not already done and defined.456 if (!StringUtil.isNullOrEmpty(tag) && !tagAlreadyAdded) {457 // We create or update it.458 ITagService tagService = appContext.getBean(ITagService.class);459 tagService.createAuto(tag, campaign, user, envJSONArray, countryJSONArray);460 tagAlreadyAdded = true;461 }462 // manage manual host for this execution463 String manualHostforThisApplication = getManualHostForThisApplication(myHostMap, app.getApplication());464 if ((app != null)465 && (app.getType() != null)466 && (app.getType().equalsIgnoreCase(Application.TYPE_GUI) || app.getType().equalsIgnoreCase(Application.TYPE_APK)467 || app.getType().equalsIgnoreCase(Application.TYPE_IPA) || app.getType().equalsIgnoreCase(Application.TYPE_FAT))) {468 for (Map.Entry<String, Robot> entry : robotsMap.entrySet()) {469 String key = entry.getKey();470 Robot robot = entry.getValue();471 try {472 if ("".equals(robot.getType()) || app.getType().equals(robot.getType())) {473 // Robot type is not feeded (not attached to any techno) or robot type match the one of the application.474 LOG.debug("Insert Queue Entry.");475 // We get here the corresponding robotDecli value from robot.476 String robotDecli = robot.getRobotDecli();477 if (StringUtil.isNullOrEmpty(robotDecli)) {478 robotDecli = robot.getRobot();479 }480 if ("".equals(robot.getRobot()) && StringUtil.isNullOrEmpty(robotIP)) {481 // We don't insert the execution for robot application that have no robot and robotIP defined.482 nbrobotmissing++;483 } else {484 toInserts.add(inQueueFactoryService.create(app.getSystem(),485 test, testCase, country.getCountry(), environment,486 robot.getRobot(), robotDecli, robotIP, robotPort, browser,487 browserVersion, platform, screenSize, manualURL,488 manualHostforThisApplication, manualContextRoot,489 manualLoginRelativeURL, manualEnvData, tag,490 screenshot, verbose, timeout, pageSource,491 seleniumLog, 0, retries, manualExecution, priority,492 user, null, null, null));493 }494 } else {495 LOG.debug("Not inserted because app type '" + app.getType() + "' does not match robot type '" + robot.getType() + "'.");496 }497 } catch (FactoryCreationException e) {498 LOG.error("Unable to insert record due to: " + e, e);499 LOG.error("test: " + test + "-" + testCase + "-" + country.getCountry() + "-" + environment + "-" + robots);500 }501 }502 } else {503 // Application does not support robot so we force an empty value.504 LOG.debug("Forcing Robot to empty value. Application type=" + app.getType());505 try {506 LOG.debug("Insert Queue Entry.");507 toInserts.add(inQueueFactoryService.create(app.getSystem(), test,508 testCase, country.getCountry(), environment, "", "", "", "",509 "", "", "", "", manualURL, manualHostforThisApplication, manualContextRoot,510 manualLoginRelativeURL, manualEnvData, tag, screenshot,511 verbose, timeout, pageSource, seleniumLog, 0, retries,512 manualExecution, priority, user, null, null, null));513 } catch (FactoryCreationException e) {514 LOG.error("Unable to insert record due to: " + e, e);515 LOG.error("test: " + test + "-" + testCase + "-" + country.getCountry() + "-" + environment + "-" + robots);516 }517 }518 } else {519 LOG.debug("Env does not exist or is not active.");520 nbenvnotexist = nbenvnotexist + nbrobot;521 }522 } else {523 LOG.debug("Env group not active for testcase : " + environment);524 nbtestcaseenvgroupnotallowed = nbtestcaseenvgroupnotallowed + nbrobot;525 }526 }527 } else {528 LOG.debug("Country does not match. " + countries + " " + country.getCountry());529 }530 }531 } else {532 LOG.debug("TestCase not Active.");533 nbtestcasenotactive = nbtestcasenotactive + (nbcountries * nbenv * nbrobot);534 }535 }536 } catch (CerberusException ex) {537 LOG.warn(ex);538 }539 // Part 2a: Try to insert all these test cases to the execution queue.540 List<String> errorMessages = new ArrayList<>();541 List<Long> queueInsertedIds = new ArrayList<>();542 for (TestCaseExecutionQueue toInsert : toInserts) {543 try {544 inQueueService.convert(inQueueService.create(toInsert, true, 0, TestCaseExecutionQueue.State.QUTEMP));545 nbExe++;546 JSONObject value = new JSONObject();547 value.put("queueId", toInsert.getId());548 value.put("test", toInsert.getTest());549 value.put("testcase", toInsert.getTestCase());550 value.put("country", toInsert.getCountry());551 value.put("environment", toInsert.getEnvironment());552 queueInsertedIds.add(toInsert.getId());553 jsonArray.put(value);554 } catch (CerberusException e) {555 String errorMessageTmp = "Unable to insert " + toInsert.toString() + " due to " + e.getMessage();556 LOG.warn(errorMessageTmp);557 errorMessages.add(errorMessageTmp);558 continue;559 } catch (JSONException ex) {560 LOG.error(ex, ex);561 }562 }563 // Part 2b: move all the execution queue from tag to QUEUE state.564 inQueueService.updateAllTagToQueuedFromQuTemp(tag, queueInsertedIds);565 // Part 3 : Trigger JobQueue566 try {567 executionThreadService.executeNextInQueueAsynchroneously(false);568 } catch (CerberusException ex) {569 String errorMessageTmp = "Unable to feed the execution queue due to " + ex.getMessage();570 LOG.warn(errorMessageTmp);571 errorMessages.add(errorMessageTmp);572 }573 if (!errorMessages.isEmpty()) {574 StringBuilder errorMessageTmp = new StringBuilder();575 for (String item : errorMessages) {576 errorMessageTmp.append(item);577 errorMessageTmp.append(LINE_SEPARATOR);578 }579 errorMessage.append(errorMessageTmp.toString());580 }581 errorMessage.append(nbExe);582 errorMessage.append(" execution(s) succesfully inserted to queue. ");583 if (testcases != null && testcases.getResultMessage().getSource() == MessageEventEnum.DATA_OPERATION_WARNING_PARTIAL_RESULT) {584 errorMessage.append(testcases.getResultMessage().getDescription());585 }586 // Message that everything went fine.587 msg = new MessageEvent(MessageEventEnum.GENERIC_OK);588 }589 // Init Answer with potencial error from Parsing parameter.590 AnswerItem answer = new AnswerItem<>(msg);591 switch (outputFormat) {592 case "json":593 try {594 JSONObject jsonResponse = new JSONObject();595 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());596 jsonResponse.put("message", errorMessage.toString());597 if (error) {598 // Only display help message if error.599 jsonResponse.put("helpMessage", helpMessage);600 }601 jsonResponse.put("tag", tag);602 jsonResponse.put("nbExe", nbExe);603 jsonResponse.put("nbErrorTCNotActive", nbtestcasenotactive);604 jsonResponse.put("nbErrorTCNotAllowedOnEnv", nbtestcaseenvgroupnotallowed);605 jsonResponse.put("nbErrorEnvNotExistOrNotActive", nbenvnotexist);606 jsonResponse.put("nbErrorRobotMissing", nbrobotmissing);607 jsonResponse.put("queueList", jsonArray);608 response.setContentType("application/json");609 response.setCharacterEncoding("utf8");610 response.getWriter().print(jsonResponse.toString());611 } catch (JSONException e) {612 LOG.warn(e);613 //returns a default error message with the json format that is able to be parsed by the client-side614 response.setContentType("application/json");615 response.setCharacterEncoding("utf8");616 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());617 }618 break;619 default:620 response.setContentType("text");621 response.setCharacterEncoding("utf8");622 if (error) {623 errorMessage.append("\n");624 errorMessage.append(helpMessage);625 }626 response.getWriter().print(errorMessage.toString());627 }628 Date date1 = new Date();629 LOG.debug("TOTAL Duration : " + (date1.getTime() - requestDate.getTime()));630 }631 private HashMap<String, Application> updateMapWithApplication(String application, HashMap<String, Application> appMap) throws CerberusException {632 if (!appMap.containsKey(application)) {633 Application app = applicationService.convert(applicationService.readByKey(application));634 appMap.put(application, app);635 }636 return appMap;637 }638 /**639 * @param manualHost640 * @param application641 * @return642 */643 private String getManualHostForThisApplication(Map<String, String> manualHost, String application) {644 if (manualHost.containsKey("")) {645 return manualHost.get("");646 }647 if (manualHost.containsKey(application)) {648 return manualHost.get(application);649 }650 return "";651 }652 /**653 * Convert manualhost parameter to MAP. manual host can be just654 * 'manualHost1' (case 1) or655 * `applicationname1:manualhost1;applicationname2:manualhost2;...` (cases 2)656 * or a json string in format : { "applicationname1" : "manualhost1",657 * "applicationname2" : "manualhost2" } (case 3)658 *659 * @param manualHost660 * @return a Map of application : url661 */662 private Map<String, String> getManualHostMap(String manualHost) {663 Map<String, String> myHostMap = new HashMap<>();664 if (StringUtil.isNullOrEmpty(manualHost)) {665 LOG.debug("Converting from empty.");666 myHostMap.put("", "");667 return myHostMap;668 }669 try {670 JSONObject myJSONObj = new JSONObject(manualHost);671 Iterator<?> nameItr = myJSONObj.keys();672 LOG.debug("Converting from JSON.");673 while (nameItr.hasNext()) {674 String name = (String) nameItr.next();675 myHostMap.put(name, myJSONObj.getString(name));676 }...
getManualHostMap
Using AI Code Generation
1def cerberus = new org.cerberus.servlet.zzpublic.AddToExecutionQueueV003()2def hostMap = cerberus.getManualHostMap()3hostMap.each{ key, value ->4}5def cerberus = new org.cerberus.servlet.zzpublic.AddToExecutionQueueV003()6def hostMap = cerberus.getManualHostMap()7hostMap.each{ key, value ->8}9def cerberus = new org.cerberus.servlet.zzpublic.AddToExecutionQueueV003()10def hostMap = cerberus.getManualHostMap()11hostMap.each{ key, value ->12}13def cerberus = new org.cerberus.servlet.zzpublic.AddToExecutionQueueV003()
getManualHostMap
Using AI Code Generation
1import java.util.HashMap;2import java.util.Map;3import org.cerberus.servlet.zzpublic.AddToExecutionQueueV003;4import org.cerberus.servlet.zzpublic.AddToExecutionQueueV003;5Map<String, String> manualHostMap = new HashMap<>();6manualHostMap = AddToExecutionQueueV003.getManualHostMap();7Map<String, String> newHostMap = new HashMap<>();8newHostMap.put("Cerberus_Manual", manualHostMap.get("Cerberus_Manual"));9AddToExecutionQueueV003.createExecutionQueue(newHostMap, "Cerberus_Manual", "Cerberus_Manual", ""
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!!