feat: 测试评审测试计划功能测试同步添加关联的接口和性能测试

This commit is contained in:
wenyann 2021-03-16 17:48:26 +08:00
parent 2a40e173b5
commit f74bf38052
9 changed files with 156 additions and 6 deletions

View File

@ -12,4 +12,5 @@ public interface ExtTestPlanLoadCaseMapper {
List<TestPlanLoadCaseDTO> selectTestPlanLoadCaseList(@Param("request") LoadCaseRequest request); List<TestPlanLoadCaseDTO> selectTestPlanLoadCaseList(@Param("request") LoadCaseRequest request);
void updateCaseStatus(@Param("reportId") String reportId, @Param("status") String status); void updateCaseStatus(@Param("reportId") String reportId, @Param("status") String status);
List<String> getStatusByTestPlanId(@Param("planId") String planId); List<String> getStatusByTestPlanId(@Param("planId") String planId);
} }

View File

@ -0,0 +1,5 @@
package io.metersphere.commons.constants;
public enum TestCaseStatus {
performance,api,testcase,automation
}

View File

@ -23,4 +23,6 @@ public class PlanCaseRelevanceRequest {
* 具体要关联的用例 * 具体要关联的用例
*/ */
private List<String> testCaseIds = new ArrayList<>(); private List<String> testCaseIds = new ArrayList<>();
private Boolean checked;
} }

View File

@ -24,4 +24,6 @@ public class ReviewRelevanceRequest {
* 具体选择要关联的用例 * 具体选择要关联的用例
*/ */
private List<String> testCaseIds = new ArrayList<>(); private List<String> testCaseIds = new ArrayList<>();
private Boolean checked;
} }

View File

