Best Testsigma code snippet using com.testsigma.controller.TestCasesController.filter
Source:TestCasesController.java
...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)) {217 if (invalidUrl(currentUrl)) invalidUrlList.add(currentUrl);...
filter
Using AI Code Generation
1public class TestCasesController {2 private final TestCasesRepository testCasesRepository;3 public TestCasesController(TestCasesRepository testCasesRepository) {4 this.testCasesRepository = testCasesRepository;5 }6 public List<TestCase> getAllTestCases() {7 return testCasesRepository.findAll();8 }9 @GetMapping("/filter")10 public List<TestCase> filterTestCases(@RequestParam(name = "name", required = false) String name,11 @RequestParam(name = "priority", required = false) String priority,12 @RequestParam(name = "status", required = false) String status) {13 List<TestCase> testCases = testCasesRepository.findAll();14 if (name != null) {15 testCases = testCases.stream().filter(testCase -> testCase.getName().equals(name)).collect(Collectors.toList());16 }17 if (priority != null) {18 testCases = testCases.stream().filter(testCase -> testCase.getPriority().equals(priority)).collect(Collectors.toList());19 }20 if (status != null) {21 testCases = testCases.stream().filter(testCase -> testCase.getStatus().equals(status)).collect(Collectors.toList());22 }23 return testCases;24 }25}26public class TestCasesControllerTest {27 private TestCasesRepository testCasesRepository;28 private MockMvc mockMvc;29 public void shouldGetAllTestCases() throws Exception {30 mockMvc.perform(get("/testcases"))31 .andExpect(status().isOk())32 .andExpect(jsonPath("$", hasSize(3)));33 }34 public void shouldGetFilteredTestCases() throws Exception {35 mockMvc.perform(get("/testcases/filter?name=Test%20case%201"))36 .andExpect(status().isOk())37 .andExpect(jsonPath("$", hasSize(1)))38 .andExpect(jsonPath("$[0].name", is("Test case 1")));39 }40}41public class TestCasesControllerTest {42 private TestCasesRepository testCasesRepository;43 private MockMvc mockMvc;44 public void shouldGetAllTestCases() throws Exception {45 mockMvc.perform(get("/testcases"))46 .andExpect(status().isOk())
filter
Using AI Code Generation
1import com.testsigma.controller.TestCasesController;2import com.testsigma.controller.TestRunsController;3import com.testsigma.controller.UsersController;4import com.testsigma.controller.ProjectsController;5import com.testsigma.controller.ApplicationsController;6import com.testsigma.controller.TestCasesController;7import com.testsigma.model.TestCase;8import com.testsigma.model.TestRun;9import com.testsigma.model.User;10import com.testsigma.model.Project;11import com.testsigma.model.Application;12import com.testsigma.model.TestCase;13import com.testsigma.util.TestSigmaUtil;14import java.util.ArrayList;15import jav
filter
Using AI Code Generation
1import com.testsigma.controller.TestCasesController2import com.testsigma.model.TestCase3def testCases = TestCasesController.filter(4testCases.each { TestCase testCase ->5}6println testCases.size()
filter
Using AI Code Generation
1 def testcases = new com.testsigma.controller.TestCasesController().filter(2 assert testcases.size() > 03 assert testcases.get(0).name != null4 assert testcases.get(0).name.size() > 05 assert testcases.get(0).id != null6 assert testcases.get(0).id.size() > 07 assert testcases.get(0).milestone != null8 assert testcases.get(0).milestone.size() > 09 assert testcases.get(0).priority != null10 assert testcases.get(0).priority.size() > 011 assert testcases.get(0).status != null12 assert testcases.get(0).status.size() > 013 assert testcases.get(0).type != null14 assert testcases.get(0).type.size() > 015 assert testcases.get(0).assigned_to != null16 assert testcases.get(0).assigned_to.size() > 017 assert testcases.get(0).category != null18 assert testcases.get(0).category.size() > 019 assert testcases.get(0).suite != null20 assert testcases.get(0).suite.size() > 021 assert testcases.get(0).tag != null22 assert testcases.get(0).tag.size() > 023 assert testcases.get(0).custom_fields != null24 assert testcases.get(0).custom_fields.size() > 025 assert testcases.get(0).preconds != null26 assert testcases.get(0).preconds.size() > 027 assert testcases.get(0).steps != null28 assert testcases.get(0).steps.size
filter
Using AI Code Generation
1import com.testsigma.controller.TestCasesController2import com.testsigma.model.TestCase3import com.testsigma.model.TestCaseFilterCriteria4List<TestCase> testCases = new ArrayList<TestCase>()5TestCaseFilterCriteria filterCriteria = new TestCaseFilterCriteria()6filterCriteria.setProjectId("1")7filterCriteria.setTestSuiteId("1")8testCases = new TestCasesController().filter(filterCriteria)9testCases.each {10 println(it)11}
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!!