How to use readExecutionByTagList method of org.cerberus.servlet.crud.testexecution.ReadTestCaseExecution class

Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.ReadTestCaseExecution.readExecutionByTagList

Source:ReadTestCaseExecution.java Github

copy

Full Screen

...290 List<String> search = new ArrayList<>(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));291 individualSearch.put(columnToSort[a], search);292 }293 }294 List<TestCaseExecution> testCaseExecutions = readExecutionByTagList(appContext, Tag, startPosition, length, sortInformation.toString(), searchParameter, individualSearch);295 JSONArray executionList = new JSONArray();296 JSONObject statusFilter = getStatusList(request);297 JSONObject countryFilter = getCountryList(request, appContext);298 LinkedHashMap<String, JSONObject> ttc = new LinkedHashMap<>();299 String globalStart = "";300 String globalEnd = "";301 String globalStatus = "Finished";302 /**303 * Find the list of labels304 */305 AnswerList<TestCaseLabel> testCaseLabelList = testCaseLabelService.readByTestTestCase(null, null, null);306 for (TestCaseExecution testCaseExecution : testCaseExecutions) {307 try {308 if (testCaseExecution.getStart() != 0) {309 if ((globalStart.isEmpty()) || (globalStart.compareTo(String.valueOf(testCaseExecution.getStart())) > 0)) {310 globalStart = String.valueOf(testCaseExecution.getStart());311 }312 }313 if (testCaseExecution.getEnd() != 0) {314 if ((globalEnd.isEmpty()) || (globalEnd.compareTo(String.valueOf(testCaseExecution.getEnd())) < 0)) {315 globalEnd = String.valueOf(testCaseExecution.getEnd());316 }317 }318 if (testCaseExecution.getControlStatus().equalsIgnoreCase("PE")) {319 globalStatus = "Pending...";320 }321 String controlStatus = testCaseExecution.getControlStatus();322 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseExecution.getCountry()).equals("on")) {323 JSONObject execution = testCaseExecutionToJSONObject(testCaseExecution);324 String execKey = testCaseExecution.getEnvironment() + " " + testCaseExecution.getCountry() + " " + testCaseExecution.getBrowser();325 String testCaseKey = testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase();326 JSONObject execTab = new JSONObject();327 executionList.put(testCaseExecutionToJSONObject(testCaseExecution));328 JSONObject ttcObject = new JSONObject();329 if (ttc.containsKey(testCaseKey)) {330 ttcObject = ttc.get(testCaseKey);331 execTab = ttcObject.getJSONObject("execTab");332 execTab.put(execKey, execution);333 ttcObject.put("execTab", execTab);334 } else {335 ttcObject.put("test", testCaseExecution.getTest());336 ttcObject.put("testCase", testCaseExecution.getTestCase());337 ttcObject.put("function", testCaseExecution.getTestCaseObj().getFunction());338 ttcObject.put("shortDesc", testCaseExecution.getTestCaseObj().getDescription());339 ttcObject.put("status", testCaseExecution.getStatus());340 ttcObject.put("application", testCaseExecution.getApplication());341 ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());342 ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());343 execTab.put(execKey, execution);344 ttcObject.put("execTab", execTab);345 /**346 * Iterate on the label retrieved and generate HashMap347 * based on the key Test_TestCase348 */349 LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap<>();350 for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList.getDataList()) {351 String key = label.getTest() + "_" + label.getTestcase();352 if (testCaseWithLabel.containsKey(key)) {353 JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());354 testCaseWithLabel.get(key).put(jo);355 } else {356 JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());357 testCaseWithLabel.put(key, new JSONArray().put(jo));358 }359 }360 ttcObject.put("labels", testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase()));361 }362 ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);363 }364 } catch (JSONException ex) {365 LOG.warn(ex);366 }367 }368 JSONObject jsonResponse = new JSONObject();369 jsonResponse.put("globalEnd", globalEnd.toString());370 jsonResponse.put("globalStart", globalStart.toString());371 jsonResponse.put("globalStatus", globalStatus);372 jsonResponse.put("testList", ttc.values());373 jsonResponse.put("iTotalRecords", ttc.size());374 jsonResponse.put("iTotalDisplayRecords", ttc.size());375 answer.setItem(jsonResponse);376 answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));377 return answer;378 }379 private AnswerItem<JSONObject> findTestCaseExecutionList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException, CerberusException {380 AnswerItem<JSONObject> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));381 List<TestCaseExecution> testCaseExecutionList;382 JSONObject object = new JSONObject();383 testCaseExecutionService = appContext.getBean(TestCaseExecutionService.class);384 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));385 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));386 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");387 int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));388 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,description,active,automated,tdatecrea");389 String columnToSort[] = sColumns.split(",");390 String columnName = columnToSort[columnToSortParameter];391 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");392 List<String> system = ParameterParserUtil.parseListParamAndDecodeAndDeleteEmptyValue(request.getParameterValues("system"), Arrays.asList("DEFAULT"), "UTF-8");393 Map<String, List<String>> individualSearch = new HashMap<>();394 List<String> individualLike = new ArrayList<>(Arrays.asList(ParameterParserUtil.parseStringParam(request.getParameter("sLike"), "").split(",")));395 for (int a = 0; a < columnToSort.length; a++) {396 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {397 List<String> search = new ArrayList<>(Arrays.asList(request.getParameter("sSearch_" + a).split(",")));398 if (individualLike.contains(columnToSort[a])) {399 individualSearch.put(columnToSort[a] + ":like", search);400 } else {401 individualSearch.put(columnToSort[a], search);402 }403 }404 }405 AnswerList<TestCaseExecution> resp = testCaseExecutionService.readByCriteria(startPosition, length, columnName.concat(" ").concat(sort), searchParameter, individualSearch, individualLike, system);406 JSONArray jsonArray = new JSONArray();407 if (resp.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {//the service was able to perform the query, then we should get all values408 for (TestCaseExecution testCaseExecution : (List<TestCaseExecution>) resp.getDataList()) {409 jsonArray.put(testCaseExecution.toJson(true).put("hasPermissions", userHasPermissions));410 }411 }412 object.put("contentTable", jsonArray);413 object.put("hasPermissions", userHasPermissions);414 object.put("iTotalRecords", resp.getTotalRows());415 object.put("iTotalDisplayRecords", resp.getTotalRows());416 answer.setItem(object);417 answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK_GENERIC));418 return answer;419 }420 private JSONObject getStatusList(HttpServletRequest request) {421 JSONObject statusList = new JSONObject();422 try {423 statusList.put("OK", ParameterParserUtil.parseStringParam(request.getParameter("OK"), "off"));424 statusList.put("KO", ParameterParserUtil.parseStringParam(request.getParameter("KO"), "off"));425 statusList.put("NA", ParameterParserUtil.parseStringParam(request.getParameter("NA"), "off"));426 statusList.put("NE", ParameterParserUtil.parseStringParam(request.getParameter("NE"), "off"));427 statusList.put("PE", ParameterParserUtil.parseStringParam(request.getParameter("PE"), "off"));428 statusList.put("FA", ParameterParserUtil.parseStringParam(request.getParameter("FA"), "off"));429 statusList.put("CA", ParameterParserUtil.parseStringParam(request.getParameter("CA"), "off"));430 } catch (JSONException ex) {431 LOG.warn(ex);432 }433 return statusList;434 }435 private JSONObject getCountryList(HttpServletRequest request, ApplicationContext appContext) {436 JSONObject countryList = new JSONObject();437 try {438 invariantService = appContext.getBean(InvariantService.class);439 for (Invariant country : invariantService.readByIdName("COUNTRY")) {440 countryList.put(country.getValue(), ParameterParserUtil.parseStringParam(request.getParameter(country.getValue()), "off"));441 }442 } catch (JSONException ex) {443 LOG.warn("JSON exception when getting Country List.", ex);444 } catch (CerberusException ex) {445 LOG.error("JSON exception when getting Country List.", ex);446 }447 return countryList;448 }449 private List<TestCaseExecution> hashExecution(List<TestCaseExecution> testCaseExecutions, List<TestCaseExecutionQueue> testCaseExecutionsInQueue) throws ParseException {450 LinkedHashMap<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap<>();451 SimpleDateFormat formater = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");452 for (TestCaseExecution testCaseExecution : testCaseExecutions) {453 String key = testCaseExecution.getBrowser() + "_"454 + testCaseExecution.getCountry() + "_"455 + testCaseExecution.getEnvironment() + "_"456 + testCaseExecution.getTest() + "_"457 + testCaseExecution.getTestCase();458 testCaseExecutionsList.put(key, testCaseExecution);459 }460 for (TestCaseExecutionQueue testCaseExecutionInQueue : testCaseExecutionsInQueue) {461 TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(testCaseExecutionInQueue);462 String key = testCaseExecution.getBrowser() + "_"463 + testCaseExecution.getCountry() + "_"464 + testCaseExecution.getEnvironment() + "_"465 + testCaseExecution.getTest() + "_"466 + testCaseExecution.getTestCase();467 if ((testCaseExecutionsList.containsKey(key)468 && testCaseExecutionsList.get(key).getStart() < testCaseExecutionInQueue.getRequestDate().getTime())469 || !testCaseExecutionsList.containsKey(key)) {470 testCaseExecutionsList.put(key, testCaseExecution);471 }472 }473 List<TestCaseExecution> result = new ArrayList<>(testCaseExecutionsList.values());474 return result;475 }476 private JSONObject testCaseExecutionToJSONObject(477 TestCaseExecution testCaseExecution) throws JSONException {478 JSONObject result = new JSONObject();479 result.put("ID", String.valueOf(testCaseExecution.getId()));480 result.put("Test", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTest()));481 result.put("TestCase", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCase()));482 result.put("Environment", JavaScriptUtils.javaScriptEscape(testCaseExecution.getEnvironment()));483 result.put("Start", testCaseExecution.getStart());484 result.put("End", testCaseExecution.getEnd());485 result.put("Country", JavaScriptUtils.javaScriptEscape(testCaseExecution.getCountry()));486 result.put("Browser", JavaScriptUtils.javaScriptEscape(testCaseExecution.getBrowser()));487 result.put("ControlStatus", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlStatus()));488 result.put("ControlMessage", JavaScriptUtils.javaScriptEscape(testCaseExecution.getControlMessage()));489 result.put("Status", JavaScriptUtils.javaScriptEscape(testCaseExecution.getStatus()));490 JSONArray bugId = new JSONArray();491 if (testCaseExecution.getApplicationObj() != null && testCaseExecution.getApplicationObj().getBugTrackerUrl() != null492 && !"".equals(testCaseExecution.getApplicationObj().getBugTrackerUrl()) && testCaseExecution.getTestCaseObj().getBugID() != null) {493// bugId = testCaseExecution.getApplicationObj().getBugTrackerUrl().replace("%BUGID%", testCaseExecution.getTestCaseObj().getBugID());494// bugId = new StringBuffer("<a href='")495// .append(bugId)496// .append("' target='reportBugID'>")497// .append(testCaseExecution.getTestCaseObj().getBugID())498// .append("</a>")499// .toString();500 } else {501 bugId = testCaseExecution.getTestCaseObj().getBugID();502 }503 result.put("BugID", bugId);504 result.put("Comment", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getComment()));505 result.put("Priority", JavaScriptUtils.javaScriptEscape(String.valueOf(testCaseExecution.getTestCaseObj().getPriority())));506 result.put("Function", JavaScriptUtils.javaScriptEscape(testCaseExecution.getTestCaseObj().getFunction()));507 result.put("Application", JavaScriptUtils.javaScriptEscape(testCaseExecution.getApplication()));508 result.put("ShortDescription", testCaseExecution.getTestCaseObj().getDescription());509 return result;510 }511 private List<TestCaseExecution> readExecutionByTagList(ApplicationContext appContext, String Tag, int startPosition, int length, String sortInformation, String searchParameter, Map<String, List<String>> individualSearch) throws ParseException, CerberusException {512 AnswerList<TestCaseExecution> testCaseExecution;513 AnswerList<TestCaseExecutionQueue> testCaseExecutionInQueue;514 ITestCaseExecutionService testCaseExecService = appContext.getBean(ITestCaseExecutionService.class);515 testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);516 /**517 * Get list of execution by tag, env, country, browser518 */519 testCaseExecution = testCaseExecService.readByTagByCriteria(Tag, startPosition, length, sortInformation, searchParameter, individualSearch);520 List<TestCaseExecution> testCaseExecutions = testCaseExecution.getDataList();521 /**522 * Get list of Execution in Queue by Tag523 */524 testCaseExecutionInQueue = testCaseExecutionInQueueService.readByTagByCriteria(Tag, startPosition, length, sortInformation, searchParameter, individualSearch);525 List<TestCaseExecutionQueue> testCaseExecutionsInQueue = testCaseExecutionInQueue.getDataList();...

Full Screen

Full Screen

readExecutionByTagList

Using AI Code Generation

copy

Full Screen

1ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();2String[] tagList = {"tag1","tag2"};3List<TestCaseExecution> testCaseExecutions = readTestCaseExecution.readExecutionByTagList(tagList);4ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();5String[] tagList = {"tag1","tag2"};6List<TestCaseExecution> testCaseExecutions = readTestCaseExecution.readExecutionByTagList(tagList);7ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();8String[] tagList = {"tag1","tag2"};9List<TestCaseExecution> testCaseExecutions = readTestCaseExecution.readExecutionByTagList(tagList);10ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();11String[] tagList = {"tag1","tag2"};12List<TestCaseExecution> testCaseExecutions = readTestCaseExecution.readExecutionByTagList(tagList);13ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();14String[] tagList = {"tag1","tag2"};15List<TestCaseExecution> testCaseExecutions = readTestCaseExecution.readExecutionByTagList(tagList);16ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();17String[] tagList = {"tag1","tag2"};18List<TestCaseExecution> testCaseExecutions = readTestCaseExecution.readExecutionByTagList(tagList);19ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();20String[] tagList = {"tag1","tag2"};21List<TestCaseExecution> testCaseExecutions = readTestCaseExecution.readExecutionByTagList(tagList);

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.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful