diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java index 09b1c6cdcb..07e03e7125 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiTestCaseService.java @@ -1165,11 +1165,13 @@ public class ApiTestCaseService { List apiTestCaseDTOS = extApiTestCaseMapper.relevanceApiList(request); List versionIds = apiTestCaseDTOS.stream().map(ApiTestCaseDTO::getVersionId).collect(Collectors.toList()); ProjectVersionService projectVersionService = CommonBeanFactory.getBean(ProjectVersionService.class); - Map projectVersionMap = projectVersionService.getProjectVersionByIds(versionIds).stream() - .collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); - apiTestCaseDTOS.forEach(apiTestCaseDTO -> { - apiTestCaseDTO.setVersionName(projectVersionMap.get(apiTestCaseDTO.getVersionId())); - }); + if (projectVersionService != null) { + Map projectVersionMap = projectVersionService.getProjectVersionByIds(versionIds).stream() + .collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); + apiTestCaseDTOS.forEach(apiTestCaseDTO -> { + apiTestCaseDTO.setVersionName(projectVersionMap.get(apiTestCaseDTO.getVersionId())); + }); + } return apiTestCaseDTOS; } @@ -1177,11 +1179,13 @@ public class ApiTestCaseService { List apiScenarioDTOS = extApiScenarioMapper.relevanceScenarioList(request); List versionIds = apiScenarioDTOS.stream().map(ApiScenarioDTO::getVersionId).collect(Collectors.toList()); ProjectVersionService projectVersionService = CommonBeanFactory.getBean(ProjectVersionService.class); - Map projectVersionMap = projectVersionService.getProjectVersionByIds(versionIds).stream() - .collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); - apiScenarioDTOS.forEach(apiTestCaseDTO -> { - apiTestCaseDTO.setVersionName(projectVersionMap.get(apiTestCaseDTO.getVersionId())); - }); + if (projectVersionService != null) { + Map projectVersionMap = projectVersionService.getProjectVersionByIds(versionIds).stream() + .collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); + apiScenarioDTOS.forEach(apiTestCaseDTO -> { + apiTestCaseDTO.setVersionName(projectVersionMap.get(apiTestCaseDTO.getVersionId())); + }); + } return apiScenarioDTOS; } diff --git a/performance-test/backend/src/main/java/io/metersphere/track/service/PerformanceTestCaseService.java b/performance-test/backend/src/main/java/io/metersphere/track/service/PerformanceTestCaseService.java index c2572a3082..f81bcb3d61 100644 --- a/performance-test/backend/src/main/java/io/metersphere/track/service/PerformanceTestCaseService.java +++ b/performance-test/backend/src/main/java/io/metersphere/track/service/PerformanceTestCaseService.java @@ -31,10 +31,12 @@ public class PerformanceTestCaseService { public void buildVersionInfo(List loadTests) { List versionIds = loadTests.stream().map(LoadTestDTO::getVersionId).collect(Collectors.toList()); ProjectVersionService projectVersionService = CommonBeanFactory.getBean(ProjectVersionService.class); - Map projectVersionMap = projectVersionService.getProjectVersionByIds(versionIds).stream() - .collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); - loadTests.forEach(loadTest -> { - loadTest.setVersionName(projectVersionMap.get(loadTest.getVersionId())); - }); + if(projectVersionService != null) { + Map projectVersionMap = projectVersionService.getProjectVersionByIds(versionIds).stream() + .collect(Collectors.toMap(ProjectVersion::getId, ProjectVersion::getName)); + loadTests.forEach(loadTest -> { + loadTest.setVersionName(projectVersionMap.get(loadTest.getVersionId())); + }); + } } }