Best Testsigma code snippet using com.testsigma.service.TestSuiteService.handleTestCaseMappings
Source:TestSuiteService.java
...73 validatePreRequisiteIsValid(testSuite, prereq);74 testSuite = this.repository.save(testSuite);75 testSuite.setTestCaseIds(testCaseIds);76 tagService.updateTags(testSuite.getTags(), TagType.TEST_SUITE, testSuite.getId());77 this.handleTestCaseMappings(testSuite);78 publishEvent(testSuite, EventType.CREATE);79 return testSuite;80 }81 public TestSuite update(TestSuite testSuite) throws TestsigmaException {82 List<Long> testCaseIds = testSuite.getTestCaseIds();83 List<String> tagNames = testSuite.getTags();84 List<Long> prereq = new ArrayList<>();85 prereq.add(testSuite.getId());86 validatePreRequisiteIsValid(testSuite, prereq);87 testSuite = this.repository.save(testSuite);88 testSuite.setTestCaseIds(testCaseIds);89 testSuite.setTags(tagNames);90 if (testSuite.getTags() != null)91 tagService.updateTags(testSuite.getTags(), TagType.TEST_SUITE, testSuite.getId());92 this.handleTestCaseMappings(testSuite);93 publishEvent(testSuite, EventType.UPDATE);94 return testSuite;95 }96 public void handlePrequisiteChange(TestSuite testSuite){97 this.suiteMappingService.handlePreRequisiteChange(testSuite);98 }99 private void validatePreRequisiteIsValid(TestSuite testSuite, List<Long> preReqList) throws TestsigmaException {100 Long preRequsiteId = testSuite.getPreRequisite();101 if (preRequsiteId != null) {102 if (preReqList.size() > 5) {103 log.debug("Testsuite Prerequisite hierarchy is more than 5,Prerequisite IDs:" + preReqList);104 throw new TestsigmaException("Prerequisite hierarchy crossed the allowed limit of 5");105 } else if (preReqList.contains(testSuite.getPreRequisite())) {106 log.debug("Cyclic dependency for Testsuite prerequisites found for Testsuite:" + testSuite);107 throw new TestsigmaException("Prerequisite to the Testsuite is not valid. This prerequisite causes cyclic dependencies for Testsuites.");108 }109 preReqList.add(preRequsiteId);110 TestSuite preReqTestSuite = find(preRequsiteId);111 if (preReqTestSuite.getPreRequisite() != null) {112 validatePreRequisiteIsValid(preReqTestSuite, preReqList);113 }114 } else {115 return;116 }117 }118 public TestSuite updateSuite(TestSuite testSuite) {119 testSuite = this.repository.save(testSuite);120 publishEvent(testSuite, EventType.UPDATE);121 return testSuite;122 }123 public void destroy(Long id) throws ResourceNotFoundException {124 TestSuite testSuite = this.find(id);125 publishEvent(testSuite, EventType.DELETE);126 this.repository.deleteById(id);127 }128 public void handleTestCaseMappings(TestSuite testSuite) {129 int position = 0;130 List<SuiteTestCaseMapping> newMappings = new ArrayList<>();131 List<SuiteTestCaseMapping> updatedMappings = new ArrayList<>();132 this.cleanupOrphanCaseMappings(testSuite);133 List<SuiteTestCaseMapping> mappings = this.suiteTestCaseMappingRepository.findBySuiteIdAndTestCaseIds(testSuite.getId(), testSuite.getTestCaseIds());134 for (Long testCaseId : testSuite.getTestCaseIds()) {135 SuiteTestCaseMapping suiteTestCaseMapping = new SuiteTestCaseMapping();136 Optional<SuiteTestCaseMapping> existing = mappings.stream().filter(mapping -> mapping.getTestCaseId().equals(testCaseId)).findFirst();137 position++;138 if (existing.isPresent()) {139 suiteTestCaseMapping = existing.get();140 if (!suiteTestCaseMapping.getPosition().equals(position)) {141 suiteTestCaseMapping.setPosition(position);142 suiteTestCaseMapping = this.suiteTestCaseMappingService.update(suiteTestCaseMapping);143 updatedMappings.add(suiteTestCaseMapping);144 }145 } else {146 suiteTestCaseMapping.setSuiteId(testSuite.getId());147 suiteTestCaseMapping.setTestCaseId(testCaseId);148 suiteTestCaseMapping.setPosition(position);149 suiteTestCaseMapping = this.suiteTestCaseMappingService.add(suiteTestCaseMapping);150 newMappings.add(suiteTestCaseMapping);151 }152 }153 testSuite.setUpdatedTestCases(updatedMappings);154 testSuite.setAddedTestCases(newMappings);155 }156 private void cleanupOrphanCaseMappings(TestSuite testSuite) {157 List<SuiteTestCaseMapping> suiteTestCaseMappings = this.suiteTestCaseMappingService.findAllBySuiteId(testSuite.getId());158 List<Long> existingCaseIds = suiteTestCaseMappings.stream().map(SuiteTestCaseMapping::getTestCaseId).collect(Collectors.toList());159 existingCaseIds.removeAll(testSuite.getTestCaseIds());160 if (existingCaseIds.size() > 0) {161 this.deleteAllBySuiteIdAndCaseIds(testSuite, existingCaseIds);162 List<Long> testCaseIds = testSuite.getTestCaseIds();163 testCaseIds.removeAll(existingCaseIds);164 testSuite.setTestCaseIds(testCaseIds);165 }166 }167 private void deleteAllBySuiteIdAndCaseIds(TestSuite suite, List<Long> existingCaseIds) {168 List<SuiteTestCaseMapping> mappings = this.suiteTestCaseMappingRepository.findBySuiteIdAndTestCaseIds(suite.getId(), existingCaseIds);169 suite.setRemovedTestCases(mappings);170 this.suiteTestCaseMappingService.deleteAll(mappings);171 }172 public void bulkDelete(Long[] ids) throws Exception {173 Boolean allIdsDeleted = true;174 TestPlanSpecificationsBuilder builder = new TestPlanSpecificationsBuilder();175 for (Long id : ids) {176 List<SearchCriteria> params = new ArrayList<>();177 params.add(new SearchCriteria("suiteId", SearchOperation.EQUALITY, id));178 builder.setParams(params);179 Specification<TestPlan> spec = builder.build();180 Page<TestPlan> linkedTestPlans = testPlanService.findAll(spec, PageRequest.of(0, 1));181 if (linkedTestPlans.getTotalElements() == 0) {182 this.destroy(id);183 } else {184 allIdsDeleted = false;185 }186 }187 if (!allIdsDeleted) {188 throw new DataIntegrityViolationException("dataIntegrityViolationException");189 }190 }191 public void publishEvent(TestSuite testSuite, EventType eventType) {192 TestSuiteEvent<TestSuite> event = createEvent(testSuite, eventType);193 log.info("Publishing event - " + event.toString());194 applicationEventPublisher.publishEvent(event);195 }196 public TestSuiteEvent<TestSuite> createEvent(TestSuite testSuite, EventType eventType) {197 TestSuiteEvent<TestSuite> event = new TestSuiteEvent<>();198 event.setEventData(testSuite);199 event.setEventType(eventType);200 return event;201 }202 public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {203 if (!backupDTO.getIsSuitesEnabled()) return;204 writeXML("test_suites", backupDTO, PageRequest.of(0, 25));205 }206 public Specification<TestSuite> getExportXmlSpecification(BackupDTO backupDTO) {207 SearchCriteria criteria = new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, backupDTO.getWorkspaceVersionId());208 List<SearchCriteria> params = new ArrayList<>();209 params.add(criteria);210 TestSuiteSpecificationsBuilder testStepSpecificationsBuilder = new TestSuiteSpecificationsBuilder();211 testStepSpecificationsBuilder.params = params;212 return testStepSpecificationsBuilder.build();213 }214 @Override215 protected List<TestSuiteXMLDTO> mapToXMLDTOList(List<TestSuite> list) {216 return mapper.mapTestSuites(list);217 }218 public void handlePreRequisiteChange(TestCase testCase) {219 List<TestSuite> testSuites =repository.findAllByTestCaseId(testCase.getId());220 testSuites.forEach(testSuite -> {221 List<Long> testCaseIds = suiteTestCaseMappingRepository.findTestCaseIdsByTestSuiteId(testSuite.getId());222 if (!testCaseIds.contains(testCase.getPreRequisite())) {223 int indexOfCaseId = testCaseIds.indexOf(testCase.getId());224 testCaseIds.add(indexOfCaseId, testCase.getPreRequisite());225 testSuite.setTestCaseIds(testCaseIds);226 handleTestCaseMappings(testSuite);227 }228 });229 }230}...
handleTestCaseMappings
Using AI Code Generation
1import com.testsigma.service.TestSuiteService2def testSuiteService = new TestSigmaService()3def testCaseMappings = testSuiteService.handleTestCaseMappings(testSuiteId)4def testCaseIds = testCaseMappings.keySet()5import com.testsigma.service.TestCaseService6def testCaseService = new TestCaseService()7def testCase = testCaseService.getTestCase(testCaseId)8import com.testsigma.service.TestSuiteService9def testSuiteService = new TestSuiteService()10def testSuite = testSuiteService.getTestSuite(testSuiteId)11import com.testsigma.service.TestCaseService12def testCaseService = new TestCaseService()13def testCases = testCaseService.getTestCases(testSuiteId)14import com.testsigma.service.TestCaseService15def testCaseService = new TestCaseService()16def testCases = testCaseService.getTestCases(testSuiteName)
handleTestCaseMappings
Using AI Code Generation
1import com.testsigma.service.TestSuiteService2def testSuiteService = new TestSuiteService()3def testCaseMappings = testSuiteService.handleTestCaseMappings(testSuiteId)4def testCaseIds = testCaseMappings.collect{it.testCaseId}5def testCaseNames = testCaseMappings.collect{it.testCaseName}6def testCaseMappingIds = testCaseMappings.collect{it.testCaseMappingId}7import groovy.json.JsonBuilder8import com.testsigma.service.TestSuiteService9import com.testsigma.service.TestSuiteService10def testSuiteService = new TestSuiteService()11def testCaseMappings = testSuiteService.handleTestCaseMappings(testSuiteId)12def testCaseIds = testCaseMappings.collect{it.testCaseId}13def testSuiteService = new TestSuiteService()14def testCaseMappings = testSuiteService.handleTestCaseMappings(testSuiteId)15def testCaseIds = testCaseMappings.collect{it.testCaseId}16def testCaseNames = testCaseMappings.collect{it.testCaseName}17def testCaseMappingIds = testCaseMappings.collect{it.testCaseMappingId}18def testSuiteService = new TestSuiteService()19def testCaseMappings = testSuiteService.handleTestCaseMappings(testSuiteId)20def testCaseIds = testCaseMappings.collect{it.testCaseId}21def testCaseNames = testCaseMappings.collect{it.testCaseName}22def testCaseMappingIds = testCaseMappings.collect{it.testCaseMappingId}23def testSuiteService = new TestSuiteService()24def testCaseMappings = testSuiteService.handleTestCaseMappings(testSuiteId)25def testCaseIds = testCaseMappings.collect{it.testCaseId}26def testCaseNames = testCaseMappings.collect{it.testCaseName}27def testCaseMappingIds = testCaseMappings.collect{it.testCaseMappingId}28def testSuiteService = new TestSuiteService()29def testCaseMappings = testSuiteService.handleTestCaseMappings(testSuiteId)30def testCaseIds = testCaseMappings.collect{it.testCaseId}31def testCaseNames = testCaseMappings.collect{it.testCaseName}32def testCaseMappingIds = testCaseMappings.collect{it.testCaseMappingId}33def testSuiteService = new TestSuiteService()
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!!