性能测试 复制

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}")
@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();

View File

@ -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<DashboardTestDTO> dashboardTests() {
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;
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<LoadTest> 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<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'));
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({

View File

@ -59,7 +59,7 @@
width="150"
:label="$t('commons.operating')">
<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>
</el-table-column>
</el-table>
@ -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'),