Best Testsigma code snippet using com.testsigma.specification.TestCaseSpecificationsBuilder
Source:TestCaseService.java  
...17import com.testsigma.model.*;18import com.testsigma.repository.TestCaseRepository;19import com.testsigma.specification.SearchCriteria;20import com.testsigma.specification.SearchOperation;21import com.testsigma.specification.TestCaseSpecificationsBuilder;22import com.testsigma.web.request.TestCaseCopyRequest;23import com.testsigma.web.request.TestCaseRequest;24import lombok.RequiredArgsConstructor;25import lombok.extern.log4j.Log4j2;26import org.springframework.beans.factory.ObjectFactory;27import org.springframework.beans.factory.annotation.Autowired;28import org.springframework.context.ApplicationEventPublisher;29import org.springframework.context.annotation.Lazy;30import org.springframework.data.domain.Page;31import org.springframework.data.domain.PageRequest;32import org.springframework.data.domain.Pageable;33import org.springframework.data.jpa.domain.Specification;34import org.springframework.stereotype.Service;35import java.io.IOException;36import java.sql.SQLException;37import java.sql.Timestamp;38import java.util.*;39@Service40@RequiredArgsConstructor(onConstructor = @__({@Autowired, @Lazy}))41@Log4j242public class TestCaseService extends XMLExportService<TestCase> {43  private final TestCaseMapper testCaseMapper;44  private final com.testsigma.service.TestPlanService testPlanService;45  private final TestDeviceService testDeviceService;46  private final TestDeviceResultService testDeviceResultService;47  private final ObjectFactory<AgentExecutionService> agentExecutionServiceObjectFactory;48  private final TestCaseRepository testCaseRepository;49  private final TagService tagService;50  private final TestStepService testStepService;51  private final TestStepMapper testStepMapper;52  private final ApplicationEventPublisher applicationEventPublisher;53  private final com.testsigma.service.DryTestPlanService dryTestPlanService;54  private final TestCaseMapper mapper;55  private final TestCaseFilterService testCaseFilterService;56  private final StepGroupFilterService stepGroupFilterService;57  private final WorkspaceVersionService workspaceVersionService;58  private final TestSuiteService testSuiteService;59  public Page<TestCase> findAll(Specification<TestCase> specification, Pageable pageable) {60    return testCaseRepository.findAll(specification, pageable);61  }62  public List<TestCase> findAllByWorkspaceVersionId(Long workspaceVersionId) {63    return testCaseRepository.findAllByWorkspaceVersionId(workspaceVersionId);64  }65  public List<TestCase> findAllBySuiteId(Long suiteId) {66    return this.testCaseRepository.findAllBySuiteId(suiteId);67  }68  public Page<TestCase> findAllByTestDataId(Long testDataId, Pageable pageable) {69    return this.testCaseRepository.findAllByTestDataId(testDataId, pageable);70  }71  public Page<TestCase> findAllByPreRequisite(Long preRequisite, Pageable pageable) {72    return this.testCaseRepository.findAllByPreRequisite(preRequisite, pageable);73  }74  public TestCase find(Long id) throws ResourceNotFoundException {75    return testCaseRepository.findById(id).orElseThrow(76      () -> new ResourceNotFoundException("Couldn't find TestCase resource with id:" + id));77  }78  public TestCaseEntityDTO find(Long id, Long environmentResultId, String testDataSetName, Long testCaseResultId) {79    TestCaseEntityDTO testCaseEntityDTO = new TestCaseEntityDTO();80    try {81      TestCase testCase = this.find(id);82      testCaseEntityDTO = testCaseMapper.map(testCase);83      TestDeviceResult testDeviceResult = testDeviceResultService.find(environmentResultId);84      TestDevice testDevice = testDeviceService.find(testDeviceResult.getTestDeviceId());85      Optional<TestPlan> optionalTestPlan = testPlanService.findOptional(testDevice.getTestPlanId());86      AbstractTestPlan testPlan;87      if (optionalTestPlan.isPresent())88        testPlan = optionalTestPlan.get();89      else90        testPlan = dryTestPlanService.find(testDevice.getTestPlanId());91      WorkspaceVersion applicationVersion = testPlan.getWorkspaceVersion();92      Workspace workspace = applicationVersion.getWorkspace();93      testCaseEntityDTO.setTestCaseResultId(testCaseResultId);94      testCaseEntityDTO.setStatus(testDeviceResult.getStatus());95      testCaseEntityDTO.setResult(testDeviceResult.getResult());96      AgentExecutionService agentExecutionService = agentExecutionServiceObjectFactory.getObject();97      agentExecutionService.setTestPlan(testPlan);98      agentExecutionService.checkTestCaseIsInReadyState(testCase);99      agentExecutionService100        .loadTestCase(testDataSetName, testCaseEntityDTO, testPlan, workspace);101    } catch (TestsigmaNoMinsAvailableException e) {102      log.debug("======= Testcase Error=========");103      log.error(e.getMessage(), e);104      testCaseEntityDTO.setMessage(e.getMessage());105      testCaseEntityDTO.setErrorCode(ExceptionErrorCodes.ERROR_MINS_VALIDATION_FAILURE);106      return testCaseEntityDTO;107    } catch (TestsigmaException e) {108      log.debug("======= Testcase Error=========");109      log.error(e.getMessage(), e);110      if (e.getErrorCode() != null) {111        if (e.getErrorCode().equals(ExceptionErrorCodes.ENVIRONMENT_PARAMETERS_NOT_CONFIGURED)) {112          testCaseEntityDTO.setErrorCode(ExceptionErrorCodes.ERROR_ENVIRONMENT_PARAM_FAILURE);113        } else if (e.getErrorCode().equals(ExceptionErrorCodes.ENVIRONMENT_PARAMETER_NOT_FOUND)) {114          testCaseEntityDTO.setErrorCode(ExceptionErrorCodes.ERROR_ENVIRONMENT_PARAM_FAILURE);115        } else if (e.getErrorCode().equals(ExceptionErrorCodes.TEST_DATA_SET_NOT_FOUND)) {116          testCaseEntityDTO.setErrorCode(ExceptionErrorCodes.ERROR_TEST_DATA_SET_FAILURE);117        } else if (e.getErrorCode().equals(ExceptionErrorCodes.TEST_DATA_NOT_FOUND)) {118          testCaseEntityDTO.setErrorCode(ExceptionErrorCodes.ERROR_TEST_DATA_FAILURE);119        } else if (e.getErrorCode().equals(ExceptionErrorCodes.ELEMENT_NOT_FOUND)) {120          testCaseEntityDTO.setErrorCode(ExceptionErrorCodes.ERROR_ELEMENT_FAILURE);121        }122      }123      testCaseEntityDTO.setErrorCode(testCaseEntityDTO.getErrorCode() == null ? ExceptionErrorCodes.UNKNOWN_ERROR : testCaseEntityDTO.getErrorCode());124      testCaseEntityDTO.setMessage(e.getMessage());125      return testCaseEntityDTO;126    } catch (Exception e) {127      log.debug("======= Testcase Error=========");128      log.error(e.getMessage(), e);129      testCaseEntityDTO.setErrorCode(ExceptionErrorCodes.UNKNOWN_ERROR);130      testCaseEntityDTO.setMessage(e.getMessage());131      return testCaseEntityDTO;132    }133    return testCaseEntityDTO;134  }135  public TestCase create(TestCaseRequest testCaseRequest) throws TestsigmaException, SQLException {136    TestCase testCase = testCaseMapper.map(testCaseRequest);137    testCase.setIsActive(true);138    testCase.setCreatedDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));139    setStatusTimeAndBy(testCaseRequest, testCase);140    List<Long> preReqList = new ArrayList<>();141    preReqList.add(testCase.getId());142    validatePreRequisiteIsValid(testCase, preReqList);143    testCase = create(testCase);144    tagService.updateTags(testCaseRequest.getTags(), TagType.TEST_CASE, testCase.getId());145    return testCase;146  }147  public TestCase create(TestCase testCaseRequest) {148    TestCase testCase = testCaseRepository.save(testCaseRequest);149    publishEvent(testCase, EventType.CREATE);150    return testCase;151  }152  public TestCase update(TestCase testCase) {153    testCase = this.testCaseRepository.save(testCase);154    publishEvent(testCase, EventType.UPDATE);155    return testCase;156  }157  public TestCase update(TestCaseRequest testCaseRequest, Long id) throws TestsigmaException, SQLException {158    TestCase testCase = testCaseRepository.findById(id).get();159    Long oldPreRequisite = testCase.getPreRequisite();160    testCase.setUpdatedDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));161    setStatusTimeAndBy(testCaseRequest, testCase);162    testCaseMapper.map(testCaseRequest, testCase);163    List<Long> preReqList = new ArrayList<>();164    preReqList.add(testCase.getId());165    validatePreRequisiteIsValid(testCase, preReqList);166    testCase = update(testCase);167    if (testCaseRequest.getTags() != null) {168      tagService.updateTags(testCaseRequest.getTags(), TagType.TEST_CASE, testCase.getId());169    }170    if (testCase.getPreRequisite() != null && !testCase.getPreRequisite().equals(oldPreRequisite)){171        testSuiteService.handlePreRequisiteChange(testCase);172    }173    return testCase;174  }175  private void validatePreRequisiteIsValid(TestCase testCase, List<Long> preReqList) throws TestsigmaException {176    Long preRequisiteId = testCase.getPreRequisite();177    if (preRequisiteId != null) {178      if (preReqList.size() > 5) {179        log.debug("Testcase Prerequisite hierarchy is more than 5,Prerequisite IDs:" + preReqList);180        throw new TestsigmaException("Prerequisite hierarchy crossed the allowed limit of 5");181      } else if (preReqList.contains(testCase.getPreRequisite())) {182        log.debug("Cyclic dependency for Testsuite prerequisites found for Testsuite:" + testCase);183        throw new TestsigmaException("Prerequisite to the TestCase is not valid. This prerequisite causes cyclic dependencies for TestCase.");184      }185      preReqList.add(preRequisiteId);186      TestCase preRequisiteTestCase = find(preRequisiteId);187      if (preRequisiteTestCase.getPreRequisite() != null) {188        validatePreRequisiteIsValid(preRequisiteTestCase, preReqList);189      }190    } else {191      return;192    }193  }194  //TODO:need to revisit this code[chandra]195  private void setStatusTimeAndBy(TestCaseRequest testCaseRequest, TestCase testcase) throws ResourceNotFoundException, TestsigmaDatabaseException, SQLException {196    TestCaseStatus status = testCaseRequest.getStatus();197    Timestamp at = new Timestamp(System.currentTimeMillis());198    if (status.equals(TestCaseStatus.DRAFT)) {199      testCaseRequest.setDraftAt(at);200    } else if (status.equals(TestCaseStatus.IN_REVIEW)) {201      if (!testcase.getStatus().equals(TestCaseStatus.IN_REVIEW)) {202        testCaseRequest.setReviewSubmittedAt(at);203      }204    } else if (status.equals(TestCaseStatus.READY)) {205      if (testcase.getStatus().equals(TestCaseStatus.IN_REVIEW)) {206        testCaseRequest.setReviewedAt(at);207      }208    } else if (status.equals(TestCaseStatus.OBSOLETE)) {209      testCaseRequest.setObsoleteAt(at);210    }211  }212  public Integer markAsDelete(List<Long> ids) {213    return testCaseRepository.markAsDelete(ids);214  }215  public void restore(Long id) {216    testCaseRepository.markAsRestored(id);217  }218  public void destroy(Long id) throws ResourceNotFoundException {219    TestCase testcase = this.find(id);220    testCaseRepository.delete(testcase);221    publishEvent(testcase, EventType.DELETE);222  }223  public Long automatedCountByVersion(Long versionId) {224    return this.testCaseRepository.countByVersion(versionId);225  }226  public Long testCaseCountByPreRequisite(Long testCaseId){227    return this.testCaseRepository.countByPreRequisite(testCaseId);228  }229  public List<Long> getTestCaseIdsByPreRequisite(Long testCaseId){230    return this.testCaseRepository.getTestCaseIdsByPreRequisite(testCaseId);231  }232  public List<TestCaseStatusBreakUpDTO> breakUpByStatus(Long versionId) {233    return this.testCaseRepository.breakUpByStatus(versionId);234  }235  public List<TestCaseTypeBreakUpDTO> breakUpByType(Long versionId) {236    return this.testCaseRepository.breakUpByType(versionId);237  }238  public TestCase copy(TestCaseCopyRequest testCaseRequest) throws ResourceNotFoundException, SQLException {239    TestCase parentCase = this.find(testCaseRequest.getTestCaseId());240    TestCase testCase = this.testCaseMapper.copy(parentCase);241    testCase.setStatus(parentCase.getStatus());242    testCase.setName(testCaseRequest.getName());243    testCase.setCreatedDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));244    testCase.setLastRunId(null);245    if (testCaseRequest.getIsStepGroup()) {246      testCase.setTestDataStartIndex(null);247      testCase.setTestDataId(null);248      testCase.setIsDataDriven(false);249    }250    testCase.setIsStepGroup(testCaseRequest.getIsStepGroup());251    testCase.setCopiedFrom(parentCase.getId());252    testCase.setPreRequisiteCase(null);253    testCase = create(testCase);254    List<String> tags = tagService.list(TagType.TEST_CASE, parentCase.getId());255    tagService.updateTags(tags, TagType.TEST_CASE, testCase.getId());256    List<TestStep> steps = this.fetchTestSteps(parentCase, testCaseRequest.getStepIds());257    List<TestStep> newSteps = new ArrayList<>();258    Map<Long, TestStep> parentStepIds = new HashMap<Long, TestStep>();259    Integer position = 0;260    TestStep firstStep = steps.get(0);261    if(firstStep.getConditionType() == TestStepConditionType.LOOP_WHILE){262      TestStep whileStep = this.testStepService.find(firstStep.getParentId());263      steps.add(0, whileStep);264    }265    for (TestStep parent : steps) {266      if (testCase.getIsStepGroup() && parent.getStepGroupId() != null)267        continue;268      TestStep step = this.testStepMapper.copy(parent);269      step.setPosition(position);270      step.setCreatedDate(new Timestamp(Calendar.getInstance().getTimeInMillis()));271      step.setTestCaseId(testCase.getId());272      TestStep parentStep = parentStepIds.get(parent.getParentId());273      step.setParentId(parentStep != null ? parentStep.getId() : null);274      TestStep prerequiste = parentStepIds.get(parentStep != null ? parent.getPreRequisiteStepId() : null);275      step.setPreRequisiteStepId(prerequiste != null ? prerequiste.getId() : null);276      step.setId(null);277      step.setParentStep(parentStep);278      step = this.testStepService.create(step);279      parentStepIds.put(parent.getId(), step);280      newSteps.add(step);281      position++;282    }283    return testCase;284  }285  private List<TestStep> fetchTestSteps(TestCase testCase, List<Long> stepIds) {286    if (stepIds != null)287      return this.testStepService.findAllByTestCaseIdAndIdIn(testCase.getId(), stepIds);288    else289      return this.testStepService.findAllByTestCaseId(testCase.getId());290  }291  public void publishEvent(TestCase testCase, EventType eventType) {292    TestCaseEvent<TestCase> event = createEvent(testCase, eventType);293    log.info("Publishing event - " + event.toString());294    applicationEventPublisher.publishEvent(event);295  }296  public TestCaseEvent<TestCase> createEvent(TestCase testCase, EventType eventType) {297    TestCaseEvent<TestCase> event = new TestCaseEvent<>();298    event.setEventData(testCase);299    event.setEventType(eventType);300    return event;301  }302  public void export(BackupDTO backupDTO) throws IOException, ResourceNotFoundException {303    if (!backupDTO.getIsTestCaseEnabled()) return;304    log.debug("backup process for testcase initiated");305    writeXML("testcases", backupDTO, PageRequest.of(0, 25));306    log.debug("backup process for testcase completed");307  }308  public Specification<TestCase> getExportXmlSpecification(BackupDTO backupDTO) throws ResourceNotFoundException {309    boolean hasFilter = backupDTO.getFilterId() != null && backupDTO.getFilterId() > 0;310    if (hasFilter) return specificationBuilder(backupDTO);311    SearchCriteria criteria = new SearchCriteria("workspaceVersionId", SearchOperation.EQUALITY, backupDTO.getWorkspaceVersionId());312    List<SearchCriteria> params = new ArrayList<>();313    params.add(criteria);314    TestCaseSpecificationsBuilder testCaseSpecificationsBuilder = new TestCaseSpecificationsBuilder();315    testCaseSpecificationsBuilder.params = params;316    return testCaseSpecificationsBuilder.build();317  }318  private Specification<TestCase> specificationBuilder(BackupDTO backupDTO) throws ResourceNotFoundException {319    ListFilter filter;320    try {321      filter = testCaseFilterService.find(backupDTO.getFilterId());322    } catch (ResourceNotFoundException e) {323      filter = stepGroupFilterService.find(backupDTO.getFilterId());324    }325    WorkspaceVersion version = workspaceVersionService.find(backupDTO.getWorkspaceVersionId());326    TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();327    return builder.build(filter, version);328  }329  @Override330  protected List<TestCaseXMLDTO> mapToXMLDTOList(List<TestCase> list) {331    return mapper.mapTestcases(list);332  }333}...Source:TestCasesController.java  
...15import com.testsigma.exception.TestsigmaException;16import com.testsigma.mapper.TestCaseMapper;17import com.testsigma.model.*;18import com.testsigma.service.*;19import com.testsigma.specification.TestCaseSpecificationsBuilder;20import com.testsigma.util.HttpClient;21import com.testsigma.web.request.TestCaseCopyRequest;22import com.testsigma.web.request.TestCaseRequest;23import lombok.RequiredArgsConstructor;24import lombok.extern.log4j.Log4j2;25import org.apache.commons.lang3.StringUtils;26import org.springframework.beans.factory.annotation.Autowired;27import org.springframework.data.domain.Page;28import org.springframework.data.domain.PageImpl;29import org.springframework.data.domain.PageRequest;30import org.springframework.data.domain.Pageable;31import org.springframework.data.jpa.domain.Specification;32import org.springframework.data.web.PageableDefault;33import org.springframework.http.HttpStatus;34import org.springframework.http.ResponseEntity;35import org.springframework.web.bind.annotation.*;36import javax.validation.Valid;37import java.net.HttpURLConnection;38import java.net.URL;39import java.sql.SQLException;40import java.util.ArrayList;41import java.util.List;42import java.util.Map;43import java.util.stream.Collectors;44@Log4j245@RestController46@RequestMapping(value = "/test_cases")47@RequiredArgsConstructor(onConstructor = @__(@Autowired))48public class TestCasesController {49  private final TestCaseService testCaseService;50  private final TestStepService testStepService;51  private final NaturalTextActionsService templateService;52  private final TestCaseMapper testCaseMapper;53  private final TagService tagService;54  private final AttachmentService attachmentService;55  private final TestCaseFilterService testCaseFilterService;56  private final WorkspaceVersionService versionService;57  private final StepGroupFilterService stepGroupFilterService;58  private final HttpClient httpClient;59  @RequestMapping(path = "/filter/{filterId}", method = RequestMethod.GET)60  public Page<TestCaseDTO> filter(@PathVariable("filterId") Long filterId, @RequestParam("versionId") Long versionId, Pageable pageable) throws ResourceNotFoundException {61    log.debug("GET /test_cases/filter/" + filterId);62    Specification<TestCase> spec = specificationBuilder(filterId, versionId);63    Page<TestCase> testCases = testCaseService.findAll(spec, pageable);64    List<TestCaseDTO> testCaseDTOS = testCaseMapper.mapDTOs(testCases.getContent());65    return new PageImpl<>(testCaseDTOS, pageable, testCases.getTotalElements());66  }67  @RequestMapping(method = RequestMethod.GET)68  public Page<TestCaseDTO> index(TestCaseSpecificationsBuilder builder,69                                 @PageableDefault(value = 25, page = 0) Pageable pageable) {70    log.debug("GET /test_cases");71    Specification<TestCase> spec = builder.build();72    Page<TestCase> testCases = testCaseService.findAll(spec, pageable);73    List<TestCaseDTO> testCaseDTOS = testCaseMapper.mapDTOs(testCases.getContent());74    return new PageImpl<>(testCaseDTOS, pageable, testCases.getTotalElements());75  }76  @RequestMapping(method = RequestMethod.POST)77  public TestCaseDTO create(@RequestBody @Valid TestCaseRequest testCaseRequest) throws TestsigmaException, SQLException {78    log.debug("POST /test_cases with request:" + testCaseRequest);79    TestCase testCase = testCaseService.create(testCaseRequest);80    return testCaseMapper.mapDTO(testCase);81  }82  @PostMapping(path = "/copy")83  public TestCaseDTO copy(@RequestBody @Valid TestCaseCopyRequest testCaseRequest) throws TestsigmaException, SQLException {84    log.debug("POST /test_cases/copy with request:" + testCaseRequest);85    TestCase testCase = testCaseService.copy(testCaseRequest);86    return testCaseMapper.mapDTO(testCase);87  }88  @RequestMapping(value = "/{id}", method = RequestMethod.GET)89  public TestCaseDTO show(@PathVariable("id") Long id) throws TestsigmaException {90    TestCase testCase = testCaseService.find(id);91    TestCaseDTO testCaseDTO = testCaseMapper.mapTo(testCase);92    testCaseDTO.setTags(tagService.list(TagType.TEST_CASE, id));93    testCaseDTO.setFiles(attachmentService.findAllByEntityIdAndEntity(id,94      TestCase.class.getName(), PageRequest.of(0, 10)));95    return testCaseDTO;96  }97  @RequestMapping(value = "/{id}", method = RequestMethod.PUT)98  @ResponseBody99  public TestCaseDTO update(@PathVariable("id") Long id,100                            @RequestBody TestCaseRequest testCase) throws TestsigmaException, SQLException, CloneNotSupportedException {101    log.debug("PUT /test_cases/" + id + "  with request:" + testCase);102    TestCase testcase = testCaseService.update(testCase, id);103    return testCaseMapper.mapDTO(testcase);104  }105  @DeleteMapping(value = "/{id}/mark_as_delete")106  public ResponseEntity<String> markAsDelete(@PathVariable("id") Long id) throws ResourceNotFoundException {107    log.debug("DELETE /test_cases/mark_as_delete  with request:" + id);108    Long testCaseCountByPreRequisite = testCaseService.testCaseCountByPreRequisite(id);109    if(testCaseCountByPreRequisite==0){110      TestCase testCase = testCaseService.find(id);111      testCase.setDeleted(true);112      testCase.setIsActive(null);113      testCaseService.update(testCase);114      return new ResponseEntity<>("", HttpStatus.OK);115    }116    else{117      return new ResponseEntity<>("Can't Delete Test Case, Used as PreRequisite", HttpStatus.BAD_REQUEST);118    }119  }120  @RequestMapping(value = {"/mark_as_delete"}, method = RequestMethod.DELETE)121  public ResponseEntity<String> bulkMarkAsDelete(@RequestBody(required = false) Map<String, List<Long>> deleteList, @RequestParam(required = false) List<Long> ids) {122    log.debug("DELETE /test_cases/mark_as_delete  with request:" + deleteList);123    List<Long> validIds = new ArrayList<>();124    if (deleteList != null) {125        ids = deleteList.get("ids");126    }127    for(Long id:ids){128      List<Long> preRequisteIds = testCaseService.getTestCaseIdsByPreRequisite(id);129      if(preRequisteIds.size()==0){130        if(!validIds.contains(id)) {131          validIds.add(id);132        }133      }else{134        if(ids.containsAll(preRequisteIds)){135          for(Long pid: preRequisteIds) {136            if (!validIds.contains(pid) && testCaseService.testCaseCountByPreRequisite(pid)==0) {137              validIds.add(pid);138            }139          }140          if(!validIds.contains(id)) {141            validIds.add(id);142          }143        }144      }145    }146    testCaseService.markAsDelete(validIds);147    if(validIds.size()!= ids.size()){148      return new ResponseEntity<>("Select List contains PreRequisite Test cases", HttpStatus.BAD_REQUEST);149    }150    return new ResponseEntity<>("", HttpStatus.OK);151  }152  @RequestMapping(value = {"/restore_delete/{id}"}, method = RequestMethod.PUT)153  public void restore(@PathVariable(value = "id") Long testCaseId) {154    testCaseService.restore(testCaseId);155  }156  @RequestMapping(value = {"/{id}/restore"}, method = RequestMethod.PUT)157  public void restoreNewUI(@PathVariable(value = "id") Long testCaseId) {158    testCaseService.restore(testCaseId);159  }160  @RequestMapping(value = "/{id}", method = RequestMethod.DELETE)161  public void destroy(@PathVariable("id") Long id) throws ResourceNotFoundException {162    testCaseService.destroy(id);163  }164  @GetMapping(value = {"/coverage_summary"})165  public TestCaseCoverageSummaryDTO coverageSummary(@RequestParam("versionId") Long versionId) {166    TestCaseCoverageSummaryDTO summary = new TestCaseCoverageSummaryDTO();167    summary.setAutomatedCount(testCaseService.automatedCountByVersion(versionId));168    return summary;169  }170  @GetMapping(value = {"/break_up_by_status"})171  public List<TestCaseStatusBreakUpDTO> breakUpByStatus(@RequestParam("versionId") Long versionId) {172    return this.testCaseService.breakUpByStatus(versionId);173  }174  @GetMapping(value = {"/break_up_by_type"})175  public List<TestCaseTypeBreakUpDTO> breakUpByType(@RequestParam("versionId") Long versionId) {176    return this.testCaseService.breakUpByType(versionId);177  }178  @RequestMapping(value = "/test_data/{id}", method = RequestMethod.GET)179  public @ResponseBody180  Page<TestCaseDTO> findAllByTestData(@PathVariable(value = "id") Long testDataId,181                                      @PageableDefault(value = 10, page = 0) Pageable pageable) {182    Page<TestCase> testCases = testCaseService.findAllByTestDataId(testDataId, pageable);183    List<TestCaseDTO> dtos = testCaseMapper.mapDTOs(testCases.getContent());184    return new PageImpl<>(dtos, pageable, dtos.size());185  }186  @RequestMapping(value = "/pre_requisite/{id}", method = RequestMethod.GET)187  public @ResponseBody188  Page<TestCaseDTO> findAllByPreRequisite(@PathVariable(value = "id") Long prerequisite,189                                          @PageableDefault(value = 10, page = 0) Pageable pageable) {190    Page<TestCase> testCases = testCaseService.findAllByPreRequisite(prerequisite, pageable);191    List<TestCaseDTO> dtos = testCaseMapper.mapDTOs(testCases.getContent());192    return new PageImpl<>(dtos, pageable, dtos.size());193  }194  private Specification<TestCase> specificationBuilder(Long filterId, Long versionId) throws ResourceNotFoundException {195    ListFilter filter;196    try {197      filter = testCaseFilterService.find(filterId);198    } catch (ResourceNotFoundException e) {199      filter = stepGroupFilterService.find(filterId);200    }201    WorkspaceVersion version = versionService.find(versionId);202    TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();203    return builder.build(filter, version);204  }205  @GetMapping(value = "/validateUrls/{id}")206  public @ResponseBody207  ArrayList<String> findAllEmptyElementsByTestCaseId(@PathVariable(value = "id") Long id,208                                                     @RequestParam(value = "currentUrl", required = false) String currentUrl) throws Exception {209    List<TestStep> testSteps = testStepService.findAllByTestCaseIdAndNaturalTextActionIds(210      id,211      templateService.findByDisplayName("navigateTo")212        .stream().map(NaturalTextActions::getId).map(Long::intValue).collect(Collectors.toList())213    );214    ArrayList<String> invalidUrlList = new ArrayList<>();215    ArrayList<String> urls = new ArrayList<>();216    if (!StringUtils.isEmpty(currentUrl)) {...Source:TestCaseSpecificationsBuilder.java  
...3import com.testsigma.model.*;4import org.springframework.data.jpa.domain.Specification;5import java.util.ArrayList;6import java.util.List;7public class TestCaseSpecificationsBuilder extends BaseSpecificationsBuilder {8  public TestCaseSpecificationsBuilder() {9    super(new ArrayList<>());10  }11  public Specification<TestCase> build() {12    if (params.size() == 0) {13      return null;14    }15    Specification result = new TestCaseSpecification(params.get(0));16    for (int i = 1; i < params.size(); i++) {17      result = Specification.where(result).and(new TestCaseSpecification(params.get(i)));18    }19    return result;20  }21  public Specification<TestCase> build(ListFilter filter, WorkspaceVersion version) {22    if (filter.getSearchCriteria().size() == 0) {...TestCaseSpecificationsBuilder
Using AI Code Generation
1import com.testsigma.specification.TestCaseSpecificationsBuilder;2import com.testsigma.specification.TestCaseSpecifications;3import org.testng.annotations.Test;4import org.testng.annotations.BeforeClass;5import org.testng.annotations.AfterClass;6import org.testng.annotations.BeforeTest;7import org.testng.annotations.AfterTest;8import org.testng.annotations.BeforeSuite;9import org.testng.annotations.AfterSuite;10public class NewTest {11  public void f() {12    TestCaseSpecificationsBuilder testCaseSpecificationsBuilder = new TestCaseSpecificationsBuilder();13    TestCaseSpecifications specifications = testCaseSpecificationsBuilder.setTestCaseName("TestCaseName").setTestCaseDescription("TestCaseDescription").setTestCaseAuthor("TestCaseAuthor").build();14  }15  public void beforeClass() {16  }17  public void afterClass() {18  }19  public void beforeTest() {20  }21  public void afterTest() {22  }23  public void beforeSuite() {24  }25  public void afterSuite() {26  }27}TestCaseSpecificationsBuilder
Using AI Code Generation
1import com.testsigma.specification.TestCaseSpecificationsBuilder;2import com.testsigma.specification.TestCaseSpecifications;3import com.testsigma.specification.TestCaseSpecifications.TestCaseSpecification;4import com.testsigma.specification.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationBuilder;5import com.testsigma.specification.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationBuilder.TestCaseSpecificationBuilderStep;6import com.testsigma.specification.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationBuilder.TestCaseSpecificationBuilderStep.TestCaseSpecificationBuilderStepAction;7import com.testsigma.specification.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationBuilder.TestCaseSpecificationBuilderStep.TestCaseSpecificationBuilderStepAction.TestCaseSpecificationBuilderStepActionAssertion;8import com.testsigma.specification.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationBuilder.TestCaseSpecificationBuilderStep.TestCaseSpecificationBuilderStepAction.TestCaseSpecificationBuilderStepActionAssertion.TestCaseSpecificationBuilderStepActionAssertionBuilder;9import com.testsigma.specification.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationBuilder.TestCaseSpecificationBuilderStep.TestCaseSpecificationBuilderStepAction.TestCaseSpecificationBuilderStepActionAssertion.TestCaseSpecificationBuilderStepActionAssertionBuilder.TestCaseSpecificationBuilderStepActionAssertionBuilderStep;10{11    public static void main(String[] args)12    {13        TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();14            .addSpecification(15                new TestCaseSpecificationBuilder()16                    .withId("TC1")17                    .withName("Verify Login")18                    .addStep(19                        new TestCaseSpecificationBuilderStep()20                            .withOrder(1)21                            .withAction(22                                new TestCaseSpecificationBuilderStepAction()23                                    .withName("Login")24                                    .withInput("username", "testuser")25                                    .withInput("password", "testpassword")26                                    .withAssertion(27                                        new TestCaseSpecificationBuilderStepActionAssertionBuilder()28                                            .withName("Login successful")29                                            .withActual("true")30                                            .withExpected("true")31                                            .withAssertionType("Equals")32                                            .build()33                    .build()34            .addSpecification(35                new TestCaseSpecificationBuilder()36                    .withId("TC2")37                    .withName("Verify Logout")38                    .addStep(39                        new TestCaseSpecificationBuilderStep()40                            .withOrder(1)41                            .withAction(42                                new TestCaseSpecificationBuilderStepAction()43                                    .withName("Logout")44                                    .withInput("username", "testuser")45                                    .withInput("password", "testpassword")46                                    .withAssertion(47                                        new TestCaseSpecificationBuilderStepActionAssertionBuilder()48                                            .withName("Logout successful")49                                            .withActual("true")50                                            .withExpected("TestCaseSpecificationsBuilder
Using AI Code Generation
1import com.testsigma.specification.TestCaseSpecificationsBuilder;2import com.testsigma.specification.TestCaseSpecifications;3import com.testsigma.specification.TestCaseSpecification;4import com.testsigma.specification.TestCaseSpecificationType;5import com.testsigma.specification.TestCaseSpecificationResult;6import com.testsigma.specification.TestCaseSpecificationResultType;7public class TestSpecificationsBuilder {8    TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();9    TestCaseSpecifications specifications = builder.build();10    TestCaseSpecification specification = specifications.getSpecification("TC001");11    TestCaseSpecificationResult result = specification.getSpecificationResult(TestCaseSpecificationType.DESIGN);12    TestCaseSpecificationResultType resultType = result.getResultType();13    String resultTypeValue = resultType.getValue();14    String resultTypeName = resultType.getName();15    String resultTypeDescription = resultType.getDescription();16    String resultTypeId = resultType.getId();17}18public class TestCaseSpecificationResult {19    private TestCaseSpecificationResultType resultType;20    private String resultValue;21    public TestCaseSpecificationResultType getResultType() {22        return resultType;23    }24    public void setResultType(TestCaseSpecificationResultType resultType) {25        this.resultType = resultType;26    }27    public String getResultValue() {28        return resultValue;29    }30    public void setResultValue(String resultValue) {31        this.resultValue = resultValue;32    }33}34public class TestCaseSpecificationResultType {35    private String id;36    private String name;37    private String value;38    private String description;39    public String getId() {40        return id;41    }TestCaseSpecificationsBuilder
Using AI Code Generation
1package com.testsigma.specification;2import java.util.ArrayList;3import java.util.List;4import java.util.Map;5import java.util.Set;6import java.util.TreeMap;7import java.util.TreeSet;8import java.util.logging.Level;9import java.util.logging.Logger;10import org.testng.annotations.Test;11import com.testsigma.specification.TestCaseSpecificationsBuilder;12import com.testsigma.specification.TestCaseSpecificationsBuilder.TestCaseSpecifications;13import com.testsigma.specification.TestCaseSpecificationsBuilder.TestCaseSpecifications.TestCaseSpecification;14import com.testsigma.specification.TestCaseSpecificationsBuilder.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationStep;15import com.testsigma.specification.TestCaseSpecificationsBuilder.TestCaseSpecifications.TestCaseSpecification.TestCaseSpecificationStep.TestCaseSpecificationStepType;16public class TestCaseSpecificationsBuilderTest {17	public void test() {18		TestCaseSpecificationsBuilder builder = new TestCaseSpecificationsBuilder();19		TestCaseSpecifications specifications = builder.getSpecifications();20		TestCaseSpecification specification = specifications.getSpecification("Specification1");21		specification.addStep("Step1", TestCaseSpecificationStepType.GIVEN);22		specification.addStep("Step2", TestCaseSpecificationStepType.WHEN);23		specification.addStep("Step3", TestCaseSpecificationStepType.THEN);24		specification.addStep("Step4", TestCaseSpecificationStepType.WHEN);25		specification.addStep("Step5", TestCaseSpecificationStepType.THEN);26		specification.addStep("Step6", TestCaseSpecificationStepType.THEN);27		specification.addStep("Step7", TestCaseSpecificationStepType.THEN);28		specification.addStep("Step8", TestCaseSpecificationStepType.THEN);29		specification.addStep("Step9", TestCaseSpecificationStepType.THEN);30		specification.addStep("Step10", TestCaseSpecificationStepType.THEN);31		specification.addStep("Step11", TestCaseSpecificationStepType.THEN);32		specification.addStep("Step12", TestCaseSpecificationStepType.THEN);33		specification.addStep("Step13", TestCaseSpecificationStepType.THEN);34		specification.addStep("Step14", TestCaseSpecificationStepType.THEN);35		specification.addStep("Step15", TestCaseSpecificationStepType.THEN);36		specification.addStep("Step16", TestCaseSpecificationStepType.THEN);37		specification.addStep("Step17", TestCaseSpecificationStepType.THEN);38		specification.addStep("Step18", TestCaseSpecificationStepType.THEN);39		specification.addStep("Step19", TestCaseSpecificationStepType.THEN);TestCaseSpecificationsBuilder
Using AI Code Generation
1package com.testsigma.specification;2import java.util.ArrayList;3import java.util.List;4import java.util.Map;5import com.testsigma.specification.TestCaseSpecificationsBuilder;6public class TestCaseSpecificationsBuilderExample {7public static void main(String[] args) {8List<TestCaseSpecifications> testCaseSpecifications = new ArrayList<TestCaseSpecifications>();9testCaseSpecifications.add(new TestCaseSpecifications("Test case 1", "Test case 1 description", "Test case 1 category", "Test case 1 feature"));10testCaseSpecifications.add(new TestCaseSpecifications("Test case 2", "Test case 2 description", "Test case 2 category", "Test case 2 feature"));11testCaseSpecifications.add(new TestCaseSpecifications("Test case 3", "Test case 3 description", "Test case 3 category", "Test case 3 feature"));12TestCaseSpecificationsBuilder testCaseSpecificationsBuilder = new TestCaseSpecificationsBuilder();13Map<String, List<TestCaseSpecifications>> testCaseSpecificationsMap = testCaseSpecificationsBuilder.build(testCaseSpecifications);14System.out.println(testCaseSpecificationsMap);15}16}17{Test case 1 category=[TestCaseSpecifications [testCaseName=Test case 1, testCaseDescription=Test case 1 description, testCaseCategory=Test case 1 category, testCaseFeature=Test case 1 feature], TestCaseSpecifications [testCaseName=Test case 2, testCaseDescription=Test case 2 description, testCaseCategory=Test case 2 category, testCaseFeaTestCaseSpecificationsBuilder
Using AI Code Generation
1import com.testsigma.specification.TestCaseSpecificationsBuilder;2import com.testsigma.specification.Specification;3import com.testsigma.specification.SpecificationBuilder;4import com.testsigma.specification.SpecificationType;5public class TestCaseSpecificationsBuilderExample {6    public static void main(String[] args) {7        SpecificationBuilder specificationBuilder = new SpecificationBuilder();8        specificationBuilder.addSpecification("spec1", SpecificationType.MUST, "This is a must specification");9        specificationBuilder.addSpecification("spec2", SpecificationType.SHOULD, "This is a should specification");10        specificationBuilder.addSpecification("spec3", SpecificationType.CAN, "This is a can specification");11        specificationBuilder.addSpecification("spec4", SpecificationType.CANNOT, "This is a cannot specification");12        specificationBuilder.addSpecification("spec5", SpecificationType.MUST, "This is a must specification");13        specificationBuilder.addSpecification("spec6", SpecificationType.MUST, "This is a must specification");14        specificationBuilder.addSpecification("spec7", SpecificationType.SHOULD, "This is a should specification");15        specificationBuilder.addSpecification("spec8", SpecificationType.SHOULD, "This is a should specification");16        specificationBuilder.addSpecification("spec9", SpecificationType.CAN, "This is a can specification");17        specificationBuilder.addSpecification("spec10", SpecificationType.CAN, "This is a can specification");18        specificationBuilder.addSpecification("spec11", SpecificationType.CANNOT, "This is a cannot specification");19        specificationBuilder.addSpecification("spec12", SpecificationType.CANNOT, "This is a cannot specification");20        specificationBuilder.addSpecification("spec13", SpecificationType.MUST, "This is a must specification");21        specificationBuilder.addSpecification("spec14", SpecificationType.MUST, "This is a must specification");22        specificationBuilder.addSpecification("spec15", SpecificationType.MUST, "This is a must specification");23        specificationBuilder.addSpecification("spec16", SpecificationType.SHOULD, "This is a should specification");24        specificationBuilder.addSpecification("spec17", SpecificationType.SHOULD, "This is a should specification");25        specificationBuilder.addSpecification("spec18", SpecificationType.SHOULD, "This is a should specification");26        specificationBuilder.addSpecification("spec19", SpecificationType.CAN, "This is a can specification");27        specificationBuilder.addSpecification("spec20", SpecificationType.CAN, "This is a can specification");28        specificationBuilder.addSpecification("TestCaseSpecificationsBuilder
Using AI Code Generation
1import com.testsigma.specification.TestCaseSpecificationsBuilder;2import com.testsigma.specification.TestCaseSpecificationsBuilder.TestCaseSpecificationsBuilderException;3import com.testsigma.specification.TestCaseSpecificationsBuilder.TestCaseSpecificationsBuilderException.Reason;4{5	public static void main(String[] args)6	{7		TestCaseSpecificationsBuilder testCaseSpecificationsBuilder = new TestCaseSpecificationsBuilder();8		testCaseSpecificationsBuilder.setTestCaseName("Test Case 1");9		testCaseSpecificationsBuilder.setTestCaseDescription("Test Case 1 Description");10		testCaseSpecificationsBuilder.setTestCaseAuthor("Test Case 1 Author");11		testCaseSpecificationsBuilder.setTestCaseCreationDate("Test Case 1 Creation Date");12		testCaseSpecificationsBuilder.setTestCaseLastModifiedDate("Test Case 1 Last Modified Date");13		testCaseSpecificationsBuilder.setTestCaseLastModifiedBy("Test Case 1 Last Modified By");14		testCaseSpecificationsBuilder.setTestCasePreCondition("Test Case 1 Pre Condition");15		testCaseSpecificationsBuilder.setTestCasePostCondition("Test Case 1 Post Condition");16		testCaseSpecificationsBuilder.setTestCaseVersion("Test Case 1 Version");17		testCaseSpecificationsBuilder.setTestCaseTestStep("Test Case 1 Test Step");18		testCaseSpecificationsBuilder.setTestCaseExpectedResult("Test Case 1 Expected Result");19		testCaseSpecificationsBuilder.setTestCasePriority("Test Case 1 Priority");20		testCaseSpecificationsBuilder.setTestCaseStatus("Test Case 1 Status");21		testCaseSpecificationsBuilder.setTestCaseTags(new String[]{"Test Case 1 Tag 1", "Test Case 1 Tag 2"});22		testCaseSpecificationsBuilder.setTestCaseId("Test Case 1 Id");23		testCaseSpecificationsBuilder.setTestCaseTestSuiteName("Test Case 1 Test Suite Name");24		testCaseSpecificationsBuilder.setTestCaseTestSuiteId("Test Case 1 Test Suite Id");25		testCaseSpecificationsBuilder.setTestCaseTestSuitePath("Test Case 1 Test Suite Path");26		testCaseSpecificationsBuilder.setTestCaseTestSuiteDescription("Test Case 1 Test Suite Description");27		testCaseSpecificationsBuilder.setTestCaseTestSuiteAuthor("Test Case 1 Test Suite Author");28		testCaseSpecificationsBuilder.setTestCaseTestSuiteCreationDate("Test Case 1 Test Suite Creation Date");29		testCaseSpecificationsBuilder.setTestCaseTestSuiteLastModifiedDate("Test Case 1 Test Suite Last Modified Date");30		testCaseSpecificationsBuilder.setTestCaseTestSuiteLastModifiedBy("Test Case 1 Test Suite Last Modified By");31		testCaseSpecificationsBuilder.setTestCaseTestSuiteVersion("TestCaseSpecificationsBuilder
Using AI Code Generation
1import com.testsigma.specification.TestCaseSpecificationsBuilder;2import com.testsigma.specification.TestSpecification;3public class 2 {4    public void test2() {5        TestSpecification specification = new TestCaseSpecificationsBuilder().withName("test2").withDescription("This is a test case").build();6    }7}8import com.testsigma.specification.TestCaseSpecificationsBuilder;9import com.testsigma.specification.TestSpecification;10public class 3 {11    public void test3() {12        TestSpecification specification = new TestCaseSpecificationsBuilder().withName("test3").withDescription("This is a test case").build();13    }14}15import com.testsigma.specification.TestCaseSpecificationsBuilder;16import com.testsigma.specification.TestSpecification;17public class 4 {18    public void test4() {19        TestSpecification specification = new TestCaseSpecificationsBuilder().withName("test4").withDescription("This is a test case").build();20    }21}22import com.testsigma.specification.TestCaseSpecificationsBuilder;23import com.testsigma.specification.TestSpecification;24public class 5 {25    public void test5() {26        TestSpecification specification = new TestCaseSpecificationsBuilder().withName("test5").withDescription("This is a test case").build();27    }28}29import com.testsigma.specification.TestCaseSpecificationsBuilder;30import com.testsigma.specification.TestSpecification;31public class 6 {32    public void test6() {33        TestSpecification specification = new TestCaseSpecificationsBuilder().withName("test6").withDescription("This is a test case").build();34    }35}36import com.testsigma.specification.TestCaseSpecificationsBuilder;37import com.testsigma.specification.TestSpecification;38public class 7 {TestCaseSpecificationsBuilder
Using AI Code Generation
1package com.testsigma.specification;2import org.testng.annotations.Test;3public class TestSpecificationBuilder {4	public void test1() {5		TestCaseSpecificationsBuilder.buildSpecification("Test Specification Builder", "test1", "test1", "test1");6	}7	public void test2() {8		TestCaseSpecificationsBuilder.buildSpecification("Test Specification Builder", "test2", "test2", "test2");9	}10}11package com.testsigma.specification;12import org.testng.annotations.Test;13public class TestSpecificationBuilder {14	public void test1() {15		TestCaseSpecificationsBuilder.buildSpecification("Test Specification Builder", "test1", "test1", "test1");16	}17	public void test2() {18		TestCaseSpecificationsBuilder.buildSpecification("Test Specification Builder", "test2", "test2", "test2");19	}20}21package com.testsigma.specification;22import org.testng.annotations.Test;23public class TestSpecificationBuilder {24	public void test1() {25		TestCaseSpecificationsBuilder.buildSpecification("Test Specification Builder", "test1", "test1", "test1");26	}27	public void test2() {28		TestCaseSpecificationsBuilder.buildSpecification("Test Specification Builder", "test2", "test2", "test2");29	}30}31package com.testsigma.specification;32import org.testng.annotations.Test;33public class TestSpecificationBuilder {34	public void test1() {35		TestCaseSpecificationsBuilder.buildSpecification("Test Specification Builder", "test1", "test1", "test1");36	}37	public void test2() {TestCaseSpecificationsBuilder
Using AI Code Generation
1import com.testsigma.specification.TestCaseSpecificationsBuilder;2import com.testsigma.specification.TestCaseSpecifications;3import com.testsigma.specification.TestCaseSpecification;4import com.testsigma.specification.TestCaseSpecificationsWriter;5{6    public void test1()7    {8    }9    public void test2()10    {11    }12    public void test3()13    {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!!
