APITestController.java 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. package seecoder.devcloud.web.controller.APITest;
  2. import io.swagger.annotations.Api;
  3. import io.swagger.annotations.ApiImplicitParam;
  4. import io.swagger.annotations.ApiOperation;
  5. import org.springframework.beans.factory.annotation.Autowired;
  6. import org.springframework.web.bind.annotation.*;
  7. import seecoder.devcloud.web.model.po.APITest.APITestResult;
  8. import seecoder.devcloud.web.model.vo.APITest.APITestBodyVO;
  9. import seecoder.devcloud.web.model.vo.APITest.APITestInfoVO;
  10. import seecoder.devcloud.web.model.vo.APITest.APITestResultVO;
  11. import seecoder.devcloud.web.model.vo.Response;
  12. import seecoder.devcloud.web.service.APITest.APITestService;
  13. import java.util.List;
  14. /**
  15. * @Author zxr
  16. * @Description 接口测试相关操作
  17. */
  18. @Api(tags = "接口测试 API")
  19. @RestController
  20. @RequestMapping("/test")
  21. public class APITestController {
  22. private final APITestService apiTestService;
  23. @Autowired
  24. public APITestController(APITestService apiTestService) {
  25. this.apiTestService = apiTestService;
  26. }
  27. @PostMapping("/create")
  28. @ApiOperation(value = "创建一个新的测试任务", httpMethod = "POST")
  29. public Response createAPITestMission(@RequestBody APITestBodyVO apiTestBodyVO) {
  30. apiTestService.createAPITest(apiTestBodyVO);
  31. return Response.buildSuccess();
  32. }
  33. @GetMapping("/list/{projectId}")
  34. @ApiOperation(value = "获取指定项目的所有测试任务", httpMethod = "GET")
  35. @ApiImplicitParam(name = "projectId", dataType ="int",paramType = "query")
  36. public Response<List<APITestInfoVO>> getAPITestInfosByProjectId(@PathVariable("projectId") Integer projectId) {
  37. return Response.buildSuccess(apiTestService.getAPITestsByProjectId(projectId));
  38. }
  39. @GetMapping("/delete/{testId}")
  40. @ApiOperation(value = "删除指定测试任务", httpMethod = "DELETE")
  41. @ApiImplicitParam(name = "testId", dataType = "int", paramType = "query")
  42. public Response deleteAPITestInfoByTestId(@PathVariable("testId") Integer testId) {
  43. apiTestService.deleteAPITest(testId);
  44. return Response.buildSuccess();
  45. }
  46. @GetMapping("/execute/{testId}")
  47. @ApiOperation(value = "执行制定测试任务", httpMethod = "GET")
  48. @ApiImplicitParam(name = "testID", dataType = "int", paramType = "query")
  49. public Response executeAPITestByTestId(@PathVariable("testId") Integer testId) throws InterruptedException {
  50. apiTestService.executeAPITest(testId);
  51. return Response.buildSuccess();
  52. }
  53. @GetMapping("/result/{testId}")
  54. @ApiOperation(value = "获取执行测试任务的执行结果列表", httpMethod = "GET")
  55. @ApiImplicitParam(name = "testId", dataType = "int", paramType = "query")
  56. public Response<List<APITestResultVO>> getAPITestResultByTestId(@PathVariable("testId") Integer testId) {
  57. return Response.buildSuccess(apiTestService.getAPITestResultByTestId(testId));
  58. }
  59. @GetMapping("/latest/{testId}")
  60. @ApiOperation(value = "获取测试任务的最近一次执行信息", httpMethod = "GET")
  61. @ApiImplicitParam(name = "testId", dataType = "int", paramType = "query")
  62. public Response<APITestResultVO> getLatestTestResultByTestId(@PathVariable("testId") Integer testId) {
  63. return Response.buildSuccess(apiTestService.getLatestTestResultByTestId(testId));
  64. }
  65. }