fix(测试跟踪): 修复通过功能用例导入测试计划的其他用例没有环境导致无法运行问题

--bug=1020897--user=郭雨琦
https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001020897
This commit is contained in:
guoyuqi 2022-12-20 15:28:30 +08:00 committed by xiaomeinvG
parent f5959f7363
commit 7dbef8d2a6
11 changed files with 93 additions and 7 deletions

View File

@ -158,6 +158,11 @@ public class TestPlanApiCaseController {
return testPlanApiCaseService.getApiCaseEnv(planId);
}
@GetMapping("/get/project/ids/{planId}")
public List<String> getApiCaseProjectIds(@PathVariable("planId") String planId) {
return testPlanApiCaseService.getApiCaseProjectIds(planId);
}
@GetMapping("/is/executing/{planId}")
public Boolean isExecuting(@PathVariable("planId") String planId) {
return testPlanApiCaseService.isExecuting(planId);

View File

@ -175,6 +175,11 @@ public class TestPlanScenarioCaseController {
return testPlanScenarioCaseService.getApiScenarioEnv(planId);
}
@GetMapping("/get/project/ids/{planId}")
public List<String> getApiScenarioProjectIds(@PathVariable("planId") String planId) {
return testPlanScenarioCaseService.getApiScenarioProjectIds(planId);
}
@PostMapping("/plan/report")
public ApiPlanReportDTO buildApiReport(@RequestBody ApiPlanReportRequest request) {
return testPlanScenarioCaseService.buildApiReport(request);

View File

@ -817,4 +817,18 @@ public class TestPlanApiCaseService {
List<ApiDefinitionExecResultWithBLOBs> results = apiDefinitionExecResultMapper.selectByExampleWithBLOBs(example);
return results;
}
public List<String> getApiCaseProjectIds(String planId) {
TestPlanApiCaseExample caseExample = new TestPlanApiCaseExample();
caseExample.createCriteria().andTestPlanIdEqualTo(planId);
List<TestPlanApiCase> testPlanApiCases = testPlanApiCaseMapper.selectByExample(caseExample);
List<String> apiCaseIds = testPlanApiCases.stream().map(TestPlanApiCase::getApiCaseId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(apiCaseIds)) {
return new ArrayList<>();
}
ApiTestCaseExample example = new ApiTestCaseExample();
example.createCriteria().andIdIn(apiCaseIds);
List<ApiTestCase> apiTestCases = apiTestCaseMapper.selectByExample(example);
return apiTestCases.stream().map(ApiTestCase::getProjectId).collect(Collectors.toList());
}
}

View File

@ -1245,4 +1245,18 @@ public class TestPlanScenarioCaseService {
public String selectProjectId(String testPlanId) {
return extTestPlanScenarioCaseMapper.selectProjectId(testPlanId);
}
public List<String> getApiScenarioProjectIds(String planId) {
TestPlanApiScenarioExample scenarioExample = new TestPlanApiScenarioExample();
scenarioExample.createCriteria().andTestPlanIdEqualTo(planId);
List<TestPlanApiScenario> testPlanApiScenarios = testPlanApiScenarioMapper.selectByExample(scenarioExample);
List<String> scenarioIds = testPlanApiScenarios.stream().map(TestPlanApiScenario::getApiScenarioId).collect(Collectors.toList());
if (CollectionUtils.isEmpty(scenarioIds)) {
return new ArrayList<>();
}
ApiScenarioExample example = new ApiScenarioExample();
example.createCriteria().andIdIn(scenarioIds);
List<ApiScenario> apiScenarios = apiScenarioMapper.selectByExample(example);
return apiScenarios.stream().map(ApiScenario::getProjectId).collect(Collectors.toList());
}
}

View File

@ -227,6 +227,11 @@ public class TestPlanController {
return testPlanService.getPlanCaseEnv(plan.getId());
}
@PostMapping("/case/relevance/project/ids")
public List<String> getRelevanceProjectIds(@RequestBody TestPlan plan) {
return testPlanService.getRelevanceProjectIds(plan.getId());
}
@PostMapping("/edit/run/config")
public void updateRunModeConfig(@RequestBody TestPlanRunRequest testplanRunRequest) {

View File

@ -2059,7 +2059,7 @@ public class TestPlanService {
}
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
List<UiScenarioReportWithBLOBs> apiDefinitionLists = planTestPlanUiScenarioCaseService.selectExtForPlanReport(reportId);
if(CollectionUtils.isNotEmpty(apiDefinitionLists)){
if (CollectionUtils.isNotEmpty(apiDefinitionLists)) {
UiScenarioReportWithBLOBs apiDefinition = apiDefinitionLists.get(0);
convertEnvConfig(apiDefinition.getEnvConfig(), testPlanExtReportDTO);
getResourcePool(apiDefinition.getActuator(), testPlanExtReportDTO);
@ -2068,4 +2068,17 @@ public class TestPlanService {
}
return testPlanExtReportDTO;
}
public List<String> getRelevanceProjectIds(String planId) {
List<String> projectIds = new ArrayList<>();
List<String> apiCaseProjectIds = planTestPlanApiCaseService.getApiCaseProjectIds(planId);
List<String> apiScenarioProjectIds = planTestPlanScenarioCaseService.getApiScenarioProjectIds(planId);
if (DiscoveryUtil.hasService(MicroServiceName.UI_TEST)) {
List<String> uiScenarioProjectIds = planTestPlanUiScenarioCaseService.getUiScenarioProjectIds(planId);
projectIds.addAll(uiScenarioProjectIds);
}
projectIds.addAll(apiCaseProjectIds);
projectIds.addAll(apiScenarioProjectIds);
return projectIds.stream().distinct().collect(Collectors.toList());
}
}

View File

@ -131,6 +131,10 @@ public class PlanTestPlanApiCaseService extends ApiTestService {
return (Map<String, List<String>>) microService.getForData(serviceName, BASE_UEL + "/get/env/" + planId);
}
public List<String> getApiCaseProjectIds(String planId) {
return (List<String>) microService.getForData(serviceName, BASE_UEL + "/get/project/ids/" + planId);
}
public Boolean isCaseExecuting(String planId) {
return (Boolean) microService.getForData(serviceName, BASE_UEL + "/is/executing/" + planId);
}

View File

@ -143,6 +143,10 @@ public class PlanTestPlanScenarioCaseService extends ApiTestService {
return microService.getForData(serviceName, BASE_UEL + "/get/env/" + planId, Map.class);
}
public List<String> getApiScenarioProjectIds(String planId) {
return microService.getForData(serviceName, BASE_UEL + "/get/project/ids/" + planId, List.class);
}
public ApiPlanReportDTO getApiReport(ApiPlanReportRequest request) {
return microService.postForData(serviceName, BASE_UEL + "/plan/report", request, ApiPlanReportDTO.class);
}

View File

@ -157,4 +157,8 @@ public class PlanTestPlanUiScenarioCaseService extends UiTestService {
public Map<String, List<String>> getUiScenarioEnv(String planId) {
return microService.getForData(serviceName, BASE_URL + "/get/env/" + planId, Map.class);
}
public List<String> getUiScenarioProjectIds(String planId) {
return microService.getForData(serviceName, BASE_URL + "/get/project/ids/" + planId, List.class);
}
}

View File

@ -289,12 +289,16 @@ export function updateSchedule(param){
return post(BASE_URL + 'schedule/update',param);
}
export function getApiScenarioEnv(param){
return post(BASE_URL + 'api/scenario/env',param);
export function getApiScenarioEnv(param) {
return post(BASE_URL + 'api/scenario/env', param);
}
export function getPlanCaseEnv(param){
return post(BASE_URL + 'case/env',param);
export function getPlanCaseEnv(param) {
return post(BASE_URL + 'case/env', param);
}
export function getPlanCaseProjectIds(param) {
return post(BASE_URL + 'case/relevance/project/ids', param);
}
export function run(testId, reportId) {

View File

@ -200,7 +200,7 @@ import {getCurrentProjectID, getOwnerProjects} from "@/business/utils/sdk-utils"
import {getQuotaValidResourcePools} from "@/api/remote/resource-pool";
import EnvGroupPopover from "@/business/plan/env/EnvGroupPopover";
import {getApiCaseEnv} from "@/api/remote/plan/test-plan-api-case";
import {getApiScenarioEnv, getPlanCaseEnv} from "@/api/remote/plan/test-plan";
import {getApiScenarioEnv, getPlanCaseEnv, getPlanCaseProjectIds} from "@/api/remote/plan/test-plan";
import EnvGroupWithOption from "../env/EnvGroupWithOption";
import EnvironmentGroup from "@/business/plan/env/EnvironmentGroupList";
import EnvSelectPopover from "@/business/plan/env/EnvSelectPopover";
@ -402,9 +402,23 @@ export default {
this.projectIds.add(d);
}
}
this.$refs.envSelectPopover.open();
if (this.projectIds.size === 0) {
param = {id: this.planId};
getPlanCaseProjectIds(param).then((res) => {
let data = res.data;
if (data) {
for (let i = 0; i < data.length; i++) {
this.projectIds.add(data[i]);
}
}
this.$refs.envSelectPopover.open();
});
} else {
this.$refs.envSelectPopover.open();
}
});
}
},
handleCommand(command) {
if (