From 194326b11ec127d2bcb230d1fe3dd6294238d90f Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 1 Jun 2020 14:29:00 +0800 Subject: [PATCH 1/4] =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95=20?= =?UTF-8?q?=E5=A4=8D=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/UserController.java | 2 +- .../controller/PerformanceTestController.java | 6 ++++- .../service/PerformanceTestService.java | 27 +++++++++++++++++++ .../report/PerformanceTestReport.vue | 2 +- .../performance/test/PerformanceTestPlan.vue | 24 +++++++++++++++-- 5 files changed, 56 insertions(+), 5 deletions(-) diff --git a/backend/src/main/java/io/metersphere/controller/UserController.java b/backend/src/main/java/io/metersphere/controller/UserController.java index 9a724fc608..688b6b59d0 100644 --- a/backend/src/main/java/io/metersphere/controller/UserController.java +++ b/backend/src/main/java/io/metersphere/controller/UserController.java @@ -140,7 +140,7 @@ public class UserController { } @PostMapping("/switch/source/org/{sourceId}") - @RequiresRoles(RoleConstants.ORG_ADMIN) + @RequiresRoles(value = {RoleConstants.ORG_ADMIN, RoleConstants.TEST_MANAGER, RoleConstants.TEST_VIEWER, RoleConstants.TEST_USER}, logical = Logical.OR) public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) { userService.switchUserRole("organization", sourceId); return SessionUtils.getUser(); diff --git a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java index 60b65ff5d0..5144b01cc3 100644 --- a/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java +++ b/backend/src/main/java/io/metersphere/performance/controller/PerformanceTestController.java @@ -20,7 +20,6 @@ import org.springframework.http.MediaType; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; - import javax.annotation.Resource; import java.util.List; @@ -113,4 +112,9 @@ public class PerformanceTestController { public List dashboardTests() { return performanceTestService.dashboardTests(SessionUtils.getCurrentWorkspaceId()); } + + @PostMapping(value = "/copy") + public void copy(@RequestBody SaveTestPlanRequest request) { + performanceTestService.copy(request); + } } diff --git a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java index a997e441e8..e5f98c09d1 100644 --- a/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java +++ b/backend/src/main/java/io/metersphere/performance/service/PerformanceTestService.java @@ -1,10 +1,12 @@ package io.metersphere.performance.service; +import io.metersphere.api.dto.SaveAPITestRequest; import io.metersphere.base.domain.*; import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportDetailMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; +import io.metersphere.commons.constants.APITestStatus; import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.LogUtil; @@ -28,6 +30,7 @@ import javax.annotation.Resource; import java.time.Instant; import java.time.temporal.ChronoUnit; import java.util.List; +import java.util.Objects; import java.util.Optional; import java.util.UUID; import java.util.stream.Collectors; @@ -283,4 +286,28 @@ public class PerformanceTestService { public List getLoadTestByProjectId(String projectId) { return extLoadTestMapper.getLoadTestByProjectId(projectId); } + + public void copy(SaveTestPlanRequest request) { + // copy test + LoadTestWithBLOBs copy = loadTestMapper.selectByPrimaryKey(request.getId()); + copy.setId(UUID.randomUUID().toString()); + copy.setName(copy.getName() + " Copy"); + copy.setCreateTime(System.currentTimeMillis()); + copy.setUpdateTime(System.currentTimeMillis()); + copy.setStatus(APITestStatus.Saved.name()); + copy.setUserId(Objects.requireNonNull(SessionUtils.getUser()).getId()); + loadTestMapper.insert(copy); + // copy test file + LoadTestFileExample loadTestFileExample = new LoadTestFileExample(); + loadTestFileExample.createCriteria().andTestIdEqualTo(request.getId()); + List loadTestFiles = loadTestFileMapper.selectByExample(loadTestFileExample); + if (!CollectionUtils.isEmpty(loadTestFiles)) { + loadTestFiles.forEach(loadTestFile -> { + FileMetadata fileMetadata = fileService.copyFile(loadTestFile.getFileId()); + loadTestFile.setTestId(copy.getId()); + loadTestFile.setFileId(fileMetadata.getId()); + loadTestFileMapper.insert(loadTestFile); + }); + } + } } diff --git a/frontend/src/business/components/performance/report/PerformanceTestReport.vue b/frontend/src/business/components/performance/report/PerformanceTestReport.vue index 2785aa2fd0..a36bbacbd3 100644 --- a/frontend/src/business/components/performance/report/PerformanceTestReport.vue +++ b/frontend/src/business/components/performance/report/PerformanceTestReport.vue @@ -125,7 +125,7 @@ this.$warning(this.$t('report.generation_error')); return false } else if (report.status === "Starting") { - this.$info(this.$t('being_generated')) + this.$info(this.$t('report.being_generated')) return false } this.$router.push({ diff --git a/frontend/src/business/components/performance/test/PerformanceTestPlan.vue b/frontend/src/business/components/performance/test/PerformanceTestPlan.vue index aa57565bf7..08c2cdb8ae 100644 --- a/frontend/src/business/components/performance/test/PerformanceTestPlan.vue +++ b/frontend/src/business/components/performance/test/PerformanceTestPlan.vue @@ -59,7 +59,7 @@ width="150" :label="$t('commons.operating')"> @@ -76,6 +76,7 @@ import MsContainer from "../../common/components/MsContainer"; import MsMainContainer from "../../common/components/MsMainContainer"; import MsPerformanceTestStatus from "./PerformanceTestStatus"; + import MsTableOperators from "../../common/components/MsTableOperators"; export default { components: { @@ -83,7 +84,8 @@ MsTablePagination, MsTableOperator, MsContainer, - MsMainContainer + MsMainContainer, + MsTableOperators }, data() { return { @@ -99,6 +101,18 @@ total: 0, loading: false, testId: null, + buttons: [ + { + tip: this.$t('commons.edit'), icon: "el-icon-edit", + exec: this.handleEdit + }, { + tip: this.$t('commons.copy'), icon: "el-icon-copy-document", type: "success", + exec: this.handleCopy + }, { + tip: this.$t('commons.delete'), icon: "el-icon-delete", type: "danger", + exec: this.handleDelete + } + ] } }, watch: { @@ -141,6 +155,12 @@ path: '/performance/test/edit/' + testPlan.id, }) }, + handleCopy(testPlan) { + this.result = this.$post("/performance/copy", {id: testPlan.id}, () => { + this.$success(this.$t('commons.save_success')); + this.search(); + }); + }, handleDelete(testPlan) { this.$alert(this.$t('load_test.delete_confirm') + testPlan.name + "?", '', { confirmButtonText: this.$t('commons.confirm'), From 12c6acef77e447e0307ce8b30a869378b89dce52 Mon Sep 17 00:00:00 2001 From: shiziyuan9527 Date: Mon, 1 Jun 2020 15:15:16 +0800 Subject: [PATCH 2/4] =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95-?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E9=A1=B9=E7=9B=AE-=E7=82=B9=E5=87=BB?= =?UTF-8?q?=E9=A1=B9=E7=9B=AE=E5=90=8D=E8=B7=B3=E8=BD=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/business/components/project/MsProject.vue | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/frontend/src/business/components/project/MsProject.vue b/frontend/src/business/components/project/MsProject.vue index da3598bf48..258b8766b5 100644 --- a/frontend/src/business/components/project/MsProject.vue +++ b/frontend/src/business/components/project/MsProject.vue @@ -7,7 +7,11 @@ :create-tip="btnTips" :title="title"/> - + + + Date: Mon, 1 Jun 2020 16:43:51 +0800 Subject: [PATCH 3/4] =?UTF-8?q?=E6=80=A7=E8=83=BD=E6=B5=8B=E8=AF=95-?= =?UTF-8?q?=E5=85=A8=E9=83=A8=E6=B5=8B=E8=AF=95-=E6=8E=92=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../base/mapper/ext/ExtLoadTestMapper.xml | 7 ++++++- .../request/testplan/QueryTestPlanRequest.java | 4 ++++ .../performance/test/PerformanceTestPlan.vue | 14 +++++++++++++- 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml index efa9cdcd2b..67bb294ca6 100644 --- a/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml +++ b/backend/src/main/java/io/metersphere/base/mapper/ext/ExtLoadTestMapper.xml @@ -27,7 +27,12 @@ AND load_test.id = #{request.id} - order by load_test.update_time desc + + order by + + test_plan_test_case.${order.name} ${order.type} + +