Best Cerberus-source code snippet using org.cerberus.crud.service.impl.TestCaseService.findTestCaseByKeyWithDependencies
Source:TestCaseService.java
...167 }168 return newTcase;169 }170 @Override171 public AnswerItem<TestCase> findTestCaseByKeyWithDependencies(String test, String testCase, boolean withSteps) throws CerberusException {172 HashMap<String, TestCaseCountry> testCaseCountries;173 HashMap<String, Invariant> countryInvariants;174 AnswerItem<TestCase> answerTestCase = this.readByKey(test, testCase);175 if (answerTestCase.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && answerTestCase.getItem() != null) {176 testCaseCountries = testCaseCountryService.readByTestTestCaseToHashCountryAsKey(test, testCase);177 countryInvariants = (HashMap<String, Invariant>) invariantService.readByIdNameToHash("COUNTRY");178 answerTestCase.getItem().setInvariantCountries(invariantService.convertCountryPropertiesToCountryInvariants(testCaseCountries, countryInvariants));179 answerTestCase.getItem().setDependencies(testCaseDepService.readByTestAndTestcase(answerTestCase.getItem().getTest(), answerTestCase.getItem().getTestcase()));180 answerTestCase.getItem().setLabels(labelService.findLabelsFromTestCase(test, testCase, null).get(test + "##" + testCase));181 List<TestCase> testcases = new ArrayList<>();182 testcases.add(factoryTCase.create(test, testCase));183 answerTestCase.getItem().setTestCaseCountryProperties(testCaseCountryPropertiesService.findDistinctPropertiesOfTestCaseFromTestcaseList(testcases, countryInvariants));184 if (withSteps) {185 answerTestCase.getItem().setSteps(testCaseStepService.readByTestTestCaseStepsWithDependencies(test, testCase).getDataList());186 answerTestCase.getItem().setTestCaseInheritedProperties(testCaseCountryPropertiesService.findDistinctInheritedPropertiesOfTestCase(answerTestCase.getItem(), countryInvariants));187 }188 }189 return answerTestCase;190 }191 @Override192 public List<TestCase> findTestCaseByTest(String test) {193 return testCaseDao.findTestCaseByTest(test);194 }195 @Override196 public AnswerList<TestCase> findTestCasesByTestByCriteriaWithDependencies(List<String> system, String test, int startPosition, int length, String sortInformation, String searchParameter, Map<String, List<String>> individualSearch, boolean isCalledFromListPage) throws CerberusException {197 AnswerList<TestCase> testCases = this.readByTestByCriteria(system, test, startPosition, length, sortInformation, searchParameter, individualSearch);198 if (testCases.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && !testCases.getDataList().isEmpty() && isCalledFromListPage) {//the service was able to perform the query, then we should get all values199 HashMap<String, Invariant> countryInvariants = (HashMap<String, Invariant>) invariantService.readByIdNameToHash("COUNTRY");200 List<TestCaseCountry> testCaseCountries = testCaseCountryService.readByTestTestCase(system, test, null, testCases.getDataList()).getDataList();201 HashMap<String, HashMap<String, TestCaseCountry>> testCaseCountryHash = testCaseCountryService.convertListToHashMapTestTestCaseAsKey(testCaseCountries);202 List<TestCaseDep> testCaseDependencies = testCaseDepService.readByTestAndTestcase(testCases.getDataList());203 HashMap<String, List<TestCaseDep>> testCaseDependenciesHash = testCaseDepService.convertTestCaseDependencyListToHash(testCaseDependencies);204 HashMap<String, List<Label>> labelsHash = labelService.findLabelsFromTestCase(test, null, testCases.getDataList());205 for (TestCase testCase : testCases.getDataList()) {206 if (testCaseCountryHash.containsKey(testCase.getKey())) {207 testCase.setInvariantCountries(invariantService.convertCountryPropertiesToCountryInvariants(testCaseCountryHash.get(testCase.getKey()), countryInvariants));208 }209 if (labelsHash.containsKey(testCase.getTest() + "##" + testCase.getTestcase())) {210 testCase.setLabels(labelsHash.get(testCase.getTest() + "##" + testCase.getTestcase()));211 }212 if (testCaseDependenciesHash.containsKey(testCase.getTestcase())) {213 testCase.setDependencies(testCaseDependenciesHash.get(testCase.getTestcase()));214 }215 }216 }217 return testCases;218 }219 @Override220 public List<TestCase> findTestCaseByTestSystem(String test, String system) {221 return testCaseDao.findTestCaseByTestSystem(test, system);222 }223 @Override224 public List<TestCase> findTestCaseByApplication(final String application) {225 return testCaseDao.findTestCaseByApplication(application);226 }227 @Override228 public boolean updateTestCaseInformation(TestCase testCase) {229 return testCaseDao.updateTestCaseInformation(testCase);230 }231 @Override232 public List<TestCase> getTestCaseForPrePostTesting(String test, String application, String country, String system, String build, String revision) {233 List<TestCase> tmpTests = testCaseDao.findTestCaseByCriteria(test, application, country, "Y");234 List<TestCase> resultTests = new ArrayList<>();235 for (TestCase tmpTest : tmpTests) {236 // We check here if build/revision is compatible.237 if (executionCheckService.checkRangeBuildRevision(tmpTest, build, revision, system)) {238 resultTests.add(tmpTest);239 }240 }241 return resultTests;242 }243 @Override244 public List<TestCase> findTestCaseByAllCriteria(TestCase tCase, String text, String system) {245 return this.testCaseDao.findTestCaseByCriteria(tCase, text, system);246 }247 @Override248 public AnswerList<TestCase> readByVarious(String[] test, String[] app, String[] creator, String[] implementer, String[] system,249 String[] campaign, List<Integer> labelid, String[] priority, String[] type, String[] status, int length) {250 return testCaseDao.readByVarious(test, app, creator, implementer, system, campaign, labelid, priority, type, status, length);251 }252 /**253 * @param column254 * @return255 * @since 0.9.1256 */257 @Override258 public List<String> findUniqueDataOfColumn(String column) {259 return this.testCaseDao.findUniqueDataOfColumn(column);260 }261 @Override262 public List<String> findTestWithTestCaseActiveAutomatedBySystem(String system) {263 TestCase tCase = factoryTCase.create(null, null, null, null, null, null, null, null,264 null, true, true, false, -1, null, null, null, null, true, null, null,265 null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);266 List<String> result = new ArrayList<>();267 List<TestCase> testCases = findTestCaseByAllCriteria(tCase, null, system);268 for (TestCase testCase : testCases) {269 if (!testCase.getType().equals("PRIVATE")) {270 result.add(testCase.getTest());271 }272 }273 Set<String> uniqueResult = new HashSet<>(result);274 result = new ArrayList<>();275 result.addAll(uniqueResult);276 Collections.sort(result);277 return result;278 }279 @Override280 public List<TestCase> findTestCaseActiveAutomatedBySystem(String test, String system) {281 TestCase tCase = factoryTCase.create(test, null, null, null, null, null, null, null,282 null, true, true, false, -1, null, null, null, null, true, null, null,283 null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null, null);284 List<TestCase> result = new ArrayList<>();285 List<TestCase> testCases = findTestCaseByAllCriteria(tCase, null, system);286 for (TestCase testCase : testCases) {287 if (!testCase.getType().equals("PRIVATE")) {288 result.add(testCase);289 }290 }291 return result;292 }293 @Override294 public String getNextAvailableTestcaseId(String test) {295 String result = testCaseDao.getMaxTestcaseIdByTestFolder(test);296 if (result == null) {297 return "0001A";298 }299 int resultInt = 0;300 try {301 resultInt = Integer.valueOf(result);302 } catch (NumberFormatException e) {303 LOG.debug("Could not convert '" + result + "' to Integer.");304 }305 resultInt++;306 return String.format("%04dA", resultInt);307 }308 @Override309 public AnswerList<TestCase> findTestCaseByCampaign(String campaign) {310 final AnswerItem<Map<String, List<String>>> parsedCampaignParameters = campaignParameterService.parseParametersByCampaign(campaign);311 List<String> countries = parsedCampaignParameters.getItem().get(CampaignParameter.COUNTRY_PARAMETER);312 AnswerList<TestCase> testCases = null;313 if (countries != null && !countries.isEmpty()) {314 testCases = this.findTestCaseByCampaignNameAndCountries(campaign, countries.toArray(new String[countries.size()]));315 } else {316 testCases = this.findTestCaseByCampaignNameAndCountries(campaign, null);317 }318 return testCases;319 }320 @Override321 public AnswerList<TestCase> findTestCaseByCampaignNameAndCountries(String campaign, String[] countries) {322 AnswerList<TestCase> result;323 String[] status = null;324 String[] system = null;325 String[] application = null;326 String[] priority = null;327 String[] type = null;328 AnswerItem<Map<String, List<String>>> parameters = campaignParameterService.parseParametersByCampaign(campaign);329 for (Map.Entry<String, List<String>> entry : parameters.getItem().entrySet()) {330 String cle = entry.getKey();331 List<String> valeur = entry.getValue();332 switch (cle) {333 case CampaignParameter.PRIORITY_PARAMETER:334 priority = valeur.toArray(new String[valeur.size()]);335 break;336 case CampaignParameter.STATUS_PARAMETER:337 status = valeur.toArray(new String[valeur.size()]);338 break;339 case CampaignParameter.SYSTEM_PARAMETER:340 system = valeur.toArray(new String[valeur.size()]);341 break;342 case CampaignParameter.APPLICATION_PARAMETER:343 application = valeur.toArray(new String[valeur.size()]);344 break;345 case CampaignParameter.TYPE_PARAMETER:346 type = valeur.toArray(new String[valeur.size()]);347 break;348 }349 }350 AnswerList<CampaignLabel> label = campaignLabelService.readByVarious(campaign);351 List<Integer> labelIdList = new ArrayList<>();352 List<CampaignLabel> labelList = label.getDataList();353 for (CampaignLabel campaignLabel : labelList) {354 labelIdList.add(campaignLabel.getLabelId());355 }356 labelIdList = labelService.enrichWithChild(labelIdList);357 Integer maxReturn = parameterService.getParameterIntegerByKey("cerberus_campaign_maxtestcase", "", 1000);358 result = testCaseDao.findTestCaseByCampaignNameAndCountries(campaign, countries, labelIdList, status, system, application, priority, type, maxReturn);359 return result;360 }361 @Override362 public List<TestCase> findUseTestCaseList(String test, String testCase) throws CerberusException {363 List<TestCase> result = new ArrayList<>();364 List<TestCaseStep> tcsList = testCaseStepService.getListOfSteps(test, testCase);365 for (TestCaseStep tcs : tcsList) {366 if (tcs.isUsingLibraryStep()) {367 /**368 * We prepend the TestCase in order to leave at the end of the369 * list the testcase with the higher prio (which correspond to370 * the 1st Use Step found) #1907. That way, if inside the same371 * testcase, you import 2 use Step that define a property that372 * has the same name, the 1st step imported will define the373 * property value.374 */375 result.add(0, this.findTestCaseByKey(tcs.getLibraryStepTest(), tcs.getLibraryStepTestcase()));376 }377 }378 return result;379 }380 @Override381 public List<TestCase> findByCriteria(String[] test, String[] app, String[] active, String[] priority, String[] status, String[] type, String[] targetMajor, String[] targetMinor, String[] creator, String[] implementer, String[] campaign, String[] battery) {382 return testCaseDao.findTestCaseByCriteria(test, app, active, priority, status, type, targetMajor, targetMinor, creator, implementer, campaign);383 }384 @Override385 public String findSystemOfTestCase(String test, String testcase) throws CerberusException {386 return testCaseDao.findSystemOfTestCase(test, testcase);387 }388 @Override389 public AnswerList<TestListDTO> findTestCasesThatUseTestDataLib(int testDataLibId, String name, String country) {390 return testCaseCountryPropertiesService.findTestCaseCountryPropertiesByValue1(testDataLibId, name, country, TestCaseCountryProperties.TYPE_GETFROMDATALIB);391 }392 public boolean containsTestCase(final List<TestCaseListDTO> list, final String number) {393 return list.stream().anyMatch(testCaseListDTO -> testCaseListDTO.getTestCaseNumber().equals(number));394 }395 @Override396 public AnswerList<TestListDTO> findTestCasesThatUseService(String service) {397 AnswerList<TestListDTO> testCaseByServiceByDataLib = testCaseDao.findTestCaseByServiceByDataLib(service);398 AnswerList<TestListDTO> testCaseByService = testCaseDao.findTestCaseByService(service);399 List<TestListDTO> listOfTestCaseByDataLib = testCaseByServiceByDataLib.getDataList();400 List<TestListDTO> listOfTestCaseByService = testCaseByService.getDataList();401 List<TestListDTO> newTestCase = new ArrayList<>();402 if (!listOfTestCaseByDataLib.isEmpty()) {403 for (TestListDTO datalibList : listOfTestCaseByDataLib) {404 for (TestListDTO serviceList : listOfTestCaseByService) {405 if (datalibList.getTest().equals(serviceList.getTest())) {406 List<TestCaseListDTO> testCaseDataLibList = datalibList.getTestCaseList();407 for (TestCaseListDTO testCaseService : serviceList.getTestCaseList()) {408 if (!containsTestCase(testCaseDataLibList, testCaseService.getTestCaseNumber())) {409 testCaseDataLibList.add(testCaseService);410 }411 }412 } else {413 newTestCase.add(serviceList);414 }415 }416 }417 listOfTestCaseByDataLib.addAll(newTestCase);418 testCaseByServiceByDataLib.setDataList(listOfTestCaseByDataLib);419 return testCaseByServiceByDataLib;420 } else {421 return testCaseByService;422 }423 }424 @Override425 public AnswerList readTestCaseByStepsInLibrary(String test) {426 return testCaseDao.readTestCaseByStepsInLibrary(test);427 }428 @Override429 public AnswerList<TestCase> readByTestByCriteria(List<String> system, String test, int start, int amount, String sortInformation, String searchTerm, Map<String, List<String>> individualSearch) {430 return testCaseDao.readByTestByCriteria(system, test, start, amount, sortInformation, searchTerm, individualSearch);431 }432 @Override433 public AnswerItem<TestCase> readByKey(String test, String testCase) {434 return testCaseDao.readByKey(test, testCase);435 }436 @Override437 public AnswerItem<TestCase> readByKeyWithDependency(String test, String testCase) {438 AnswerItem<TestCase> answer = new AnswerItem<>(new MessageEvent(MessageEventEnum.DATA_OPERATION_ERROR_UNEXPECTED));439 AnswerItem<TestCase> ai = testCaseDao.readByKey(test, testCase);440 if (ai.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && ai.getItem() != null) {441 TestCase tc = ai.getItem();442 AnswerList<TestCaseStep> al = testCaseStepService.readByTestTestCaseStepsWithDependencies(tc.getTest(), tc.getTestcase());443 if (al.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode()) && al.getDataList() != null) {444 tc.setSteps(al.getDataList());445 }446 answer.setResultMessage(al.getResultMessage());447 answer.setItem(tc);448 }449 return answer;450 }451 @Override452 public AnswerList<String> readDistinctValuesByCriteria(List<String> system, String test, String searchParameter, Map<String, List<String>> individualSearch, String columnName) {453 return testCaseDao.readDistinctValuesByCriteria(system, test, searchParameter, individualSearch, columnName);454 }455 @Override456 public AnswerList<TestCase> readStatsBySystem(List<String> system, Date to) {457 return testCaseDao.readStatsBySystem(system, to);458 }459 @Override460 public Answer update(String keyTest, String keyTestcase, TestCase testcase) {461 // We first create the corresponding test if it doesn,'t exist.462 if (testcase.getTest() != null && !testService.exist(testcase.getTest())) {463 testService.create(factoryTest.create(testcase.getTest(), "", true, null, testcase.getUsrModif(), null, "", null));464 }465 Answer ans = testCaseDao.update(keyTest, keyTestcase, testcase);466 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {467 eventService.triggerEvent(EventHook.EVENTREFERENCE_TESTCASE_UPDATE, testcase, keyTest, keyTestcase, null);468 }469 return ans;470 }471 @Override472 public Answer create(TestCase testCase) {473 // We first create the corresponding test if it doesn,'t exist.474 if (testCase.getTest() != null && !testService.exist(testCase.getTest())) {475 testService.create(factoryTest.create(testCase.getTest(), "", true, null, testCase.getUsrCreated(), null, "", null));476 }477 Answer ans = testCaseDao.create(testCase);478 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {479 eventService.triggerEvent(EventHook.EVENTREFERENCE_TESTCASE_CREATE, testCase, null, null, null);480 }481 return ans;482 }483 @Override484 public Answer createAPI(TestCase testCase) {485 // We first create the corresponding test if it doesn,'t exist.486 if (testCase.getTest() != null && !testService.exist(testCase.getTest())) {487 testService.create(factoryTest.create(testCase.getTest(), "", true, null, testCase.getUsrCreated(), null, "", null));488 }489 return testCaseDao.create(testCase);490 }491 @Override492 public Answer delete(TestCase testCase) {493 Answer ans = testCaseDao.delete(testCase);494 if (ans.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {495 eventService.triggerEvent(EventHook.EVENTREFERENCE_TESTCASE_DELETE, testCase, null, null, null);496 }497 return ans;498 }499 @Override500 public TestCase convert(AnswerItem<TestCase> answerItem) throws CerberusException {501 if (answerItem.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {502 //if the service returns an OK message then we can get the item503 return answerItem.getItem();504 }505 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));506 }507 @Override508 public List<TestCase> convert(AnswerList<TestCase> answerList) throws CerberusException {509 if (answerList.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {510 //if the service returns an OK message then we can get the item511 return answerList.getDataList();512 }513 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));514 }515 @Override516 public void convert(Answer answer) throws CerberusException {517 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {518 //if the service returns an OK message then we can get the item519 return;520 }521 throw new CerberusException(new MessageGeneral(MessageGeneralEnum.DATA_OPERATION_ERROR));522 }523 @Override524 public boolean hasPermissionsRead(TestCase testCase, HttpServletRequest request) {525 // Access right calculation.526 return true;527 }528 @Override529 public boolean hasPermissionsUpdate(TestCase testCase, HttpServletRequest request) {530 // Access right calculation.531 if (testCase.getStatus().equalsIgnoreCase("WORKING")) { // If testcase is WORKING only TestAdmin can update it532 return request.isUserInRole("TestAdmin");533 } else {534 return request.isUserInRole("Test");535 }536 }537 @Override538 public boolean hasPermissionsCreate(TestCase testCase, HttpServletRequest request) {539 // Access right calculation.540 return request.isUserInRole("Test");541 }542 @Override543 public boolean hasPermissionsDelete(TestCase testCase, HttpServletRequest request) {544 // Access right calculation.545 return request.isUserInRole("TestAdmin");546 }547 @Override548 public void createTestcaseWithDependencies(TestCase testCase) throws CerberusException {549 //TODO ------------------------550 //Check Cerberus version compatibility. If not stop551 //-------------------------------552 //insert testcase553 Answer newTestcase = this.create(testCase);554 if (!newTestcase.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {555 MessageGeneral msg = new MessageGeneral(MessageGeneralEnum.GENERIC_ERROR);556 msg.setDescription(newTestcase.getResultMessage().getDescription());557 throw new CerberusException(msg);558 }559 //for tcstep, insert steps560 for (TestCaseStep tcs : testCase.getSteps()) {561 tcs.setTest(testCase.getTest());562 tcs.setTestcase(testCase.getTestcase());563 Answer newTestcaseStep = testCaseStepService.create(tcs);564 if (!newTestcaseStep.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {565 throw new CerberusException(new MessageGeneral(newTestcaseStep.getResultMessage().getMessage()));566 }567 for (TestCaseStepAction tcsa : tcs.getActions()) {568 tcsa.setTest(testCase.getTest());569 tcsa.setTestcase(testCase.getTestcase());570 Answer newTestcaseStepAction = testCaseStepActionService.create(tcsa);571 if (!newTestcaseStepAction.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {572 throw new CerberusException(new MessageGeneral(newTestcaseStepAction.getResultMessage().getMessage()));573 }574 for (TestCaseStepActionControl tcsac : tcsa.getControls()) {575 tcsac.setTest(testCase.getTest());576 tcsac.setTestcase(testCase.getTestcase());577 Answer newTestcaseStepActionControl = testCaseStepActionControlService.create(tcsac);578 if (!newTestcaseStepActionControl.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {579 throw new CerberusException(new MessageGeneral(newTestcaseStepActionControl.getResultMessage().getMessage()));580 }581 }582 }583 }584 //insert tccountry, insert countries585 for (TestCaseCountry tcc : testCase.getTestCaseCountries()) {586 tcc.setTest(testCase.getTest());587 tcc.setTestcase(testCase.getTestcase());588 Answer newTestcaseCountry = testCaseCountryService.create(tcc);589 if (!newTestcaseCountry.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {590 throw new CerberusException(new MessageGeneral(newTestcaseCountry.getResultMessage().getMessage()));591 }592 for (TestCaseCountryProperties tccp : tcc.getTestCaseCountryProperty()) {593 tccp.setTest(testCase.getTest());594 tccp.setTestcase(testCase.getTestcase());595 Answer newTestcaseCountryProperties = testCaseCountryPropertiesService.create(tccp);596 if (!newTestcaseCountryProperties.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {597 throw new CerberusException(new MessageGeneral(newTestcaseCountryProperties.getResultMessage().getMessage()));598 }599 }600 }601 //insert testcasedependencies602 for (TestCaseDep tcd : testCase.getDependencies()) {603 tcd.setTest(testCase.getTest());604 tcd.setTestcase(testCase.getTestcase());605 testCaseDepService.create(tcd);606 }607 //insert testcaselabel608 for (TestCaseLabel tcl : testCase.getTestCaseLabels()) {609 tcl.setTest(testCase.getTest());610 tcl.setTestcase(testCase.getTestcase());611 testCaseLabelService.create(tcl);612 }613 }614 @Override615 public TestCase createTestcaseWithDependenciesAPI(TestCase newTestcase) throws CerberusException {616 final String FAILED_TO_INSERT = "Failed to insert the testcase in the database";617 if (newTestcase.getTest() == null || newTestcase.getTest().isEmpty()) {618 throw new InvalidRequestException("testFolderId required to create Testcase");619 }620 if (newTestcase.getApplication() == null || newTestcase.getApplication().isEmpty()) {621 throw new InvalidRequestException("application is required to create a Testcase");622 }623 if (newTestcase.getTestcase() != null) {624 throw new InvalidRequestException("testcaseId forbidden to create Testcase");625 }626 newTestcase.setTestcase(this.getNextAvailableTestcaseId(newTestcase.getTest()));627 Answer testcaseCreationAnswer = this.create(newTestcase);628 if (!testcaseCreationAnswer.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {629 throw new FailedInsertOperationException(FAILED_TO_INSERT);630 }631 //for tcstep, insert steps632 if (newTestcase.getSteps() != null) {633 int stepId = 0;634 for (TestCaseStep step : newTestcase.getSteps()) {635 step.setTest(newTestcase.getTest());636 step.setTestcase(newTestcase.getTestcase());637 step.setStepId(stepId++);638 Answer newTestcaseStep = testCaseStepService.create(step);639 if (!newTestcaseStep.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {640 throw new FailedInsertOperationException(FAILED_TO_INSERT);641 }642 if (step.getActions() != null && !step.isUsingLibraryStep()) {643 int actionId = 0;644 for (TestCaseStepAction action : step.getActions()) {645 action.setTest(newTestcase.getTest());646 action.setTestcase(newTestcase.getTestcase());647 action.setStepId(step.getStepId());648 action.setActionId(actionId++);649 Answer newTestcaseStepAction = testCaseStepActionService.create(action);650 if (!newTestcaseStepAction.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {651 throw new FailedInsertOperationException(FAILED_TO_INSERT);652 }653 if (action.getControls() != null) {654 int controlId = 0;655 for (TestCaseStepActionControl control : action.getControls()) {656 control.setTest(newTestcase.getTest());657 control.setTestcase(newTestcase.getTestcase());658 control.setStepId(step.getStepId());659 control.setActionId(action.getActionId());660 control.setControlId(controlId++);661 Answer newTestcaseStepActionControl = testCaseStepActionControlService.create(control);662 if (!newTestcaseStepActionControl.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {663 throw new FailedInsertOperationException(FAILED_TO_INSERT);664 }665 }666 }667 }668 }669 }670 }671 this.fillTestcaseCountriesFromInvariantsCountry(newTestcase);672 if (newTestcase.getTestCaseCountryProperties() != null && !newTestcase.getTestCaseCountryProperties().isEmpty()) {673 newTestcase.setTestCaseCountryProperties(674 this.testCaseCountryPropertiesService.getFlatListOfTestCaseCountryPropertiesFromAggregate(675 newTestcase.getTestCaseCountryProperties()676 )677 );678 }679 for (TestCaseCountry tcc : newTestcase.getTestCaseCountries()) {680 tcc.setTest(newTestcase.getTest());681 tcc.setTestcase(newTestcase.getTestcase());682 Answer newTestcaseCountry = testCaseCountryService.create(tcc);683 if (!newTestcaseCountry.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {684 throw new FailedInsertOperationException(FAILED_TO_INSERT);685 }686 if (tcc.getTestCaseCountryProperty() != null) {687 for (TestCaseCountryProperties tccp : tcc.getTestCaseCountryProperty()) {688 tccp.setTest(newTestcase.getTest());689 tccp.setTestcase(newTestcase.getTestcase());690 Answer newTestcaseCountryProperties = testCaseCountryPropertiesService.create(tccp);691 if (!newTestcaseCountryProperties.getResultMessage().getSource().equals(MessageEventEnum.DATA_OPERATION_OK)) {692 throw new FailedInsertOperationException(FAILED_TO_INSERT);693 }694 }695 }696 }697 //insert testcasedependencies698 if (newTestcase.getDependencies() != null) {699 for (TestCaseDep tcd : newTestcase.getDependencies()) {700 tcd.setTest(newTestcase.getTest());701 tcd.setTestcase(newTestcase.getTestcase());702 try {703 testCaseDepService.create(tcd);704 } catch (CerberusException ex) {705 throw new FailedInsertOperationException(ex.getMessage());706 }707 }708 }709 //insert testcaselabel710 if (newTestcase.getLabels() != null && !newTestcase.getLabels().isEmpty()) {711 newTestcase.setTestCaseLabels(712 this.getTestcaseLabelsFromLabels(713 newTestcase.getLabels(), newTestcase.getTest(), newTestcase.getTestcase(), newTestcase.getUsrCreated()714 )715 );716 this.testCaseLabelService.createList(newTestcase.getTestCaseLabels());717 }718 return this.findTestCaseByKeyWithDependencies(newTestcase.getTest(), newTestcase.getTestcase(), true).getItem();719 }720 public TestCase updateTestcaseAPI(String testFolderId, String testcaseId, TestCase newTestcaseVersion) throws CerberusException {721 if (testFolderId == null || testFolderId.isEmpty()) {722 throw new InvalidRequestException("testFolderId is required to update a testcase");723 }724 if (testcaseId == null || testcaseId.isEmpty()) {725 throw new InvalidRequestException("testcaseId is required to update a testcase");726 }727 TestCase oldTestcaseVersion = new TestCase();728 try {729 oldTestcaseVersion = this.findTestCaseByKeyWithDependencies(newTestcaseVersion.getTest(), newTestcaseVersion.getTestcase(), true).getItem();730 if (oldTestcaseVersion == null) {731 throw new EntityNotFoundException(TestCase.class, "testcaseFolderId", newTestcaseVersion.getTest(), "testcaseId", newTestcaseVersion.getTestcase());732 }733 } catch (CerberusException e) {734 LOG.warn(e.getMessage());735 }736 if (!newTestcaseVersion.equals(oldTestcaseVersion)) {737 newTestcaseVersion.setVersion(newTestcaseVersion.getVersion() + 1);738 LOG.debug(this.updateTestCaseInformation(newTestcaseVersion));739 }740 if (newTestcaseVersion.getSteps() != null && !newTestcaseVersion.getSteps().isEmpty()) {741 this.testCaseStepService.compareListAndUpdateInsertDeleteElements(newTestcaseVersion.getSteps(), oldTestcaseVersion.getSteps(), false);742 List<TestCaseStepAction> newActions = this.getAllActionsFromTestcase(newTestcaseVersion);743 List<TestCaseStepAction> oldActions = this.testCaseStepActionService.readByTestTestCase(testFolderId, testcaseId).getDataList();744 this.testCaseStepActionService.compareListAndUpdateInsertDeleteElements(newActions, oldActions, false);745 List<TestCaseStepActionControl> newControls = this.getAllControlsFromTestcase(newTestcaseVersion);746 List<TestCaseStepActionControl> oldControls = this.testCaseStepActionControlService.findControlByTestTestCase(testFolderId, testcaseId);747 this.testCaseStepActionControlService.compareListAndUpdateInsertDeleteElements(newControls, oldControls, false);748 }749 this.fillTestcaseCountriesFromInvariantsCountry(newTestcaseVersion);750 this.testCaseCountryService.compareListAndUpdateInsertDeleteElements(751 newTestcaseVersion.getTest(),752 newTestcaseVersion.getTestcase(),753 newTestcaseVersion.getTestCaseCountries()754 );755 if (newTestcaseVersion.getTestCaseCountryProperties() != null && !newTestcaseVersion.getTestCaseCountryProperties().isEmpty()) {756 newTestcaseVersion.setTestCaseCountryProperties(757 this.testCaseCountryPropertiesService758 .getFlatListOfTestCaseCountryPropertiesFromAggregate(newTestcaseVersion.getTestCaseCountryProperties())759 );760 }761 LOG.debug(newTestcaseVersion.getTestCaseCountryProperties());762 if (newTestcaseVersion.getTestCaseCountryProperties() != null && !newTestcaseVersion.getTestCaseCountryProperties().isEmpty()) {763 this.testCaseCountryPropertiesService.compareListAndUpdateInsertDeleteElements(764 newTestcaseVersion.getTest(),765 newTestcaseVersion.getTestcase(),766 newTestcaseVersion.getTestCaseCountryProperties()767 );768 }769 if (newTestcaseVersion.getDependencies() != null && !newTestcaseVersion.getDependencies().isEmpty()) {770 this.testCaseDepService.compareListAndUpdateInsertDeleteElements(771 newTestcaseVersion.getTest(),772 newTestcaseVersion.getTestcase(),773 newTestcaseVersion.getDependencies()774 );775 }776 if (newTestcaseVersion.getLabels() != null && !newTestcaseVersion.getLabels().isEmpty()) {777 newTestcaseVersion.setTestCaseLabels(778 this.getTestcaseLabelsFromLabels(779 newTestcaseVersion.getLabels(), newTestcaseVersion.getTest(), newTestcaseVersion.getTestcase(), newTestcaseVersion.getUsrCreated()780 )781 );782 this.testCaseLabelService.compareListAndUpdateInsertDeleteElements(783 newTestcaseVersion.getTest(),784 newTestcaseVersion.getTestcase(),785 newTestcaseVersion.getTestCaseLabels()786 );787 }788 return this.findTestCaseByKeyWithDependencies(newTestcaseVersion.getTest(), newTestcaseVersion.getTestcase(), true).getItem();789 }790 private void fillTestcaseCountriesFromInvariantsCountry(TestCase testcase) {791 if (testcase.getInvariantCountries() == null || testcase.getInvariantCountries().isEmpty()) {792 try {793 testcase.setInvariantCountries(this.invariantService.readByIdName("COUNTRY"));794 } catch (CerberusException e) {795 LOG.warn("Unable to retrieve countries from invariant table" + e);796 }797 }798 testcase.getInvariantCountries()799 .forEach(invariantCountry -> testcase.appendTestCaseCountries(800 TestCaseCountry.builder()801 .test(testcase.getTest())802 .testcase(testcase.getTestcase())...
findTestCaseByKeyWithDependencies
Using AI Code Generation
1import org.cerberus.crud.entity.TestCase;2import org.cerberus.crud.service.impl.TestCaseService;3import org.cerberus.engine.entity.MessageEvent;4import org.cerberus.engine.entity.MessageGeneral;5import org.cerberus.engine.entity.MessageGeneralEnum;6import org.cerberus.engine.execution.IExecutionThreadService;7import org.cerberus.engine.execution.IExecutionThreadPoolService;8import org.cerberus.engine.execution.impl.ExecutionThreadService;9import org.cerberus.engine.execution.impl.ExecutionThreadPoolService;10import org.cerberus.engine.threadpool.IExecutionThreadPool;11import org.cerberus.engine.threadpool.impl.ExecutionThreadPool;12import org.cerberus.engine.threadpool.impl.ExecutionThreadPoolFactory;13import org.cerberus.exception.CerberusException;14import org.cerberus.util.answer.AnswerList;15import org.springframework.beans.factory.annotation.Autowired;16import org.springframework.stereotype.Service;17public class CerberusEngineService implements ICerberusEngineService {18 private static final org.apache.logging.log4j.Logger LOG = org.apache.logging.log4j.LogManager.getLogger(CerberusEngineService.class);19 private TestCaseService testCaseService;20 public MessageEvent executeTestCase(String testCase, String test, String environment, String country, String browser, String browserVersion, String platform, String tag, String outputFormat, String screenshot, String pageSource, String verbose, String seleniumIP, String seleniumPort, String timeout, String retries, String manualURL, String manualHost, String manualContextRoot, String manualLoginRelativeURL, String manualEnvData, String manualExecution) throws CerberusException {21 MessageEvent message = new MessageEvent(MessageEventEnum.GENERIC_OK);22 message.setDescription(message.getDescription().replace("%TEST%", test).replace("%TESTCASE%", testCase));23 AnswerList<TestCase> answer = testCaseService.findTestCaseByKeyWithDependencies(test, testCase);24 if (answer.isCodeEquals(MessageEventEnum.DATA_OPERATION_OK.getCode())) {25 if (answer.getDataList().isEmpty()) {26 message = new MessageEvent(MessageEventEnum.DATA_OPERATION_NO_DATA_FOUND);27 message.setDescription(message.getDescription().replace("%TEST%", test).replace("%TESTCASE%", testCase));28 } else {29 TestCase tCase = answer.getDataList().get(0);30 IExecutionThreadPoolService executionThreadPoolService = new ExecutionThreadPoolService();
findTestCaseByKeyWithDependencies
Using AI Code Generation
1import org.cerberus.crud.entity.TestCase2import org.cerberus.crud.service.impl.TestCaseService3import org.cerberus.crud.service.impl.TestCaseExecutionService4import org.cerberus.crud.service.impl.TestCaseStepService5import org.cerberus.crud.service.impl.TestCaseCountryService6import org.cerberus.crud.service.impl.TestCaseCountryPropertiesService7import org.cerberus.crud.service.impl.TestCaseStepActionService8import org.cerberus.crud.service.impl.TestCaseStepActionControlService9import org.cerberus.crud.service.impl.TestCaseStepActionControlExecutionService10import org.cerberus.crud.service.impl.TestCaseStepActionExecutionService11import org.cerberus.crud.service.impl.TestCaseStepExecutionService12import org.cerberus.crud.service.impl.TestBatteryService13import org.cerberus.crud.service.impl.TestBatteryContentService14import org.cerberus.crud.service.impl.TestBatteryContentSequenceService15import org.cerberus.crud.service.impl.TestBatteryExecutionService16import org.cerberus.crud.service.impl.TestBatteryExecutionContentService17import org.cerberus.crud.service.impl.TestBatteryExecutionContentSequenceService18import org.cerberus.crud.service.impl.TestService19import org.cerberus.crud.service.impl.TestBatteryService20import org.cerberus.crud.service.impl.TestBatteryContentService21import org.cerberus.crud.service.impl.TestBatteryContentSequenceService22import org.cerberus.crud.service.impl.TestBatteryExecutionService23import org.cerberus.crud.service.impl.TestBatteryExecutionContentService24import org.cerberus.crud.service.impl.TestBatteryExecutionContentSequenceService25import org.cerberus.crud.service.impl.TestBatteryExecutionContentService26import org.cerberus.crud.service.impl.TestBatteryExecutionContentSequenceService27import org.cerberus.crud.service.impl.TestBatteryExecutionContentService28import org.cerberus.crud.service.impl.TestBatteryExecutionContentSequenceService29import org.cerberus.crud.service.impl.TestBatteryExecutionContentService30import org.cerberus.crud.service.impl.TestBatteryExecutionContentSequenceService31import org.cerberus.crud.service.impl.TestBatteryExecutionContentService32import org.cerberus.crud.service.impl.TestBatteryExecutionContentSequenceService33import org.cerberus.cr
findTestCaseByKeyWithDependencies
Using AI Code Generation
1 TestCaseService testCaseService = ApplicationContextProvider.getApplicationContext().getBean(TestCaseService.class);2 TestCase tc = testCaseService.findTestCaseByKeyWithDependencies(test, testCase);3 TestCaseCountryPropertiesService testCaseCountryPropertiesService = ApplicationContextProvider.getApplicationContext().getBean(TestCaseCountryPropertiesService.class);4 List<TestCaseCountryProperties> tcCountryProperties = testCaseCountryPropertiesService.findListOfPropertyPerTestTestCaseCountry(test, testCase, country);5 TestCaseStepService testCaseStepService = ApplicationContextProvider.getApplicationContext().getBean(TestCaseStepService.class);6 List<TestCaseStep> tcSteps = testCaseStepService.findTestCaseStepByTestTestCase(test, testCase);7 TestCaseStepActionService testCaseStepActionService = ApplicationContextProvider.getApplicationContext().getBean(TestCaseStepActionService.class);8 List<TestCaseStepAction> tcStepActions = testCaseStepActionService.findTestCaseStepActionByTestTestCase(test, testCase);9 TestCaseStepActionControlService testCaseStepActionControlService = ApplicationContextProvider.getApplicationContext().getBean(TestCaseStepActionControlService.class);10 List<TestCaseStepActionControl> tcStepActionControls = testCaseStepActionControlService.findControlByTestTestCase(test, testCase);11 TestCaseExecutionService testCaseExecutionService = ApplicationContextProvider.getApplicationContext().getBean(TestCaseExecutionService.class);
findTestCaseByKeyWithDependencies
Using AI Code Generation
1String test = "TEST";2String testCase = "TC1";3int maxDepth = 2;4List<TestCase> testCaseList = new ArrayList<>();5List<TestCase> testCaseListToProcess = new ArrayList<>();6TestCase startTestCase = testCaseService.findTestCaseByKeyWithDependencies(test, testCase);7testCaseListToProcess.add(startTestCase);8while (!testCaseListToProcess.isEmpty()) {9 TestCase testCaseToProcess = testCaseListToProcess.get(0);10 testCaseListToProcess.remove(0);11 testCaseList.add(testCaseToProcess);12 List<TestCase> linkedTestCases = testCaseService.findTestCaseByDependency(testCaseToProcess);13 if (!linkedTestCases.isEmpty()) {14 if (testCaseToProcess.getDepth() < maxDepth) {15 testCaseListToProcess.addAll(linkedTestCases);16 }17 }18}19for (TestCase testCase : testCaseList) {20 System.out.println(testCase.getTest() + " - " + testCase.getTestCase());21}
findTestCaseByKeyWithDependencies
Using AI Code Generation
1TestCase testCase = new TestCase();2testCase.setTest("TEST");3testCase.setTestCase("TESTCASE");4try {5 testCase = testCaseService.findTestCaseByKeyWithDependencies(testCase);6} catch (CerberusException ex) {7 Logger.getLogger(UseFindTestCaseByKeyWithDependencies.class.getName()).log(Level.SEVERE, null, ex);8}9System.out.println(testCase);10System.out.println(testCase.getTestCaseStepList());11System.out.println(testCase.getTestCaseCountryList());12System.out.println(testCase.getTestCaseLabelList());13System.out.println(testCase.getTestCaseControlList());14System.out.println(testCase.getTestCaseStepActionControlList());15System.out.println(testCase.getTestCaseStepActionControlExecutionList());16System.out.println(testCase.getTestCaseStepActionExecutionList());17System.out.println(testCase.getTestCaseExecutionList());18System.out.println(testCase.getTestCaseExecutionQueueList());19System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionList());20System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionExecutionList());21System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionControlList());22System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionControlExecutionList());23System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionList().get(0).getTestCaseStepActionControlList());24System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionList().get(0).getTestCaseStepActionControlExecutionList());25System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionList().get(0).getTestCaseStepActionControlList().get(0).getTestCaseStepActionControlExecutionList());26System.out.println(testCase.getTestCaseStepList().get(0).getTestCaseStepActionList().get(0).getTestCaseStepActionControlList().get(0).getTestCaseStepActionControlExecutionList().get(0).getTestCaseExecutionList());
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!!