refactor: 检查测试用例是否关联测试

This commit is contained in:
shiziyuan9527 2020-07-14 21:52:10 +08:00
parent 5cc3755dcd
commit c3e32f2df8
3 changed files with 27 additions and 26 deletions

View File

@ -27,6 +27,7 @@ import io.metersphere.i18n.Translator;
import io.metersphere.job.sechedule.ApiTestJob; import io.metersphere.job.sechedule.ApiTestJob;
import io.metersphere.service.FileService; import io.metersphere.service.FileService;
import io.metersphere.service.ScheduleService; import io.metersphere.service.ScheduleService;
import io.metersphere.track.service.TestCaseService;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.CollectionUtils; import org.springframework.util.CollectionUtils;
@ -58,6 +59,8 @@ public class APITestService {
private ScheduleService scheduleService; private ScheduleService scheduleService;
@Resource @Resource
private TestCaseMapper testCaseMapper; private TestCaseMapper testCaseMapper;
@Resource
private TestCaseService testCaseService;
public List<APITestResult> list(QueryAPITestRequest request) { public List<APITestResult> list(QueryAPITestRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
@ -130,20 +133,7 @@ public class APITestService {
} }
public void delete(String testId) { public void delete(String testId) {
testCaseService.checkIsRelateTest(testId);
// 是否关联测试用例
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andTestIdEqualTo(testId);
List<TestCase> testCases = testCaseMapper.selectByExample(testCaseExample);
if (testCases.size() > 0) {
String caseName = "";
for (int i = 0; i < testCases.size(); i++) {
caseName = caseName + testCases.get(i).getName() + ",";
}
caseName = caseName.substring(0, caseName.length() - 1);
MSException.throwException(Translator.get("related_case_del_fail_prefix") + caseName + Translator.get("related_case_del_fail_suffix"));
}
deleteFileByTestId(testId); deleteFileByTestId(testId);
apiReportService.deleteByTestId(testId); apiReportService.deleteByTestId(testId);
apiTestMapper.deleteByPrimaryKey(testId); apiTestMapper.deleteByPrimaryKey(testId);

View File

@ -22,6 +22,7 @@ import io.metersphere.service.FileService;
import io.metersphere.service.ScheduleService; import io.metersphere.service.ScheduleService;
import io.metersphere.service.TestResourceService; import io.metersphere.service.TestResourceService;
import io.metersphere.track.request.testplan.*; import io.metersphere.track.request.testplan.*;
import io.metersphere.track.service.TestCaseService;
import org.apache.commons.collections4.ListUtils; import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -73,6 +74,8 @@ public class PerformanceTestService {
private ScheduleService scheduleService; private ScheduleService scheduleService;
@Resource @Resource
private TestCaseMapper testCaseMapper; private TestCaseMapper testCaseMapper;
@Resource
private TestCaseService testCaseService;
public List<LoadTestDTO> list(QueryTestPlanRequest request) { public List<LoadTestDTO> list(QueryTestPlanRequest request) {
request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders())); request.setOrders(ServiceUtils.getDefaultOrder(request.getOrders()));
@ -82,18 +85,7 @@ public class PerformanceTestService {
public void delete(DeleteTestPlanRequest request) { public void delete(DeleteTestPlanRequest request) {
String testId = request.getId(); String testId = request.getId();
// 是否关联测试用例 testCaseService.checkIsRelateTest(testId);
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andTestIdEqualTo(testId);
List<TestCase> testCases = testCaseMapper.selectByExample(testCaseExample);
if (testCases.size() > 0) {
String caseName = "";
for (int i = 0; i < testCases.size(); i++) {
caseName = caseName + testCases.get(i).getName() + ",";
}
caseName = caseName.substring(0, caseName.length() - 1);
MSException.throwException(Translator.get("related_case_del_fail_prefix") + caseName + Translator.get("related_case_del_fail_suffix"));
}
LoadTestReportExample loadTestReportExample = new LoadTestReportExample(); LoadTestReportExample loadTestReportExample = new LoadTestReportExample();
loadTestReportExample.createCriteria().andTestIdEqualTo(testId); loadTestReportExample.createCriteria().andTestIdEqualTo(testId);

View File

@ -410,4 +410,23 @@ public class TestCaseService {
example.createCriteria().andProjectIdEqualTo(projectId); example.createCriteria().andProjectIdEqualTo(projectId);
testCaseMapper.deleteByExample(example); testCaseMapper.deleteByExample(example);
} }
/**
* 是否关联测试
*
* @param testId
*/
public void checkIsRelateTest(String testId) {
TestCaseExample testCaseExample = new TestCaseExample();
testCaseExample.createCriteria().andTestIdEqualTo(testId);
List<TestCase> testCases = testCaseMapper.selectByExample(testCaseExample);
StringBuilder caseName = new StringBuilder();
if (testCases.size() > 0) {
for (TestCase testCase : testCases) {
caseName = caseName.append(testCase.getName()).append(",");
}
String str = caseName.toString().substring(0, caseName.length() - 1);
MSException.throwException(Translator.get("related_case_del_fail_prefix") + " " + str + " " + Translator.get("related_case_del_fail_suffix"));
}
}
} }