Best Cerberus-source code snippet using org.cerberus.servlet.crud.testexecution.ReadTestCaseExecution.findTestCaseExecutionList
Source:ReadTestCaseExecution.java
...137 TestCaseExecution tce = (TestCaseExecution) answer.getItem();138 jsonResponse.put("testCaseExecution", tce.toJson(true));139 } else if (executionId != 0 && executionWithDependency) {140 } else {141 answer = findTestCaseExecutionList(appContext, true, request);142 jsonResponse = (JSONObject) answer.getItem();143 }144 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());145 jsonResponse.put("message", answer.getResultMessage().getDescription());146 response.getWriter().print(jsonResponse.toString());147 } catch (CerberusException ce) {148 AnswerItem answer = AnswerUtil.convertToAnswerItem(() -> {149 throw ce;150 });151 jsonResponse.put("messageType", answer.getResultMessage().getMessage().getCodeString());152 jsonResponse.put("message", answer.getResultMessage().getDescription());153 response.getWriter().print(jsonResponse.toString());154 }155 } catch (JSONException ex) {156 LOG.warn(ex);157 //returns a default error message with the json format that is able to be parsed by the client-side158 response.getWriter().print(AnswerUtil.createGenericErrorAnswer());159 }160 }161 // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">162 /**163 * Handles the HTTP <code>GET</code> method.164 *165 * @param request servlet request166 * @param response servlet response167 * @throws ServletException if a servlet-specific error occurs168 * @throws IOException if an I/O error occurs169 */170 @Override171 protected void doGet(HttpServletRequest request, HttpServletResponse response)172 throws ServletException, IOException {173 try {174 processRequest(request, response);175 } catch (CerberusException ex) {176 LOG.warn(ex);177 } catch (ParseException ex) {178 LOG.warn(ex);179 }180 }181 /**182 * Handles the HTTP <code>POST</code> method.183 *184 * @param request servlet request185 * @param response servlet response186 * @throws ServletException if a servlet-specific error occurs187 * @throws IOException if an I/O error occurs188 */189 @Override190 protected void doPost(HttpServletRequest request, HttpServletResponse response)191 throws ServletException, IOException {192 try {193 processRequest(request, response);194 } catch (CerberusException ex) {195 LOG.warn(ex);196 } catch (ParseException ex) {197 LOG.warn(ex);198 }199 }200 /**201 * Returns a short description of the servlet.202 *203 * @return a String containing servlet description204 */205 @Override206 public String getServletInfo() {207 return "Short description";208 }// </editor-fold>209 private AnswerItem<JSONObject> findExecutionColumns(ApplicationContext appContext, HttpServletRequest request, String Tag) throws CerberusException, ParseException, JSONException {210 AnswerItem<JSONObject> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));211 JSONObject jsonResponse = new JSONObject();212 AnswerList<TestCaseExecution> testCaseExecutionList = new AnswerList<>();213 AnswerList<TestCaseExecutionQueue> testCaseExecutionListInQueue = new AnswerList<>();214 testCaseExecutionService = appContext.getBean(ITestCaseExecutionService.class);215 testCaseExecutionInQueueService = appContext.getBean(ITestCaseExecutionQueueService.class);216 /**217 * Get list of execution by tag, env, country, browser218 */219 testCaseExecutionList = testCaseExecutionService.readDistinctEnvCoutnryBrowserByTag(Tag);220 List<TestCaseExecution> testCaseExecutions = testCaseExecutionList.getDataList();221 /**222 * Get list of Execution in Queue by Tag223 */224 testCaseExecutionListInQueue = testCaseExecutionInQueueService.readDistinctEnvCountryBrowserByTag(Tag);225 List<TestCaseExecutionQueue> testCaseExecutionsInQueue = testCaseExecutionListInQueue.getDataList();226 /**227 * Feed hash map with execution from the two list (to get only one by228 * test,testcase,country,env,browser)229 */230 LinkedHashMap<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap<>();231 for (TestCaseExecution testCaseWithExecution : testCaseExecutions) {232 String key = testCaseWithExecution.getBrowser() + "_"233 + testCaseWithExecution.getCountry() + "_"234 + testCaseWithExecution.getEnvironment() + " "235 + testCaseWithExecution.getControlStatus();236 testCaseExecutionsList.put(key, testCaseWithExecution);237 }238 for (TestCaseExecutionQueue testCaseWithExecutionInQueue : testCaseExecutionsInQueue) {239 TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(testCaseWithExecutionInQueue);240 String key = testCaseExecution.getBrowser() + "_"241 + testCaseExecution.getCountry() + "_"242 + testCaseExecution.getEnvironment() + "_"243 + testCaseExecution.getControlStatus();244 testCaseExecutionsList.put(key, testCaseExecution);245 }246 testCaseExecutions = new ArrayList<>(testCaseExecutionsList.values());247 JSONObject statusFilter = getStatusList(request);248 JSONObject countryFilter = getCountryList(request, appContext);249 LinkedHashMap<String, JSONObject> columnMap = new LinkedHashMap<>();250 for (TestCaseExecution testCaseWithExecution : testCaseExecutions) {251 String controlStatus = testCaseWithExecution.getControlStatus();252 if (statusFilter.get(controlStatus).equals("on") && countryFilter.get(testCaseWithExecution.getCountry()).equals("on")) {253 JSONObject column = new JSONObject();254 column.put("country", testCaseWithExecution.getCountry());255 column.put("environment", testCaseWithExecution.getEnvironment());256 column.put("browser", testCaseWithExecution.getBrowser());257 columnMap.put(testCaseWithExecution.getBrowser() + "_" + testCaseWithExecution.getCountry() + "_" + testCaseWithExecution.getEnvironment(), column);258 }259 }260 jsonResponse.put("Columns", columnMap.values());261 answer.setItem(jsonResponse);262 answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));263 return answer;264 }265 private AnswerItem findExecutionListByTag(ApplicationContext appContext, HttpServletRequest request, String Tag) throws CerberusException, ParseException, JSONException {266 AnswerItem<JSONObject> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));267 testCaseLabelService = appContext.getBean(ITestCaseLabelService.class);268 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));269 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));270 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");271 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,testCase,application,priority,status,description,bugs,function");272 String columnToSort[] = sColumns.split(",");273 //Get Sorting information274 int numberOfColumnToSort = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortingCols"), "1"));275 int columnToSortParameter = 0;276 String sort = "asc";277 StringBuilder sortInformation = new StringBuilder();278 for (int c = 0; c < numberOfColumnToSort; c++) {279 columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_" + c), "0"));280 sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_" + c), "asc");281 String columnName = columnToSort[columnToSortParameter];282 sortInformation.append(columnName).append(" ").append(sort);283 if (c != numberOfColumnToSort - 1) {284 sortInformation.append(" , ");285 }286 }287 Map<String, List<String>> individualSearch = new HashMap<String, List<String>>();288 for (int a = 0; a < columnToSort.length; a++) {289 if (null != request.getParameter("sSearch_" + a) && !request.getParameter("sSearch_" + a).isEmpty()) {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("shortDesc", testCaseExecution.getTestCaseObj().getDescription());338 ttcObject.put("status", testCaseExecution.getStatus());339 ttcObject.put("application", testCaseExecution.getApplication());340 ttcObject.put("priority", testCaseExecution.getTestCaseObj().getPriority());341 ttcObject.put("comment", testCaseExecution.getTestCaseObj().getComment());342 execTab.put(execKey, execution);343 ttcObject.put("execTab", execTab);344 /**345 * Iterate on the label retrieved and generate HashMap346 * based on the key Test_TestCase347 */348 LinkedHashMap<String, JSONArray> testCaseWithLabel = new LinkedHashMap<>();349 for (TestCaseLabel label : (List<TestCaseLabel>) testCaseLabelList.getDataList()) {350 String key = label.getTest() + "_" + label.getTestcase();351 if (testCaseWithLabel.containsKey(key)) {352 JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());353 testCaseWithLabel.get(key).put(jo);354 } else {355 JSONObject jo = new JSONObject().put("name", label.getLabel().getLabel()).put("color", label.getLabel().getColor()).put("description", label.getLabel().getDescription());356 testCaseWithLabel.put(key, new JSONArray().put(jo));357 }358 }359 ttcObject.put("labels", testCaseWithLabel.get(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase()));360 }361 ttc.put(testCaseExecution.getTest() + "_" + testCaseExecution.getTestCase(), ttcObject);362 }363 } catch (JSONException ex) {364 LOG.warn(ex);365 }366 }367 JSONObject jsonResponse = new JSONObject();368 jsonResponse.put("globalEnd", globalEnd.toString());369 jsonResponse.put("globalStart", globalStart.toString());370 jsonResponse.put("globalStatus", globalStatus);371 jsonResponse.put("testList", ttc.values());372 jsonResponse.put("iTotalRecords", ttc.size());373 jsonResponse.put("iTotalDisplayRecords", ttc.size());374 answer.setItem(jsonResponse);375 answer.setResultMessage(new MessageEvent(MessageEventEnum.DATA_OPERATION_OK));376 return answer;377 }378 private AnswerItem<JSONObject> findTestCaseExecutionList(ApplicationContext appContext, boolean userHasPermissions, HttpServletRequest request) throws JSONException, CerberusException {379 AnswerItem<JSONObject> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));380 List<TestCaseExecution> testCaseExecutionList;381 JSONObject object = new JSONObject();382 testCaseExecutionService = appContext.getBean(TestCaseExecutionService.class);383 int startPosition = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayStart"), "0"));384 int length = Integer.valueOf(ParameterParserUtil.parseStringParam(request.getParameter("iDisplayLength"), "0"));385 String searchParameter = ParameterParserUtil.parseStringParam(request.getParameter("sSearch"), "");386 int columnToSortParameter = Integer.parseInt(ParameterParserUtil.parseStringParam(request.getParameter("iSortCol_0"), "0"));387 String sColumns = ParameterParserUtil.parseStringParam(request.getParameter("sColumns"), "test,description,active,automated,tdatecrea");388 String columnToSort[] = sColumns.split(",");389 String columnName = columnToSort[columnToSortParameter];390 String sort = ParameterParserUtil.parseStringParam(request.getParameter("sSortDir_0"), "asc");391 List<String> system = ParameterParserUtil.parseListParamAndDecodeAndDeleteEmptyValue(request.getParameterValues("system"), Arrays.asList("DEFAULT"), "UTF-8");392 Map<String, List<String>> individualSearch = new HashMap<>();...
findTestCaseExecutionList
Using AI Code Generation
1import org.cerberus.servlet.crud.testexecution.ReadTestCaseExecution;2import org.cerberus.crud.entity.TestCaseExecution;3import org.cerberus.crud.factory.IFactoryTestCaseExecution;4import org.cerberus.crud.factory.impl.FactoryTestCaseExecution;5import org.cerberus.crud.service.ITestCaseExecutionService;6import org.cerberus.crud.service.impl.TestCaseExecutionService;7import java.util.List;8import java.util.ArrayList;9ReadTestCaseExecution readTestCaseExecution = new ReadTestCaseExecution();10String test = "TEST1";11String testCase = "TC1";12String country = "FRA";13String environment = "QA";14String build = "1";15String revision = "1";16String status = "PE";17String controlStatus = "OK";18String application = "APP1";
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!!