feat(测试计划): 测试计划执行完成之后自动更新功能用例状态

This commit is contained in:
Jianguo-Genius 2024-07-08 16:31:42 +08:00 committed by 刘瑞斌
parent f3bf0a16e6
commit d5b320ae99
10 changed files with 409 additions and 15 deletions

View File

@ -2,6 +2,7 @@ package io.metersphere.functional.mapper;
import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.domain.ApiTestCase;
import io.metersphere.functional.domain.FunctionalCaseTest;
import io.metersphere.functional.dto.FunctionalCaseTestDTO;
import io.metersphere.functional.dto.FunctionalCaseTestPlanDTO;
import io.metersphere.functional.dto.TestPlanCaseExecuteHistoryDTO;
@ -27,4 +28,6 @@ public interface ExtFunctionalCaseTestMapper {
List<ApiTestCase> selectApiCaseByCaseIds(@Param("caseIds") List<String> caseIds);
List<ApiScenario> selectApiScenarioByCaseIds(@Param("caseIds") List<String> caseIds);
List<FunctionalCaseTest> selectApiAndScenarioIdsFromCaseIds(@Param("caseIds") List<String> functionalCaseIds);
}

View File

@ -244,4 +244,12 @@
</foreach>
</if>
</select>
<select id="selectApiAndScenarioIdsFromCaseIds"
resultType="io.metersphere.functional.domain.FunctionalCaseTest">
select case_id, source_id from functional_case_test where case_id in
<foreach collection="caseIds" item="caseId" open="(" close=")" separator=",">
#{caseId}
</foreach>
AND source_type in ('API','SCENARIO');
</select>
</mapper>

View File