@ -6,10 +6,7 @@ import io.metersphere.base.mapper.ext.ExtProjectMapper;
import io.metersphere.base.mapper.ext.ExtTestCaseMapper; import io.metersphere.base.mapper.ext.ExtTestCaseMapper;
import io.metersphere.base.mapper.ext.ExtTestCaseReviewMapper; import io.metersphere.base.mapper.ext.ExtTestCaseReviewMapper;
import io.metersphere.base.mapper.ext.ExtTestReviewCaseMapper; import io.metersphere.base.mapper.ext.ExtTestReviewCaseMapper;
import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.*;
import io.metersphere.commons.constants.TestCaseReviewStatus;
import io.metersphere.commons.constants.TestPlanStatus;
import io.metersphere.commons.constants.TestReviewCaseStatus;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.user.SessionUser; import io.metersphere.commons.user.SessionUser;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
@ -77,6 +74,19 @@ public class TestCaseReviewService {
private NoticeSendService noticeSendService; private NoticeSendService noticeSendService;
@Resource @Resource
private SystemParameterService systemParameterService; private SystemParameterService systemParameterService;
@Resource
private TestCaseReviewLoadMapper testCaseReviewLoadMapper;
@Resource
private TestCaseReviewApiCaseMapper testCaseReviewApiCaseMapper;
@Resource
private TestCaseReviewScenarioMapper testCaseReviewScenarioMapper;
@Resource
private ApiTestCaseMapper apiTestCaseMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
@Resource
private ApiDefinitionMapper apiDefinitionMapper;
public String saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) { public String saveTestCaseReview(SaveTestCaseReviewRequest reviewRequest) {
checkCaseReviewExist(reviewRequest); checkCaseReviewExist(reviewRequest);
@ -366,7 +376,65 @@ public class TestCaseReviewService {
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
//同步添加关联的接口和测试用例
if(request.getChecked()){
if (!testCaseIds.isEmpty()) {
testCaseIds.forEach(caseId -> {
TestCaseWithBLOBs testDtail=testCaseMapper.selectByPrimaryKey(caseId);
if(StringUtils.equals(testDtail.getType(), TestCaseStatus.performance.name())){
TestCaseReviewLoad t=new TestCaseReviewLoad();
t.setId(UUID.randomUUID().toString());
t.setTestCaseReviewId(request.getReviewId());
t.setLoadCaseId(testDtail.getTestId());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
TestCaseReviewLoadExample example=new TestCaseReviewLoadExample();
example.createCriteria().andTestCaseReviewIdEqualTo(request.getReviewId()).andLoadCaseIdEqualTo(t.getLoadCaseId());
if (testCaseReviewLoadMapper.countByExample(example) <=0) {
testCaseReviewLoadMapper.insert(t);
}
}
if(StringUtils.equals(testDtail.getType(),TestCaseStatus.testcase.name())){
TestCaseReviewApiCase t=new TestCaseReviewApiCase();
ApiTestCaseWithBLOBs apitest=apiTestCaseMapper.selectByPrimaryKey(testDtail.getTestId());
ApiDefinitionWithBLOBs apidefinition=apiDefinitionMapper.selectByPrimaryKey(apitest.getApiDefinitionId());
t.setId(UUID.randomUUID().toString());
t.setTestCaseReviewId(request.getReviewId());
t.setApiCaseId(testDtail.getTestId());
t.setEnvironmentId(apidefinition.getEnvironmentId());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
TestCaseReviewApiCaseExample example=new TestCaseReviewApiCaseExample();
example.createCriteria().andTestCaseReviewIdEqualTo(request.getReviewId()).andApiCaseIdEqualTo(t.getApiCaseId());
if(testCaseReviewApiCaseMapper.countByExample(example)<=0){
testCaseReviewApiCaseMapper.insert(t);
}
}
if(StringUtils.equals(testDtail.getType(),TestCaseStatus.automation.name())){
TestCaseReviewScenario t=new TestCaseReviewScenario();
ApiScenarioWithBLOBs testPlanApiScenario=apiScenarioMapper.selectByPrimaryKey(testDtail.getTestId());
t.setId(UUID.randomUUID().toString());
t.setTestCaseReviewId(request.getReviewId());
t.setApiScenarioId(testDtail.getTestId());
t.setLastResult(testPlanApiScenario.getLastResult());
t.setPassRate(testPlanApiScenario.getPassRate());
t.setReportId(testPlanApiScenario.getReportId());
t.setStatus(testPlanApiScenario.getStatus());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
TestCaseReviewScenarioExample example=new TestCaseReviewScenarioExample();
example.createCriteria().andTestCaseReviewIdEqualTo(request.getReviewId()).andApiScenarioIdEqualTo(t.getApiScenarioId());
if(testCaseReviewScenarioMapper.countByExample(example)<=0){
testCaseReviewScenarioMapper.insert(t);
}
}
});
}
}
TestCaseReview testCaseReview = testCaseReviewMapper.selectByPrimaryKey(request.getReviewId()); TestCaseReview testCaseReview = testCaseReviewMapper.selectByPrimaryKey(request.getReviewId());
if (StringUtils.equals(testCaseReview.getStatus(), TestCaseReviewStatus.Prepare.name()) if (StringUtils.equals(testCaseReview.getStatus(), TestCaseReviewStatus.Prepare.name())
|| StringUtils.equals(testCaseReview.getStatus(), TestCaseReviewStatus.Completed.name())) { || StringUtils.equals(testCaseReview.getStatus(), TestCaseReviewStatus.Completed.name())) {

View File

@ -114,6 +114,18 @@ public class TestPlanService {
private ApiTestCaseService apiTestCaseService; private ApiTestCaseService apiTestCaseService;
@Resource @Resource
private PerformanceTestService performanceTestService; private PerformanceTestService performanceTestService;
@Resource
private TestPlanLoadCaseMapper testPlanLoadCaseMapper;
@Resource
private ApiTestCaseMapper apiTestCaseMapper;
@Resource
private ApiDefinitionMapper apiDefinitionMapper;
@Resource
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
public synchronized void addTestPlan(AddTestPlanRequest testPlan) { public synchronized void addTestPlan(AddTestPlanRequest testPlan) {
if (getTestPlanByName(testPlan.getName()).size() > 0) { if (getTestPlanByName(testPlan.getName()).size() > 0) {
@ -416,7 +428,65 @@ public class TestPlanService {
} }
sqlSession.flushStatements(); sqlSession.flushStatements();
//同步添加关联的接口和测试用例
if(request.getChecked()){
if (!testCaseIds.isEmpty()) {
testCaseIds.forEach(caseId -> {
TestCaseWithBLOBs testDtail=testCaseMapper.selectByPrimaryKey(caseId);
if(StringUtils.equals(testDtail.getType(),TestCaseStatus.performance.name())){
TestPlanLoadCase t = new TestPlanLoadCase();
t.setId(UUID.randomUUID().toString());
t.setTestPlanId(request.getPlanId());
t.setLoadCaseId(testDtail.getTestId());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
TestPlanLoadCaseExample testPlanLoadCaseExample=new TestPlanLoadCaseExample();
testPlanLoadCaseExample.createCriteria().andTestPlanIdEqualTo(request.getPlanId()).andLoadCaseIdEqualTo(t.getLoadCaseId());
if (testPlanLoadCaseMapper.countByExample(testPlanLoadCaseExample) <=0) {
testPlanLoadCaseMapper.insert(t);
}
}
if(StringUtils.equals(testDtail.getType(),TestCaseStatus.testcase.name())){
TestPlanApiCase t=new TestPlanApiCase();
ApiTestCaseWithBLOBs apitest=apiTestCaseMapper.selectByPrimaryKey(testDtail.getTestId());
ApiDefinitionWithBLOBs apidefinition=apiDefinitionMapper.selectByPrimaryKey(apitest.getApiDefinitionId());
t.setId(UUID.randomUUID().toString());
t.setTestPlanId(request.getPlanId());
t.setApiCaseId(testDtail.getTestId());
t.setEnvironmentId(apidefinition.getEnvironmentId());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
TestPlanApiCaseExample example=new TestPlanApiCaseExample();
example.createCriteria().andTestPlanIdEqualTo(request.getPlanId()).andApiCaseIdEqualTo(t.getApiCaseId());
if(testPlanApiCaseMapper.countByExample(example)<=0){
testPlanApiCaseMapper.insert(t);
}
}
if(StringUtils.equals(testDtail.getType(),TestCaseStatus.automation.name())){
TestPlanApiScenario t=new TestPlanApiScenario();
ApiScenarioWithBLOBs testPlanApiScenario=apiScenarioMapper.selectByPrimaryKey(testDtail.getTestId());
t.setId(UUID.randomUUID().toString());
t.setTestPlanId(request.getPlanId());
t.setApiScenarioId(testDtail.getTestId());
t.setLastResult(testPlanApiScenario.getLastResult());
t.setPassRate(testPlanApiScenario.getPassRate());
t.setReportId(testPlanApiScenario.getReportId());
t.setStatus(testPlanApiScenario.getStatus());
t.setCreateTime(System.currentTimeMillis());
t.setUpdateTime(System.currentTimeMillis());
TestPlanApiScenarioExample example=new TestPlanApiScenarioExample();
example.createCriteria().andTestPlanIdEqualTo(request.getPlanId()).andApiScenarioIdEqualTo(t.getApiScenarioId());
if(testPlanApiScenarioMapper.countByExample(example)<=0){
testPlanApiScenarioMapper.insert(t);
}
}
});
}
}
TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId()); TestPlan testPlan = testPlanMapper.selectByPrimaryKey(request.getPlanId());
if (StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Prepare.name()) if (StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Prepare.name())
|| StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) { || StringUtils.equals(testPlan.getStatus(), TestPlanStatus.Completed.name())) {

View File

@ -74,7 +74,7 @@
}, },
save() { save() {
this.$emit('save'); this.$emit('save', this.checked);
}, },
close() { close() {

View File

@ -158,11 +158,12 @@ export default {
this.projectId = projectId; this.projectId = projectId;
}, },
saveCaseRelevance() { saveCaseRelevance(item) {
let param = {}; let param = {};
param.planId = this.planId; param.planId = this.planId;
param.testCaseIds = [...this.selectIds]; param.testCaseIds = [...this.selectIds];
param.request = this.condition; param.request = this.condition;
param.checked = item
// //
if (this.testCases.length === param.testCaseIds.length) { if (this.testCases.length === param.testCaseIds.length) {
param.testCaseIds = ['all']; param.testCaseIds = ['all'];

View File

@ -203,6 +203,7 @@ export default {
param.reviewId = this.reviewId; param.reviewId = this.reviewId;
param.testCaseIds = [...this.selectIds]; param.testCaseIds = [...this.selectIds];
param.request = this.condition; param.request = this.condition;
param.checked = this.checked;
// //
if (this.testReviews.length === param.testCaseIds.length) { if (this.testReviews.length === param.testCaseIds.length) {
param.testCaseIds = ['all']; param.testCaseIds = ['all'];