How to use readByCriteria method of org.cerberus.crud.dao.ITestCaseExecutionDAO class

Best Cerberus-source code snippet using org.cerberus.crud.dao.ITestCaseExecutionDAO.readByCriteria

Source:TestCaseExecutionService.java Github

copy

Full Screen

...141 status = ParameterParserUtil.wildcardIfEmpty(status);142 return testCaseExecutionDao.findExecutionbyCriteria1(dateLimitFrom, test, testCase, application, country, environment, controlStatus, status);143 }144 @Override145 public List<TestCaseExecution> readByCriteria(List<String> system, List<String> countries, List<String> environments, List<String> robotDecli, List<TestCase> testcases, Date from, Date to) throws CerberusException {146 return this.convert(testCaseExecutionDao.readByCriteria(system, countries, environments, robotDecli, testcases, from, to));147 }148 @Override149 public long registerRunID(TestCaseExecution tCExecution) throws CerberusException {150 /**151 * Insert TestCaseExecution152 */153 long runID = 0;154 try {155 runID = this.insertTCExecution(tCExecution);156 } catch (CerberusException ex) {157 LOG.warn(ex.toString(), ex);158 throw new CerberusException(ex.getMessageError());159 }160 return runID;161 }162 @Override163 public TestCaseExecution findTCExecutionByKey(long id) throws CerberusException {164 return testCaseExecutionDao.findTCExecutionByKey(id);165 }166 @Override167 public TestCaseExecution findLastTCExecutionInGroup(String test, String testCase, String environment, String country,168 String build, String revision, String browser, String browserVersion,169 String ip, String port, String tag) {170 return this.testCaseExecutionDao.findLastTCExecutionInGroup(test, testCase, environment, country, build, revision, browser, browserVersion, ip, port, tag);171 }172 @Override173 public TestCaseExecution findLastTestCaseExecutionNotPE(String test, String testCase) throws CerberusException {174 return testCaseExecutionDao.findLastTestCaseExecutionNotPE(test, testCase);175 }176 @Override177 public List<String> findDistinctTag(boolean withUUIDTag) throws CerberusException {178 return testCaseExecutionDao.findDistinctTag(withUUIDTag);179 }180 @Override181 public void setTagToExecution(long id, String tag) throws CerberusException {182 testCaseExecutionDao.setTagToExecution(id, tag);183 }184 @Override185 public AnswerList<TestCaseExecution> readByTagByCriteria(String tag, int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch) throws CerberusException {186 return AnswerUtil.convertToAnswerList(() -> testCaseExecutionDao.readByTagByCriteria(tag, start, amount, sort, searchTerm, individualSearch));187 }188 @Override189 public AnswerList<TestCaseExecution> readByCriteria(int start, int amount, String sort, String searchTerm, Map<String, List<String>> individualSearch, List<String> individualLike, List<String> system) throws CerberusException {190 return testCaseExecutionDao.readByCriteria(start, amount, sort, searchTerm, individualSearch, individualLike, system);191 }192 @Override193 public AnswerList<TestCaseExecution> readByTag(String tag) throws CerberusException {194 return testCaseExecutionDao.readByTag(tag);195 }196 @Override197 public Integer readNbByTag(String tag) throws CerberusException {198 return testCaseExecutionDao.readNbByTag(tag);199 }200 @Override201 public AnswerList<TestCaseExecution> readDistinctEnvCoutnryBrowserByTag(String tag) {202 return testCaseExecutionDao.readDistinctEnvCoutnryBrowserByTag(tag);203 }204 @Override205 public List<TestCaseExecution> createAllTestCaseExecution(List<TestCase> testCaseList, List<String> envList, List<String> countryList) {206 List<TestCaseExecution> result = new ArrayList<>();207 for (TestCase tc : testCaseList) {208 for (String environment : envList) {209 for (String country : countryList) {210 TestCaseExecution execution = new TestCaseExecution();211 execution.setTest(tc.getTest());212 execution.setTestCase(tc.getTestcase());213 execution.setEnvironment(environment);214 execution.setCountry(country);215 result.add(execution);216 }217 }218 }219 return result;220 }221 @Override222 public AnswerItem<TestCaseExecution> readByKey(long executionId) {223 return testCaseExecutionDao.readByKey(executionId);224 }225 @Override226 public AnswerItem<TestCaseExecution> readByKeyWithDependency(long executionId) {227 // Get Main Execution.228 AnswerItem<TestCaseExecution> tce = this.readByKey(executionId);229 TestCaseExecution testCaseExecution = tce.getItem();230 // Get Execution Tag.231 if (!StringUtil.isNullOrEmpty(testCaseExecution.getTag())) {232 AnswerItem<Tag> ai = tagService.readByKey(testCaseExecution.getTag());233 testCaseExecution.setTagObj(ai.getItem());234 }235 // Get Test Case.236 AnswerItem<TestCase> ai = testCaseService.readByKeyWithDependency(testCaseExecution.getTest(), testCaseExecution.getTestCase());237 testCaseExecution.setTestCaseObj(ai.getItem());238 // Get Execution Data (Properties).239 try {240 List<TestCaseExecutionData> a = testCaseExecutionDataService.readByIdWithDependency(executionId);241 for (TestCaseExecutionData tced : a) {242 if (tced.getIndex() == 1) {243 testCaseExecution.getTestCaseExecutionDataMap().put(tced.getProperty(), tced);244 }245 }246 } catch (CerberusException e) {247 LOG.error("An erreur occured while getting testcase execution data", e);248 }249 // Get Execution Dependencies.250 if (testCaseExecution.getQueueID() > 0) {251 try {252 List<TestCaseExecutionQueueDep> a = testCaseExecutionQueueDepService.convert(testCaseExecutionQueueDepService.readByExeQueueId(testCaseExecution.getQueueID()));253 testCaseExecution.setTestCaseExecutionQueueDep(a);254 } catch (CerberusException e) {255 LOG.error("An erreur occured while getting execution dependency", e);256 }257 }258 // set video if it exists259 try {260 List<TestCaseExecutionFile> videosAnswer = testCaseExecutionFileService.getListByFileDesc(executionId, "Video");261 List<String> videos = new LinkedList<>();262 videosAnswer.forEach(tcef -> videos.add(tcef.getFileName()));263 testCaseExecution.setVideos(videos);264 } catch (CerberusException e) {265 LOG.error("An erreur occured while getting video file", e);266 }267 // We first add the 'Pres Testing' testcase execution steps.268 AnswerList<TestCaseStepExecution> preTestCaseSteps = testCaseStepExecutionService.readByVarious1WithDependency(executionId, Test.TEST_PRETESTING, null);269 testCaseExecution.setTestCaseStepExecutionList(preTestCaseSteps.getDataList());270 // Then we add the steps from the main testcase.271 AnswerList<TestCaseStepExecution> steps = testCaseStepExecutionService.readByVarious1WithDependency(executionId, testCaseExecution.getTest(), testCaseExecution.getTestCase());272 testCaseExecution.addStepExecutionList(steps.getDataList());273 // Then we add the Post steps .274 AnswerList<TestCaseStepExecution> postTestCaseSteps = testCaseStepExecutionService.readByVarious1WithDependency(executionId, Test.TEST_POSTTESTING, null);275 testCaseExecution.addStepExecutionList(postTestCaseSteps.getDataList());276 // Get Execution Files.277 AnswerList<TestCaseExecutionFile> files = testCaseExecutionFileService.readByVarious(executionId, "");278 testCaseExecution.setFileList(files.getDataList());279 // Get Execution Files.280 AnswerItem<TestCaseExecutionHttpStat> httpStat = testCaseExecutionHttpStatService.readByKey(executionId);281 testCaseExecution.setHttpStat(httpStat.getItem());282 // Set Final response.283 AnswerItem<TestCaseExecution> response = new AnswerItem<>(testCaseExecution, tce.getResultMessage());284 return response;285 }286 @Override287 public TestCaseExecution convert(AnswerItem<TestCaseExecution> answerItem) throws CerberusException {288 if (answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {289 //if the service returns an OK message then we can get the item290 return answerItem.getItem();291 }292 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));293 }294 @Override295 public List<TestCaseExecution> convert(AnswerList<TestCaseExecution> answerList) throws CerberusException {296 if (answerList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {297 //if the service returns an OK message then we can get the item298 return answerList.getDataList();299 }300 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));301 }302 @Override303 public void convert(Answer answer) throws CerberusException {304 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {305 //if the service returns an OK message then we can get the item306 return;307 }308 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));309 }310 @Override311 public AnswerList<String> readDistinctValuesByCriteria(List<String> system, String test, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {312 return testCaseExecutionDao.readDistinctValuesByCriteria(system, test, searchParameter, individualSearch, columnName);313 }314 @Override315 public List<TestCaseExecution> readLastExecutionAndExecutionInQueueByTag(String tag) throws ParseException, CerberusException {316 AnswerList<TestCaseExecution> testCaseExecution;317 AnswerList<TestCaseExecutionQueue> testCaseExecutionInQueue;318 /**319 * Get list of execution by tag320 */321 testCaseExecution = this.readByTag(tag);322 List<TestCaseExecution> testCaseExecutions = testCaseExecution.getDataList();323 /**324 * Get list of Execution in Queue by Tag325 */326 List<String> stateList = new ArrayList<>();327 // We select here the list of state where no execution exist yet (or will never exist).328 stateList.add(TestCaseExecutionQueue.State.QUWITHDEP.name());329 stateList.add(TestCaseExecutionQueue.State.QUEUED.name());330 stateList.add(TestCaseExecutionQueue.State.WAITING.name());331 stateList.add(TestCaseExecutionQueue.State.STARTING.name());332 stateList.add(TestCaseExecutionQueue.State.ERROR.name());333 testCaseExecutionInQueue = testCaseExecutionInQueueService.readByVarious1(tag, stateList, true);334 List<TestCaseExecutionQueue> testCaseExecutionsInQueue = testCaseExecutionInQueue.getDataList();335 /**336 * Feed hash map with execution from the two list (to get only one by337 * test,testcase,country,env,browser)338 */339 testCaseExecutions = hashExecution(testCaseExecutions, testCaseExecutionsInQueue);340 // load all test case dependency341 testCaseExecutionQueueDepService.loadDependenciesOnTestCaseExecution(testCaseExecutions);342 return testCaseExecutions;343 }344 private List<TestCaseExecution> hashExecution(List<TestCaseExecution> testCaseExecutions, List<TestCaseExecutionQueue> testCaseExecutionsInQueue) throws ParseException {345 LinkedHashMap<String, TestCaseExecution> testCaseExecutionsList = new LinkedHashMap<>();346 for (TestCaseExecution testCaseExecution : testCaseExecutions) {347 String key = testCaseExecution.getRobotDecli() + "_"348 + testCaseExecution.getCountry() + "_"349 + testCaseExecution.getEnvironment() + "_"350 + testCaseExecution.getTest() + "_"351 + testCaseExecution.getTestCase();352 if ((testCaseExecutionsList.containsKey(key))) {353 testCaseExecution.setNbExecutions(testCaseExecutionsList.get(key).getNbExecutions() + 1);354 if (TestCaseExecution.CONTROLSTATUS_PE.equalsIgnoreCase(testCaseExecution.getControlStatus())) {355 if (testCaseExecutionsList.get(key) != null) {356 testCaseExecution.setPreviousExeId(testCaseExecutionsList.get(key).getId());357 testCaseExecution.setPreviousExeStatus(testCaseExecutionsList.get(key).getControlStatus());358 }359 }360 }361 testCaseExecutionsList.put(key, testCaseExecution);362 }363 for (TestCaseExecutionQueue testCaseExecutionInQueue : testCaseExecutionsInQueue) {364 TestCaseExecution testCaseExecution = testCaseExecutionInQueueService.convertToTestCaseExecution(testCaseExecutionInQueue);365 String key = testCaseExecution.getRobotDecli() + "_"366 + testCaseExecution.getCountry() + "_"367 + testCaseExecution.getEnvironment() + "_"368 + testCaseExecution.getTest() + "_"369 + testCaseExecution.getTestCase();370 if ((testCaseExecutionsList.containsKey(key) && testCaseExecutionsList.get(key).getStart() < testCaseExecutionInQueue.getRequestDate().getTime())371 || !testCaseExecutionsList.containsKey(key)) {372 if (TestCaseExecution.CONTROLSTATUS_QU.equalsIgnoreCase(testCaseExecution.getControlStatus())) {373 if (testCaseExecutionsList.get(key) != null) {374 testCaseExecution.setPreviousExeId(testCaseExecutionsList.get(key).getId());375 testCaseExecution.setPreviousExeStatus(testCaseExecutionsList.get(key).getControlStatus());376 }377 }378 testCaseExecutionsList.put(key, testCaseExecution);379 }380 }381 List<TestCaseExecution> result = new ArrayList<>(testCaseExecutionsList.values());382 return result;383 }384 public JSONArray getLastByCriteria(String test, String testCase, String tag, String campaign, Integer numberOfExecution) throws CerberusException {385 Map<String, List<String>> map = new HashMap<>();386 AddElementToMap(map, "test", test);387 AddElementToMap(map, "testCase", testCase);388 if (tag != null) {389 AddElementToMap(map, "tag", tag);390 }391 AnswerList<TestCaseExecution> list = readByCriteria(0, numberOfExecution, " exe.`id` desc ", null, map, null, null);392 JSONArray ja = new JSONArray();393 for (TestCaseExecution tce : list.getDataList()) {394 TestCaseExecution tcex = this.readByKeyWithDependency(tce.getId()).getItem();395 ja.put(tcex.toJson(true));396 }397 return ja;398 }399 private void AddElementToMap(Map<String, List<String>> map, String key, String value) {400 List<String> element = new ArrayList<>();401 element.add(value);402 map.put(key, element);403 }404}...

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