@ -431,14 +431,13 @@ public class SimpleUserService {
private ProjectMapper projectMapper;
public UserInviteResponse saveInviteRecord(UserInviteRequest request, String inviteSource, SessionUser inviteUser) {
Map<String, String> errorMap = this.validateUserInfo(request.getInviteEmails());
if (MapUtils.isNotEmpty(errorMap)) {
throw new MSException(SystemResultCode.INVITE_EMAIL_EXIST, JSON.toJSONString(errorMap.keySet()));
}
if (StringUtils.equals(inviteSource, EmailInviteSource.SYSTEM.name())) {
//校验角色的合法性
globalUserRoleService.checkRoleIsGlobalAndHaveMember(request.getUserRoleIds(), true);
//校验邮箱和角色的合法性
Map<String, String> errorMap = this.validateUserInfo(request.getInviteEmails());
if (MapUtils.isNotEmpty(errorMap)) {
throw new MSException(SystemResultCode.INVITE_EMAIL_EXIST, JSON.toJSONString(errorMap.keySet()));
}
request.setOrganizationId(EmailInviteSource.SYSTEM.name());
request.setProjectId(EmailInviteSource.SYSTEM.name());
} else if (StringUtils.equals(inviteSource, EmailInviteSource.ORGANIZATION.name())) {

View File

@ -0,0 +1,15 @@
package io.metersphere.plan.mapper;
import io.metersphere.plan.domain.TestPlanReportApiCase;
import io.metersphere.plan.domain.TestPlanReportApiScenario;
import java.util.List;
public interface ExtTestPlanReportCaseMapper {
List<String> selectFunctionalCaseIdsByTestPlanId(String testPlanId);
List<TestPlanReportApiCase> selectApiCaseIdAndResultByReportId(String testPlanReportId);
List<TestPlanReportApiScenario> selectApiScenarioIdAndResultByReportId(String testPlanReportId);
}

View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="io.metersphere.plan.mapper.ExtTestPlanReportCaseMapper">
<select id="selectFunctionalCaseIdsByTestPlanId" resultType="java.lang.String">
SELECT distinct functional_case_id
FROM test_plan_functional_case
WHERE test_plan_id = #{0}
</select>
<select id="selectApiCaseIdAndResultByReportId"
resultType="io.metersphere.plan.domain.TestPlanReportApiCase">
SELECT distinct api_case_id, api_case_execute_result
FROM test_plan_report_api_case
WHERE test_plan_report_id = #{0}
</select>
<select id="selectApiScenarioIdAndResultByReportId"
resultType="io.metersphere.plan.domain.TestPlanReportApiScenario">
SELECT distinct api_scenario_id, api_scenario_execute_result
FROM test_plan_report_api_scenario
WHERE test_plan_report_id = #{0}
</select>
</mapper>

View File

@ -35,6 +35,8 @@ public class TestPlanExecuteSupportService {
private TestPlanReportApiCaseMapper testPlanReportApiCaseMapper;
@Resource
private TestPlanReportApiScenarioMapper testPlanReportApiScenarioMapper;
@Resource
private TestPlanService testPlanService;
public static final String QUEUE_PREFIX_TEST_PLAN_BATCH_EXECUTE = "test-plan-batch-execute:";
public static final String QUEUE_PREFIX_TEST_PLAN_GROUP_EXECUTE = "test-plan-group-execute:";
@ -69,6 +71,9 @@ public class TestPlanExecuteSupportService {
if (isGroupReport) {
testPlanReportService.summaryGroupReport(reportId);
} else {
//汇总之前根据测试计划设置检查是否要同步修改功能用例的状态
testPlanService.autoUpdateFunctionalCase(reportId);
//进行统计汇总
testPlanReportService.summaryPlanReport(reportId);
}

View File

@ -15,6 +15,7 @@ import io.metersphere.dto.BugProviderDTO;
import io.metersphere.functional.constants.CaseFileSourceType;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseModule;
import io.metersphere.functional.domain.FunctionalCaseTest;
import io.metersphere.functional.dto.*;
import io.metersphere.functional.mapper.ExtFunctionalCaseMapper;
import io.metersphere.functional.mapper.ExtFunctionalCaseModuleMapper;
@ -938,4 +939,12 @@ public class TestPlanFunctionalCaseService extends TestPlanResourceService {
sqlSession.flushStatements();
SqlSessionUtils.closeSqlSession(sqlSession, sqlSessionFactory);
}
public Map<String, List<String>> getFuncCaseAssociationCaseMap(List<String> functionalCaseIds) {
if (CollectionUtils.isEmpty(functionalCaseIds)) {
return new HashMap<>();
}
List<FunctionalCaseTest> functionalCaseTestList = extFunctionalCaseTestMapper.selectApiAndScenarioIdsFromCaseIds(functionalCaseIds);
return functionalCaseTestList.stream().collect(Collectors.groupingBy(FunctionalCaseTest::getCaseId, Collectors.mapping(FunctionalCaseTest::getSourceId, Collectors.toList())));
}
}

View File

@ -0,0 +1,70 @@
package io.metersphere.plan.service;
import io.metersphere.plan.domain.TestPlanReportApiCase;
import io.metersphere.plan.domain.TestPlanReportApiScenario;
import io.metersphere.plan.mapper.ExtTestPlanReportCaseMapper;
import io.metersphere.plan.mapper.TestPlanReportApiCaseMapper;
import io.metersphere.plan.mapper.TestPlanReportApiScenarioMapper;
import io.metersphere.plan.mapper.TestPlanReportFunctionCaseMapper;
import io.metersphere.sdk.constants.ResultStatus;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
@Transactional(rollbackFor = Exception.class)
public class TestPlanReportCaseService {
@Resource
private TestPlanReportFunctionCaseMapper testPlanReportFunctionCaseMapper;
@Resource
private TestPlanReportApiCaseMapper testPlanReportApiCaseMapper;
@Resource
private TestPlanReportApiScenarioMapper testPlanReportApiScenarioMapper;
@Resource
private ExtTestPlanReportCaseMapper extTestPlanReportCaseMapper;
public List<String> selectFunctionalCaseIdsByTestPlanId(String testPlanId) {
return extTestPlanReportCaseMapper.selectFunctionalCaseIdsByTestPlanId(testPlanId);
}
public Map<String, String> selectCaseExecResultByReportId(String testPlanReportId) {
List<TestPlanReportApiCase> apiCases = extTestPlanReportCaseMapper.selectApiCaseIdAndResultByReportId(testPlanReportId);
List<TestPlanReportApiScenario> scenarios = extTestPlanReportCaseMapper.selectApiScenarioIdAndResultByReportId(testPlanReportId);
Map<String, String> returnMap = new HashMap<>();
apiCases.forEach(item -> returnMap.put(item.getApiCaseId(), item.getApiCaseExecuteResult()));
scenarios.forEach(item -> returnMap.put(item.getApiScenarioId(), item.getApiScenarioExecuteResult()));
return returnMap;
}
/*
1.只要有失败的就算失败
2.没有失败的情况下有未执行的就不更新
3.1和2都不满足的情况下就是成功
*/
public String calculateFuncCaseExecResult(List<String> params) {
if (CollectionUtils.isNotEmpty(params)) {
List<String> execResult = new ArrayList<>(params.stream().distinct().toList());
if (execResult.contains(ResultStatus.ERROR.name())) {
return ResultStatus.ERROR.name();
} else {
execResult.remove(ResultStatus.SUCCESS.name());
execResult.remove(ResultStatus.FAKE_ERROR.name());
if (execResult.size() > 0) {
return null;
} else {
return ResultStatus.SUCCESS.name();
}
}
}
return null;
}
}

View File

@ -39,6 +39,7 @@ import io.metersphere.system.utils.ServiceUtils;
import jakarta.annotation.Resource;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.ListUtils;
import org.apache.commons.lang3.BooleanUtils;
import org.apache.commons.lang3.ObjectUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.ibatis.session.ExecutorType;
@ -100,11 +101,56 @@ public class TestPlanService extends TestPlanBaseUtilsService {
private TestPlanApiCaseMapper testPlanApiCaseMapper;
@Resource
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource
private TestPlanReportCaseService testPlanReportCaseService;
private static final int MAX_TAG_SIZE = 10;
@Resource
private TestPlanReportService testPlanReportService;
@Resource
private TestPlanReportMapper testPlanReportMapper;
public void autoUpdateFunctionalCase(String testPlanReportId) {
TestPlanReport testPlanReport = testPlanReportMapper.selectByPrimaryKey(testPlanReportId);
if (testPlanReport == null) {
return;
}
TestPlanConfig testPlanConfig = testPlanConfigMapper.selectByPrimaryKey(testPlanReport.getTestPlanId());
if (testPlanConfig != null && BooleanUtils.isTrue(testPlanConfig.getAutomaticStatusUpdate())) {
TestPlanFunctionalCaseService testPlanFunctionalCaseService = CommonBeanFactory.getBean(TestPlanFunctionalCaseService.class);
Map<String, List<String>> execResultFuncCaseMap = new HashMap<>();
List<String> functionalCaseIds = testPlanReportCaseService.selectFunctionalCaseIdsByTestPlanId(testPlanReport.getTestPlanId());
Map<String, List<String>> funcCaseAssociationCaseMap = testPlanFunctionalCaseService.getFuncCaseAssociationCaseMap(functionalCaseIds);
Map<String, String> caseExecResult = testPlanReportCaseService.selectCaseExecResultByReportId(testPlanReportId);
funcCaseAssociationCaseMap.forEach((funcCaseId, apiIdList) -> {
List<String> execResultList = new ArrayList<>();
apiIdList.forEach(apiId -> {
String result = caseExecResult.get(apiId);
if (StringUtils.isNotBlank(result)) {
execResultList.add(result);
}
});
String lastResult = testPlanReportCaseService.calculateFuncCaseExecResult(execResultList);
if (StringUtils.isNotBlank(lastResult)) {
if (execResultFuncCaseMap.containsKey(lastResult)) {
execResultFuncCaseMap.get(lastResult).add(funcCaseId);
} else {
execResultFuncCaseMap.put(lastResult, new ArrayList<>() {{
this.add(funcCaseId);
}});
}
}
});
execResultFuncCaseMap.forEach((result, funcCaseIds) -> {
TestPlanFunctionalCaseExample updateExample = new TestPlanFunctionalCaseExample();
updateExample.createCriteria().andTestPlanIdEqualTo(testPlanReport.getTestPlanId()).andFunctionalCaseIdIn(funcCaseIds);
TestPlanFunctionalCase updateRecord = new TestPlanFunctionalCase();
updateRecord.setLastExecResult(result);
testPlanFunctionalCaseMapper.updateByExampleSelective(updateRecord, updateExample);
});
}
}
/**
* 创建测试计划

View File

@ -1,30 +1,34 @@
package io.metersphere.plan.controller;
import io.metersphere.api.domain.ApiScenario;
import io.metersphere.api.mapper.ApiScenarioMapper;
import io.metersphere.functional.domain.FunctionalCase;
import io.metersphere.functional.domain.FunctionalCaseTest;
import io.metersphere.functional.mapper.FunctionalCaseMapper;
import io.metersphere.functional.mapper.FunctionalCaseTestMapper;
import io.metersphere.plan.domain.*;
import io.metersphere.plan.dto.request.TestPlanBatchExecuteRequest;
import io.metersphere.plan.dto.request.TestPlanCreateRequest;
import io.metersphere.plan.dto.request.TestPlanExecuteRequest;
import io.metersphere.plan.mapper.TestPlanCollectionMapper;
import io.metersphere.plan.mapper.TestPlanConfigMapper;
import io.metersphere.plan.mapper.TestPlanMapper;
import io.metersphere.plan.mapper.TestPlanReportMapper;
import io.metersphere.plan.mapper.*;
import io.metersphere.plan.service.TestPlanExecuteService;
import io.metersphere.plan.service.TestPlanService;
import io.metersphere.plan.service.TestPlanTestService;
import io.metersphere.project.domain.Project;
import io.metersphere.sdk.constants.ApiBatchRunMode;
import io.metersphere.sdk.constants.ModuleConstants;
import io.metersphere.sdk.constants.TestPlanConstants;
import io.metersphere.sdk.constants.*;
import io.metersphere.sdk.util.JSON;
import io.metersphere.system.base.BaseTest;
import io.metersphere.system.controller.handler.ResultHolder;
import io.metersphere.system.dto.AddProjectRequest;
import io.metersphere.system.log.constants.OperationLogModule;
import io.metersphere.system.service.CommonProjectService;
import io.metersphere.system.uid.IDGenerator;
import io.metersphere.system.uid.NumGenerator;
import jakarta.annotation.Resource;
import lombok.Data;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.junit.jupiter.api.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.StringRedisTemplate;
@ -63,8 +67,14 @@ public class TestPlanExecuteTests extends BaseTest {
"test-plan-batch-execute:", "test-plan-group-execute:", "test-plan-case-type-execute:", "test-plan-collection-execute:"
};
public static final String QUEUE_PREFIX_TEST_PLAN_COLLECTION = "test-plan-collection-execute:";
@Autowired
@Resource
private TestPlanReportMapper testPlanReportMapper;
@Resource
private TestPlanApiScenarioMapper testPlanApiScenarioMapper;
@Resource
private TestPlanReportApiScenarioMapper testPlanReportApiScenarioMapper;
@Resource
private TestPlanService testPlanService;
@Test
@Order(1)
@ -317,4 +327,211 @@ public class TestPlanExecuteTests extends BaseTest {
Assertions.assertTrue(allQueueIds.isEmpty());
}
@Test
@Order(3)
public void autoFunctionCase() throws Exception {
if (project == null) {
this.initData();
}
//测试计划关联功能用例 -- 附带把功能用例对应的接口用例关联过来并执行
//创建测试计划
TestPlanCreateRequest request = new TestPlanCreateRequest();
request.setProjectId(project.getId());
request.setType(TestPlanConstants.TEST_PLAN_TYPE_PLAN);
request.setName("testPlanForAutoFunction");
request.setModuleId(ModuleConstants.DEFAULT_NODE_ID);
MvcResult mvcResult = this.requestPostWithOkAndReturn("/test-plan/add", request);
String returnStr = mvcResult.getResponse().getContentAsString();
ResultHolder holder = JSON.parseObject(returnStr, ResultHolder.class);
String testPlanID = JSON.parseObject(JSON.toJSONString(holder.getData()), TestPlan.class).getId();
TestPlanResourceIds testPlanResourceIds = this.insertFunctionalCase(testPlanID);
testPlanResourceIds.getReportApiScenarios().forEach(item -> {
item.setApiScenarioExecuteResult(ResultStatus.SUCCESS.name());
testPlanReportApiScenarioMapper.updateByPrimaryKeySelective(item);
});
testPlanService.autoUpdateFunctionalCase(testPlanResourceIds.getTestPlanReportId());
TestPlanFunctionalCase testPlanFunctionalCase = testPlanFunctionalCaseMapper.selectByPrimaryKey(testPlanResourceIds.getTestPlanFunctionalCaseId());
Assertions.assertEquals(testPlanFunctionalCase.getLastExecResult(), ResultStatus.SUCCESS.name());
for (int i = 0; i < testPlanResourceIds.getReportApiScenarios().size(); i++) {
TestPlanReportApiScenario reportApiScenario = testPlanResourceIds.getReportApiScenarios().get(i);
if (i == 0) {
reportApiScenario.setApiScenarioExecuteResult(ResultStatus.ERROR.name());
testPlanReportApiScenarioMapper.updateByPrimaryKeySelective(reportApiScenario);
} else if (i == 1) {
reportApiScenario.setApiScenarioExecuteResult(ResultStatus.FAKE_ERROR.name());
testPlanReportApiScenarioMapper.updateByPrimaryKeySelective(reportApiScenario);
}
}
testPlanService.autoUpdateFunctionalCase(testPlanResourceIds.getTestPlanReportId());
testPlanFunctionalCase = testPlanFunctionalCaseMapper.selectByPrimaryKey(testPlanResourceIds.getTestPlanFunctionalCaseId());
Assertions.assertEquals(testPlanFunctionalCase.getLastExecResult(), ResultStatus.ERROR.name());
String lastExecResult = testPlanFunctionalCase.getLastExecResult();
for (int i = 0; i < testPlanResourceIds.getReportApiScenarios().size(); i++) {
if (i == 0) {
TestPlanReportApiScenario reportApiScenario = testPlanResourceIds.getReportApiScenarios().get(i);
reportApiScenario.setApiScenarioExecuteResult(ResultStatus.BLOCKED.name());
testPlanReportApiScenarioMapper.updateByPrimaryKeySelective(reportApiScenario);
}
}
testPlanService.autoUpdateFunctionalCase(testPlanResourceIds.getTestPlanReportId());
testPlanFunctionalCase = testPlanFunctionalCaseMapper.selectByPrimaryKey(testPlanResourceIds.getTestPlanFunctionalCaseId());
Assertions.assertEquals(testPlanFunctionalCase.getLastExecResult(), lastExecResult);
for (int i = 0; i < testPlanResourceIds.getReportApiScenarios().size(); i++) {
TestPlanReportApiScenario reportApiScenario = testPlanResourceIds.getReportApiScenarios().get(i);
reportApiScenario.setApiScenarioExecuteResult(ResultStatus.FAKE_ERROR.name());
testPlanReportApiScenarioMapper.updateByPrimaryKeySelective(reportApiScenario);
}
testPlanService.autoUpdateFunctionalCase(testPlanResourceIds.getTestPlanReportId());
testPlanFunctionalCase = testPlanFunctionalCaseMapper.selectByPrimaryKey(testPlanResourceIds.getTestPlanFunctionalCaseId());
Assertions.assertEquals(testPlanFunctionalCase.getLastExecResult(), ResultStatus.SUCCESS.name());
}
@Resource
private FunctionalCaseMapper functionalCaseMapper;
@Resource
private FunctionalCaseTestMapper functionalCaseTestMapper;
@Resource
private TestPlanFunctionalCaseMapper testPlanFunctionalCaseMapper;
@Resource
private ApiScenarioMapper apiScenarioMapper;
private TestPlanResourceIds insertFunctionalCase(String testPlanId) {
TestPlanResourceIds returnResourceIds = new TestPlanResourceIds();
returnResourceIds.setTestPlanId(testPlanId);
TestPlanConfig testPlanConfig = new TestPlanConfig();
testPlanConfig.setTestPlanId(testPlanId);
testPlanConfig.setAutomaticStatusUpdate(true);
testPlanConfigMapper.updateByPrimaryKeySelective(testPlanConfig);
TestPlanReport testPlanReport = new TestPlanReport();
testPlanReport.setId(IDGenerator.nextStr());
testPlanReport.setTestPlanId(testPlanId);
testPlanReport.setName(testPlanId);
testPlanReport.setCreateTime(System.currentTimeMillis());
testPlanReport.setCreateUser("admin");
testPlanReport.setStartTime(System.currentTimeMillis());
testPlanReport.setEndTime(System.currentTimeMillis());
testPlanReport.setExecStatus("COMPLETED");
testPlanReport.setResultStatus("PREPARED");
testPlanReport.setPassRate(100.00);
testPlanReport.setTriggerMode("API");
testPlanReport.setPassThreshold(100.00);
testPlanReport.setProjectId(project.getId());
testPlanReport.setDeleted(false);
testPlanReport.setIntegrated(false);
testPlanReport.setTestPlanName(testPlanId);
testPlanReport.setDefaultLayout(true);
testPlanReportMapper.insert(testPlanReport);
FunctionalCase functionalCase = new FunctionalCase();
functionalCase.setProjectId(project.getId());
functionalCase.setName(String.valueOf(System.currentTimeMillis()));
functionalCase.setId(IDGenerator.nextStr());
functionalCase.setModuleId("root");
functionalCase.setTemplateId("root");
functionalCase.setReviewStatus("PREPARED");
functionalCase.setCaseEditType("STEP");
functionalCase.setPos(4096L);
functionalCase.setVersionId("root");
functionalCase.setRefId(functionalCase.getId());
functionalCase.setLastExecuteResult("PREPARED");
functionalCase.setDeleted(false);
functionalCase.setPublicCase(false);
functionalCase.setLatest(true);
functionalCase.setCreateUser("admin");
functionalCase.setCreateTime(System.currentTimeMillis());
functionalCase.setUpdateTime(System.currentTimeMillis());
functionalCase.setNum(NumGenerator.nextNum(project.getId(), ApplicationNumScope.CASE_MANAGEMENT));
functionalCaseMapper.insert(functionalCase);
TestPlanFunctionalCase testPlanFunctionalCase = new TestPlanFunctionalCase();
testPlanFunctionalCase.setId(IDGenerator.nextStr());
testPlanFunctionalCase.setTestPlanId(testPlanId);
testPlanFunctionalCase.setFunctionalCaseId(functionalCase.getId());
testPlanFunctionalCase.setCreateTime(System.currentTimeMillis());
testPlanFunctionalCase.setCreateUser("admin");
testPlanFunctionalCase.setPos(4096L);
testPlanFunctionalCase.setLastExecResult("SUCCESS");
testPlanFunctionalCase.setTestPlanCollectionId("root");
testPlanFunctionalCaseMapper.insert(testPlanFunctionalCase);
for (int i = 0; i < 4; i++) {
ApiScenario apiScenario = new ApiScenario();
apiScenario.setId(IDGenerator.nextStr());
apiScenario.setName(apiScenario.getId());
apiScenario.setPriority("P1");
apiScenario.setStatus("PREPARED");
apiScenario.setStepTotal(1);
apiScenario.setRequestPassRate("100");
apiScenario.setNum(100000L);
apiScenario.setDeleted(false);
apiScenario.setPos(4096L * (i + 1));
apiScenario.setVersionId("root");
apiScenario.setRefId(apiScenario.getId());
apiScenario.setLatest(true);
apiScenario.setProjectId(project.getId());
apiScenario.setModuleId("root");
apiScenario.setGrouped(false);
apiScenario.setCreateTime(System.currentTimeMillis());
apiScenario.setUpdateTime(System.currentTimeMillis());
apiScenario.setCreateUser("admin");
apiScenario.setUpdateUser("admin");
apiScenarioMapper.insertSelective(apiScenario);
TestPlanApiScenario testPlanApiScenario = new TestPlanApiScenario();
testPlanApiScenario.setId(IDGenerator.nextStr());
testPlanApiScenario.setTestPlanId(testPlanId);
testPlanApiScenario.setApiScenarioId(apiScenario.getId());
testPlanApiScenario.setPos(4096L * (i + 1));
testPlanApiScenario.setTestPlanCollectionId("root");
testPlanApiScenario.setCreateTime(System.currentTimeMillis());
testPlanApiScenario.setCreateUser("admin");
testPlanApiScenarioMapper.insertSelective(testPlanApiScenario);
FunctionalCaseTest functionalCaseTest = new FunctionalCaseTest();
functionalCaseTest.setId(IDGenerator.nextStr());
functionalCaseTest.setCaseId(functionalCase.getId());
functionalCaseTest.setSourceId(apiScenario.getId());
functionalCaseTest.setSourceType("SCENARIO");
functionalCaseTest.setProjectId(project.getId());
functionalCaseTest.setVersionId(functionalCase.getVersionId());
functionalCaseTest.setCreateTime(System.currentTimeMillis());
functionalCaseTest.setUpdateTime(System.currentTimeMillis());
functionalCaseTest.setCreateUser("admin");
functionalCaseTest.setUpdateUser("admin");
functionalCaseTestMapper.insertSelective(functionalCaseTest);
TestPlanReportApiScenario testPlanReportApiScenario = new TestPlanReportApiScenario();
testPlanReportApiScenario.setId(IDGenerator.nextStr());
testPlanReportApiScenario.setTestPlanReportId(testPlanReport.getId());
testPlanReportApiScenario.setTestPlanCollectionId("root");
testPlanReportApiScenario.setGrouped(false);
testPlanReportApiScenario.setTestPlanApiScenarioId(testPlanApiScenario.getId());
testPlanReportApiScenario.setApiScenarioId(testPlanApiScenario.getApiScenarioId());
testPlanReportApiScenario.setApiScenarioName(apiScenario.getName());
testPlanReportApiScenario.setPos(testPlanApiScenario.getPos());
testPlanReportApiScenario.setApiScenarioNum(apiScenario.getNum());
testPlanReportApiScenarioMapper.insertSelective(testPlanReportApiScenario);
returnResourceIds.getReportApiScenarios().add(testPlanReportApiScenario);
}
returnResourceIds.setTestPlanFunctionalCaseId(testPlanFunctionalCase.getId());
returnResourceIds.setTestPlanReportId(testPlanReport.getId());
return returnResourceIds;
}
}
@Data
class TestPlanResourceIds {
private String testPlanId;
private String testPlanReportId;
private String testPlanFunctionalCaseId;
private List<TestPlanReportApiScenario> reportApiScenarios = new ArrayList<>();
}