From 6aa69cee668e5d78ab68d078430c3e1db74ed5e3 Mon Sep 17 00:00:00 2001 From: q4speed Date: Wed, 22 Apr 2020 17:29:54 +0800 Subject: [PATCH] =?UTF-8?q?api=E6=B5=8B=E8=AF=95=EF=BC=8C=E6=9C=AA?= =?UTF-8?q?=E5=AE=8C=E5=BE=85=E7=BB=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/pom.xml | 5 + .../api/controller/APITestController.java | 68 ++++++ .../io/metersphere/api/dto/APITestResult.java | 12 ++ .../api/dto/DeleteAPITestRequest.java | 11 + .../api/dto/QueryAPITestRequest.java | 16 ++ .../api/dto/SaveAPITestRequest.java | 17 ++ .../api/service/ApiTestService.java | 100 +++++++++ .../io/metersphere/base/domain/ApiTest.java | 10 + .../base/domain/ApiTestExample.java | 70 +++++++ .../base/domain/ApiTestWithBLOBs.java | 10 +- .../metersphere/base/mapper/ApiTestMapper.xml | 53 +++-- .../base/mapper/ext/ExtApiTestMapper.java | 6 +- .../base/mapper/ext/ExtApiTestMapper.xml | 4 +- .../commons/constants/APITestStatus.java | 5 + .../controller/ApiTestController.java | 99 --------- .../handler/ResultResponseBodyAdvice.java | 2 +- .../java/io/metersphere/dto/ApiTestDTO.java | 15 -- .../metersphere/service/ApiTestService.java | 194 ------------------ .../db/migration/V2__metersphere_ddl.sql | 22 +- .../components/api/head/ApiHeaderMenus.vue | 74 +++---- .../components/api/test/ApiTestConfig.vue | 38 +++- .../components/api/test/ApiTestList.vue | 46 ++--- .../api/test/components/ApiAssertions.vue | 7 - .../api/test/components/ApiAssertionsEdit.vue | 9 +- .../api/test/components/ApiRequestConfig.vue | 5 +- .../api/test/components/ApiRequestForm.vue | 3 +- .../api/test/components/ApiScenarioConfig.vue | 27 ++- .../api/test/components/ApiScenarioForm.vue | 3 +- .../api/test/model/ScenarioModel.js | 90 +++++++- .../components/common/head/CreateTest.vue | 2 +- .../components/common/router/router.js | 21 +- frontend/src/i18n/zh-CN.js | 1 + 32 files changed, 578 insertions(+), 467 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/controller/APITestController.java create mode 100644 backend/src/main/java/io/metersphere/api/dto/APITestResult.java create mode 100644 backend/src/main/java/io/metersphere/api/dto/DeleteAPITestRequest.java create mode 100644 backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java create mode 100644 backend/src/main/java/io/metersphere/api/dto/SaveAPITestRequest.java create mode 100644 backend/src/main/java/io/metersphere/api/service/ApiTestService.java create mode 100644 backend/src/main/java/io/metersphere/commons/constants/APITestStatus.java delete mode 100644 backend/src/main/java/io/metersphere/controller/ApiTestController.java delete mode 100644 backend/src/main/java/io/metersphere/dto/ApiTestDTO.java delete mode 100644 backend/src/main/java/io/metersphere/service/ApiTestService.java diff --git a/backend/pom.xml b/backend/pom.xml index 546dad03f6..c9458fb0af 100644 --- a/backend/pom.xml +++ b/backend/pom.xml @@ -57,6 +57,11 @@ spring-boot-starter-jetty + + org.projectlombok + lombok + + org.mybatis.spring.boot mybatis-spring-boot-starter diff --git a/backend/src/main/java/io/metersphere/api/controller/APITestController.java b/backend/src/main/java/io/metersphere/api/controller/APITestController.java new file mode 100644 index 0000000000..d045159cd3 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/controller/APITestController.java @@ -0,0 +1,68 @@ +package io.metersphere.api.controller; + +import com.github.pagehelper.Page; +import com.github.pagehelper.PageHelper; +import io.metersphere.api.dto.APITestResult; +import io.metersphere.api.dto.DeleteAPITestRequest; +import io.metersphere.api.dto.QueryAPITestRequest; +import io.metersphere.api.dto.SaveAPITestRequest; +import io.metersphere.api.service.ApiTestService; +import io.metersphere.base.domain.ApiTestWithBLOBs; +import io.metersphere.commons.constants.RoleConstants; +import io.metersphere.commons.utils.PageUtils; +import io.metersphere.commons.utils.Pager; +import io.metersphere.service.FileService; +import io.metersphere.user.SessionUtils; +import org.apache.shiro.authz.annotation.Logical; +import org.apache.shiro.authz.annotation.RequiresRoles; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +import javax.annotation.Resource; + +@RestController +@RequestMapping(value = "/api") +@RequiresRoles(value = {RoleConstants.TEST_MANAGER, RoleConstants.TEST_USER, RoleConstants.TEST_VIEWER}, logical = Logical.OR) +public class APITestController { + @Resource + private ApiTestService apiTestService; + @Resource + private FileService fileService; + + @GetMapping("recent/{count}") + public List recentTest(@PathVariable int count) { + String currentWorkspaceId = SessionUtils.getCurrentWorkspaceId(); + QueryAPITestRequest request = new QueryAPITestRequest(); + request.setWorkspaceId(currentWorkspaceId); + PageHelper.startPage(1, count, true); + return apiTestService.recentTest(request); + } + + @PostMapping("/list/{goPage}/{pageSize}") + public Pager> list(@PathVariable int goPage, @PathVariable int pageSize, @RequestBody QueryAPITestRequest request) { + Page page = PageHelper.startPage(goPage, pageSize, true); + request.setWorkspaceId(SessionUtils.getCurrentWorkspaceId()); + return PageUtils.setPageInfo(page, apiTestService.list(request)); + } + + @PostMapping(value = "/save") + public String save(@RequestBody SaveAPITestRequest request) { + return apiTestService.save(request); + } + + @GetMapping("/get/{testId}") + public ApiTestWithBLOBs get(@PathVariable String testId) { + return apiTestService.get(testId); + } + + @PostMapping("/delete") + public void delete(@RequestBody DeleteAPITestRequest request) { + apiTestService.delete(request); + } +// +// @PostMapping("/run") +// public void run(@RequestBody RunTestPlanRequest request) { +// apiTestService.run(request); +// } +} diff --git a/backend/src/main/java/io/metersphere/api/dto/APITestResult.java b/backend/src/main/java/io/metersphere/api/dto/APITestResult.java new file mode 100644 index 0000000000..da08818882 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/APITestResult.java @@ -0,0 +1,12 @@ +package io.metersphere.api.dto; + +import io.metersphere.base.domain.ApiTestWithBLOBs; +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class APITestResult extends ApiTestWithBLOBs { + + private String projectName; +} diff --git a/backend/src/main/java/io/metersphere/api/dto/DeleteAPITestRequest.java b/backend/src/main/java/io/metersphere/api/dto/DeleteAPITestRequest.java new file mode 100644 index 0000000000..c05e6d9f05 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/DeleteAPITestRequest.java @@ -0,0 +1,11 @@ +package io.metersphere.api.dto; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class DeleteAPITestRequest { + + private String id; +} diff --git a/backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java b/backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java new file mode 100644 index 0000000000..88bbd2b3f8 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/QueryAPITestRequest.java @@ -0,0 +1,16 @@ +package io.metersphere.api.dto; + +import lombok.Getter; +import lombok.Setter; + +@Getter +@Setter +public class QueryAPITestRequest { + + private String id; + private String projectId; + private String name; + private String workspaceId; + private boolean recent = false; + +} diff --git a/backend/src/main/java/io/metersphere/api/dto/SaveAPITestRequest.java b/backend/src/main/java/io/metersphere/api/dto/SaveAPITestRequest.java new file mode 100644 index 0000000000..8f93f2b0a8 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/SaveAPITestRequest.java @@ -0,0 +1,17 @@ +package io.metersphere.api.dto; + +import lombok.Getter; +import lombok.Setter; + +@Setter +@Getter +public class SaveAPITestRequest { + + private String id; + + private String projectId; + + private String name; + + private String scenarioDefinition; +} diff --git a/backend/src/main/java/io/metersphere/api/service/ApiTestService.java b/backend/src/main/java/io/metersphere/api/service/ApiTestService.java new file mode 100644 index 0000000000..c9480cd8d2 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/service/ApiTestService.java @@ -0,0 +1,100 @@ +package io.metersphere.api.service; + +import io.metersphere.api.dto.APITestResult; +import io.metersphere.api.dto.DeleteAPITestRequest; +import io.metersphere.api.dto.QueryAPITestRequest; +import io.metersphere.api.dto.SaveAPITestRequest; +import io.metersphere.base.domain.*; +import io.metersphere.base.mapper.*; +import io.metersphere.base.mapper.ext.ExtApiTestMapper; +import io.metersphere.commons.constants.APITestStatus; +import io.metersphere.commons.exception.MSException; +import io.metersphere.i18n.Translator; +import io.metersphere.service.FileService; +import org.apache.commons.lang3.StringUtils; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.List; +import java.util.UUID; + +import javax.annotation.Resource; + +@Service +@Transactional(rollbackFor = Exception.class) +public class ApiTestService { + + @Resource + private ApiTestMapper apiTestMapper; + @Resource + private ExtApiTestMapper extApiTestMapper; + @Resource + private ProjectMapper projectMapper; + @Resource + private FileMetadataMapper fileMetadataMapper; + @Resource + private FileContentMapper fileContentMapper; + @Resource + private ApiTestFileMapper apiTestFileMapper; + @Resource + private FileService fileService; + + public List list(QueryAPITestRequest request) { + return extApiTestMapper.list(request); + } + + public List recentTest(QueryAPITestRequest request) { + request.setRecent(true); + return extApiTestMapper.list(request); + } + + public String save(SaveAPITestRequest request) { + final ApiTestWithBLOBs test; + if (StringUtils.isNotBlank(request.getId())) { + test = updateTest(request); + } else { + test = createTest(request); + } + return test.getId(); + } + + public ApiTestWithBLOBs get(String id) { + return apiTestMapper.selectByPrimaryKey(id); + } + + public void delete(DeleteAPITestRequest request) { + apiTestMapper.deleteByPrimaryKey(request.getId()); + } + + private ApiTestWithBLOBs updateTest(SaveAPITestRequest request) { + final ApiTestWithBLOBs test = new ApiTestWithBLOBs(); + test.setId(request.getId()); + test.setName(request.getName()); + test.setProjectId(request.getProjectId()); + test.setScenarioDefinition(request.getScenarioDefinition()); + test.setUpdateTime(System.currentTimeMillis()); + test.setStatus(APITestStatus.Saved.name()); + apiTestMapper.updateByPrimaryKeySelective(test); + return test; + } + + private ApiTestWithBLOBs createTest(SaveAPITestRequest request) { + ApiTestExample example = new ApiTestExample(); + example.createCriteria().andNameEqualTo(request.getName()).andProjectIdEqualTo(request.getProjectId()); + if (apiTestMapper.countByExample(example) > 0) { + MSException.throwException(Translator.get("load_test_already_exists")); + } + + final ApiTestWithBLOBs test = new ApiTestWithBLOBs(); + test.setId(UUID.randomUUID().toString()); + test.setName(request.getName()); + test.setProjectId(request.getProjectId()); + test.setScenarioDefinition(request.getScenarioDefinition()); + test.setCreateTime(System.currentTimeMillis()); + test.setUpdateTime(System.currentTimeMillis()); + test.setStatus(APITestStatus.Saved.name()); + apiTestMapper.insert(test); + return test; + } + +} diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiTest.java b/backend/src/main/java/io/metersphere/base/domain/ApiTest.java index aedb282bde..0e38a14f54 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiTest.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiTest.java @@ -11,6 +11,8 @@ public class ApiTest implements Serializable { private String description; + private String status; + private Long createTime; private Long updateTime; @@ -49,6 +51,14 @@ public class ApiTest implements Serializable { this.description = description == null ? null : description.trim(); } + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status == null ? null : status.trim(); + } + public Long getCreateTime() { return createTime; } diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiTestExample.java b/backend/src/main/java/io/metersphere/base/domain/ApiTestExample.java index fd377bba43..bca96d2a3c 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiTestExample.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiTestExample.java @@ -384,6 +384,76 @@ public class ApiTestExample { return (Criteria) this; } + public Criteria andStatusIsNull() { + addCriterion("status is null"); + return (Criteria) this; + } + + public Criteria andStatusIsNotNull() { + addCriterion("status is not null"); + return (Criteria) this; + } + + public Criteria andStatusEqualTo(String value) { + addCriterion("status =", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotEqualTo(String value) { + addCriterion("status <>", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThan(String value) { + addCriterion("status >", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusGreaterThanOrEqualTo(String value) { + addCriterion("status >=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThan(String value) { + addCriterion("status <", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLessThanOrEqualTo(String value) { + addCriterion("status <=", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusLike(String value) { + addCriterion("status like", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotLike(String value) { + addCriterion("status not like", value, "status"); + return (Criteria) this; + } + + public Criteria andStatusIn(List values) { + addCriterion("status in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotIn(List values) { + addCriterion("status not in", values, "status"); + return (Criteria) this; + } + + public Criteria andStatusBetween(String value1, String value2) { + addCriterion("status between", value1, value2, "status"); + return (Criteria) this; + } + + public Criteria andStatusNotBetween(String value1, String value2) { + addCriterion("status not between", value1, value2, "status"); + return (Criteria) this; + } + public Criteria andCreateTimeIsNull() { addCriterion("create_time is null"); return (Criteria) this; diff --git a/backend/src/main/java/io/metersphere/base/domain/ApiTestWithBLOBs.java b/backend/src/main/java/io/metersphere/base/domain/ApiTestWithBLOBs.java index 1dd78ac768..8e9bb95b4a 100644 --- a/backend/src/main/java/io/metersphere/base/domain/ApiTestWithBLOBs.java +++ b/backend/src/main/java/io/metersphere/base/domain/ApiTestWithBLOBs.java @@ -3,18 +3,18 @@ package io.metersphere.base.domain; import java.io.Serializable; public class ApiTestWithBLOBs extends ApiTest implements Serializable { - private String runtimeConfiguration; + private String scenarioDefinition; private String schedule; private static final long serialVersionUID = 1L; - public String getRuntimeConfiguration() { - return runtimeConfiguration; + public String getScenarioDefinition() { + return scenarioDefinition; } - public void setRuntimeConfiguration(String runtimeConfiguration) { - this.runtimeConfiguration = runtimeConfiguration == null ? null : runtimeConfiguration.trim(); + public void setScenarioDefinition(String scenarioDefinition) { + this.scenarioDefinition = scenarioDefinition == null ? null : scenarioDefinition.trim(); } public String getSchedule() { diff --git a/backend/src/main/java/io/metersphere/base/mapper/ApiTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ApiTestMapper.xml index ddf7b458e5..dbe33709e7 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ApiTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ApiTestMapper.xml @@ -6,11 +6,12 @@ + - + @@ -72,10 +73,10 @@ - id, project_id, name, description, create_time, update_time + id, project_id, name, description, status, create_time, update_time - runtime_configuration, schedule + scenario_definition, schedule +