提交 8e396d71 authored 作者: mry's avatar mry

feat(web): 测试用例集的基本操作

上级 24b2d914
...@@ -32,5 +32,6 @@ public class TestCaseCollection extends BaseEntity { ...@@ -32,5 +32,6 @@ public class TestCaseCollection extends BaseEntity {
private Long projectId; private Long projectId;
@ApiModelProperty("测试用例集合(所有测试用例的主键id)") @ApiModelProperty("测试用例集合(所有测试用例的主键id)")
private List<Long> testCaseIds; private List<Long> testCaseCollection;
} }
...@@ -10,11 +10,7 @@ import org.matrix.vo.TestCaseCollectionGroupingVo; ...@@ -10,11 +10,7 @@ import org.matrix.vo.TestCaseCollectionGroupingVo;
*/ */
public interface ITestCaseCollectionGroupingService extends IService<TestCaseCollectionGrouping> { public interface ITestCaseCollectionGroupingService extends IService<TestCaseCollectionGrouping> {
/**
* 查询测试用例集分组与分组下的分组
*
* @return 测试用例集分组与分组下的分组
*/
/** /**
* 查询测试用例集分组与分组下的分组 * 查询测试用例集分组与分组下的分组
* *
...@@ -28,6 +24,6 @@ public interface ITestCaseCollectionGroupingService extends IService<TestCaseCol ...@@ -28,6 +24,6 @@ public interface ITestCaseCollectionGroupingService extends IService<TestCaseCol
* *
* @param id 主键id * @param id 主键id
*/ */
void delete(Long id); void deleteById(Long id);
} }
...@@ -62,20 +62,20 @@ public class TestCaseCollectionGroupingServiceImpl extends ServiceImpl<TestCaseC ...@@ -62,20 +62,20 @@ public class TestCaseCollectionGroupingServiceImpl extends ServiceImpl<TestCaseC
} }
@Override @Override
public void delete(Long id) { public void deleteById(Long id) {
List<Long> list = new ArrayList<>(); List<Long> list = new ArrayList<>();
List<Long> groupIds = getGroupIds(id,list); List<Long> groupIds = getGroupIds(id, list);
mapper.deleteBatchIds(groupIds); mapper.deleteBatchIds(groupIds);
mapper.deleteById(id); mapper.deleteById(id);
} }
public List<Long> getGroupIds(Long id,List<Long> list) { public List<Long> getGroupIds(Long id, List<Long> list) {
List<TestCaseCollectionGrouping> testCaseCollectionGroupings = Optional.ofNullable(mapper.selectList(Wrappers.lambdaQuery(TestCaseCollectionGrouping.class) List<TestCaseCollectionGrouping> testCaseCollectionGroupings = Optional.ofNullable(mapper.selectList(Wrappers.lambdaQuery(TestCaseCollectionGrouping.class)
.eq(TestCaseCollectionGrouping::getGroupId, id))).orElse(new ArrayList<>()); .eq(TestCaseCollectionGrouping::getGroupId, id))).orElse(new ArrayList<>());
if (!CollectionUtils.isEmpty(testCaseCollectionGroupings)) { if (!CollectionUtils.isEmpty(testCaseCollectionGroupings)) {
for (TestCaseCollectionGrouping testCaseCollectionGrouping : testCaseCollectionGroupings) { for (TestCaseCollectionGrouping testCaseCollectionGrouping : testCaseCollectionGroupings) {
list.add(testCaseCollectionGrouping.getId()); list.add(testCaseCollectionGrouping.getId());
getGroupIds(testCaseCollectionGrouping.getId(),list); getGroupIds(testCaseCollectionGrouping.getId(), list);
} }
} }
return list; return list;
......
package org.matrix.autotest.controller; package org.matrix.autotest.controller;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api; import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiOperation;
import org.matrix.entity.Case;
import org.matrix.entity.TestCaseCollection; import org.matrix.entity.TestCaseCollection;
import org.matrix.exception.GlobalException; import org.matrix.exception.GlobalException;
import org.matrix.service.ICaseService;
import org.matrix.service.ITestCaseCollectionService; import org.matrix.service.ITestCaseCollectionService;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus; import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional; import java.util.Optional;
/** /**
...@@ -23,12 +28,15 @@ import java.util.Optional; ...@@ -23,12 +28,15 @@ import java.util.Optional;
public class TestCaseCollectionController { public class TestCaseCollectionController {
@Autowired @Autowired
private ITestCaseCollectionService testCaseGroupingService; private ITestCaseCollectionService testCaseCollectionService;
@Autowired
private ICaseService caseService;
@ApiOperation("添加测试用例集") @ApiOperation("添加测试用例集")
@PostMapping @PostMapping
public ResponseEntity<TestCaseCollection> insertTestCaseGrouping(@RequestBody TestCaseCollection testCaseCollection) { public ResponseEntity<TestCaseCollection> insertTestCaseGrouping(@RequestBody TestCaseCollection testCaseCollection) {
return Optional.of(testCaseGroupingService.save(testCaseCollection)).orElseThrow(() -> new GlobalException("添加失败")) return Optional.of(testCaseCollectionService.save(testCaseCollection)).orElseThrow(() -> new GlobalException("添加失败"))
? ResponseEntity.ok(testCaseCollection) ? ResponseEntity.ok(testCaseCollection)
: ResponseEntity.status(HttpStatus.BAD_REQUEST).body(testCaseCollection); : ResponseEntity.status(HttpStatus.BAD_REQUEST).body(testCaseCollection);
} }
...@@ -36,7 +44,7 @@ public class TestCaseCollectionController { ...@@ -36,7 +44,7 @@ public class TestCaseCollectionController {
@ApiOperation("修改测试用例集") @ApiOperation("修改测试用例集")
@PutMapping @PutMapping
public ResponseEntity<TestCaseCollection> updateTestCaseGrouping(@RequestBody TestCaseCollection testCaseCollection) { public ResponseEntity<TestCaseCollection> updateTestCaseGrouping(@RequestBody TestCaseCollection testCaseCollection) {
return Optional.of(testCaseGroupingService.updateById(testCaseCollection)).orElseThrow(() -> new GlobalException("修改失败")) return Optional.of(testCaseCollectionService.updateById(testCaseCollection)).orElseThrow(() -> new GlobalException("修改失败"))
? ResponseEntity.ok(testCaseCollection) ? ResponseEntity.ok(testCaseCollection)
: ResponseEntity.status(HttpStatus.BAD_REQUEST).body(testCaseCollection); : ResponseEntity.status(HttpStatus.BAD_REQUEST).body(testCaseCollection);
} }
...@@ -44,8 +52,46 @@ public class TestCaseCollectionController { ...@@ -44,8 +52,46 @@ public class TestCaseCollectionController {
@ApiOperation("删除测试用例集") @ApiOperation("删除测试用例集")
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
public ResponseEntity<String> removeTestCaseGrouping(@PathVariable Long id) { public ResponseEntity<String> removeTestCaseGrouping(@PathVariable Long id) {
testCaseGroupingService.removeById(id); testCaseCollectionService.removeById(id);
return ResponseEntity.ok(String.format("删除的用例分组id为,%s", id)); return ResponseEntity.ok(String.format("删除的用例分组id为,%s", id));
} }
@GetMapping
@ApiOperation("查询所有测试用例集")
public ResponseEntity<List<TestCaseCollection>> findTestCaseGrouping(@RequestParam Long projectId) {
List<TestCaseCollection> testCaseCollections = Optional.ofNullable(testCaseCollectionService.list(Wrappers.lambdaQuery(TestCaseCollection.class)
.eq(TestCaseCollection::getProjectId, projectId))).orElse(new ArrayList<>());
return ResponseEntity.ok(testCaseCollections);
}
@GetMapping("/id")
@ApiOperation("根据id查询测试用例集")
public ResponseEntity<TestCaseCollection> findById(@RequestParam Long id) {
TestCaseCollection testCaseCollection = Optional.ofNullable(testCaseCollectionService.getById(id)).orElse(new TestCaseCollection());
return ResponseEntity.ok(testCaseCollection);
}
@GetMapping("/groupId")
@ApiOperation("根据分组id查询测试用例集")
public ResponseEntity<List<TestCaseCollection>> findByGroupId(@RequestParam Long projectId, @RequestParam Long groupId) {
List<TestCaseCollection> testCaseCollections = Optional.ofNullable(testCaseCollectionService.list(Wrappers.lambdaQuery(TestCaseCollection.class)
.eq(TestCaseCollection::getProjectId, projectId)
.eq(TestCaseCollection::getGroupId, groupId))).orElse(new ArrayList<>());
return ResponseEntity.ok(testCaseCollections);
}
@GetMapping("/testCase")
@ApiOperation("查询当前测试用例集中的所有测试用例")
public ResponseEntity<List<Case>> findTestCase(@RequestParam Long id) {
//存放测试用例的集合
List<Case> list = new ArrayList<>();
TestCaseCollection testCaseCollection = Optional.ofNullable(testCaseCollectionService.getById(id)).orElse(new TestCaseCollection());
List<Long> idList = testCaseCollection.getTestCaseCollection();
for (Long caseId : idList) {
Case testCase = caseService.getById(caseId);
list.add(testCase);
}
return ResponseEntity.ok(list);
}
} }
...@@ -54,7 +54,7 @@ public class TestCaseCollectionGroupingController { ...@@ -54,7 +54,7 @@ public class TestCaseCollectionGroupingController {
@DeleteMapping("/{id}") @DeleteMapping("/{id}")
@ApiOperation("根据分组主键id删除分组,以及分组下的所有分组") @ApiOperation("根据分组主键id删除分组,以及分组下的所有分组")
public ResponseEntity<String> remove(@PathVariable Long id) { public ResponseEntity<String> remove(@PathVariable Long id) {
service.delete(id); service.deleteById(id);
return ResponseEntity.ok(String.format("删除的测试用例集分组id为%s", id)); return ResponseEntity.ok(String.format("删除的测试用例集分组id为%s", id));
} }
} }
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论