性能测试 复制

This commit is contained in:
shiziyuan9527 2020-06-01 14:29:00 +08:00
parent dde198da93
commit 194326b11e
5 changed files with 56 additions and 5 deletions

View File

@ -140,7 +140,7 @@ public class UserController {
} }
@PostMapping("/switch/source/org/{sourceId}") @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) { public UserDTO switchOrganization(@PathVariable(value = "sourceId") String sourceId) {
userService.switchUserRole("organization", sourceId); userService.switchUserRole("organization", sourceId);
return SessionUtils.getUser(); return SessionUtils.getUser();

View File

@ -20,7 +20,6 @@ import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile; import org.springframework.web.multipart.MultipartFile;
import javax.annotation.Resource; import javax.annotation.Resource;
import java.util.List; import java.util.List;
@ -113,4 +112,9 @@ public class PerformanceTestController {
public List<DashboardTestDTO> dashboardTests() { public List<DashboardTestDTO> dashboardTests() {
return performanceTestService.dashboardTests(SessionUtils.getCurrentWorkspaceId()); return performanceTestService.dashboardTests(SessionUtils.getCurrentWorkspaceId());
} }
@PostMapping(value = "/copy")
public void copy(@RequestBody SaveTestPlanRequest request) {
performanceTestService.copy(request);
}
} }

View File

@ -1,10 +1,12 @@
package io.metersphere.performance.service; package io.metersphere.performance.service;
import io.metersphere.api.dto.SaveAPITestRequest;
import io.metersphere.base.domain.*; import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*; import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtLoadTestMapper; import io.metersphere.base.mapper.ext.ExtLoadTestMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportDetailMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportDetailMapper;
import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper; import io.metersphere.base.mapper.ext.ExtLoadTestReportMapper;
import io.metersphere.commons.constants.APITestStatus;
import io.metersphere.commons.constants.PerformanceTestStatus; import io.metersphere.commons.constants.PerformanceTestStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
@ -28,6 +30,7 @@ import javax.annotation.Resource;
import java.time.Instant; import java.time.Instant;
import java.time.temporal.ChronoUnit; import java.time.temporal.ChronoUnit;
import java.util.List; import java.util.List;
import java.util.Objects;
import java.util.Optional; import java.util.Optional;
import java.util.UUID; import java.util.UUID;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -283,4 +286,28 @@ public class PerformanceTestService {
public List<LoadTest> getLoadTestByProjectId(String projectId) { public List<LoadTest> getLoadTestByProjectId(String projectId) {
return extLoadTestMapper.getLoadTestByProjectId(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<LoadTestFile> 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);
});
}
}
} }

View File

@ -125,7 +125,7 @@
this.$warning(this.$t('report.generation_error')); this.$warning(this.$t('report.generation_error'));
return false return false
} else if (report.status === "Starting") { } else if (report.status === "Starting") {
this.$info(this.$t('being_generated')) this.$info(this.$t('report.being_generated'))
return false return false
} }
this.$router.push({ this.$router.push({

View File

@ -59,7 +59,7 @@
width="150" width="150"
:label="$t('commons.operating')"> :label="$t('commons.operating')">
<template v-slot:default="scope"> <template v-slot:default="scope">
<ms-table-operator :is-tester-permission="true" @editClick="handleEdit(scope.row)" @deleteClick="handleDelete(scope.row)"/> <ms-table-operators :buttons="buttons" :row="scope.row"/>
</template> </template>
</el-table-column> </el-table-column>
</el-table> </el-table>
@ -76,6 +76,7 @@
import MsContainer from "../../common/components/MsContainer"; import MsContainer from "../../common/components/MsContainer";
import MsMainContainer from "../../common/components/MsMainContainer"; import MsMainContainer from "../../common/components/MsMainContainer";
import MsPerformanceTestStatus from "./PerformanceTestStatus"; import MsPerformanceTestStatus from "./PerformanceTestStatus";
import MsTableOperators from "../../common/components/MsTableOperators";
export default { export default {
components: { components: {
@ -83,7 +84,8 @@
MsTablePagination, MsTablePagination,
MsTableOperator, MsTableOperator,
MsContainer, MsContainer,
MsMainContainer MsMainContainer,
MsTableOperators
}, },
data() { data() {
return { return {
@ -99,6 +101,18 @@
total: 0, total: 0,
loading: false, loading: false,
testId: null, 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: { watch: {
@ -141,6 +155,12 @@
path: '/performance/test/edit/' + testPlan.id, 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) { handleDelete(testPlan) {
this.$alert(this.$t('load_test.delete_confirm') + testPlan.name + "", '', { this.$alert(this.$t('load_test.delete_confirm') + testPlan.name + "", '', {
confirmButtonText: this.$t('commons.confirm'), confirmButtonText: this.$t('commons.confirm'),