Best Cerberus-source code snippet using org.cerberus.crud.service.ITestCaseService.readByKeyWithDependency
Source:TestCaseExecutionService.java
...222 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}...
readByKeyWithDependency
Using AI Code Generation
1import org.cerberus.crud.entity.TestCase;2import org.cerberus.crud.service.ITestCaseService;3TestCase testCase = testCaseService.readByKeyWithDependency("TEST", "TESTCASE");4System.out.println(testCase);5System.out.println(testCase.getTestCaseStepList());6System.out.println(testCase.getTestCaseExecutionInQueue());7System.out.println(testCase.getTestCaseExecutionQueueDep());8System.out.println(testCase.getTestCaseLabelList());9System.out.println(testCase.getTestCaseCountryList());10System.out.println(testCase.getTestCaseCountryPropertiesList());11System.out.println(testCase.getTestCaseCountryPropertiesDepList());12System.out.println(testCase.getTestCaseCountryDepList());13System.out.println(testC
readByKeyWithDependency
Using AI Code Generation
1import org.cerberus.crud.entity.TestCase;2import org.cerberus.crud.service.ITestCaseService;3import org.springframework.beans.factory.annotation.Autowired;4import org.springframework.stereotype.Service;5import java.util.List;6import java.util.Map;7public class MyService {8 private ITestCaseService testCaseService;9 public void myMethod() {10 String test = "";11 String testCase = "";12 TestCase testCaseObject = testCaseService.readByKeyWithDependency(test, testCase, true);13 List<TestCase> testCaseList = testCaseObject.getTestCaseList();14 Map<String, TestCase> testCaseMap = testCaseObject.getTestCaseMap();15 String test = testCaseObject.getTest();16 String testCase = testCaseObject.getTestCase();17 String application = testCaseObject.getApplication();18 String project = testCaseObject.getProject();19 String ticket = testCaseObject.getTicket();20 String origin = testCaseObject.getOrigin();
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!!