refactor(测试跟踪): 测试计划代码优化

This commit is contained in:
chenjianxing 2022-11-04 15:15:03 +08:00 committed by 刘瑞斌
parent 4017ec94ec
commit 2a3f15b512
5 changed files with 18 additions and 55 deletions

View File

@ -1,17 +0,0 @@
package io.metersphere.xpack.utils;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.xpack.license.service.LicenseService;
public class XpackUtil {
public static final String LICENSE_STATUS = "valid";
public static boolean validateLicense() {
LicenseService licenseService = CommonBeanFactory.getBean(LicenseService.class);
if (licenseService != null) {
return licenseService.validate().getStatus().equals(LICENSE_STATUS);
}
return false;
}
}

View File

@ -1,7 +1,6 @@
package io.metersphere.plan.service;
import com.alibaba.fastjson.JSONObject;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
import io.metersphere.base.mapper.ext.ExtTestPlanMapper;
@ -29,7 +28,6 @@ import io.metersphere.service.BaseUserService;
import io.metersphere.service.ServiceUtils;
import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.xpack.track.dto.IssuesDao;
import io.metersphere.xpack.utils.XpackUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
@ -296,7 +294,7 @@ public class TestPlanReportService {
}
try {
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
// todo 远程调用失败处理逻辑
Map<String, String> uiScenarioIdMap = new LinkedHashMap<>();
List<TestPlanUiScenario> testPlanUiScenarioList = planTestPlanUiScenarioCaseService.list(planId);
@ -371,7 +369,7 @@ public class TestPlanReportService {
}
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
testPlanReport.setIsUiScenarioExecuting(planTestPlanUiScenarioCaseService.isCaseExecuting(planId));
}
@ -615,7 +613,7 @@ public class TestPlanReportService {
private void initTestPlanReportBaseCount(TestPlanReport testPlanReport, TestPlanReportContentWithBLOBs reportContent) {
if (testPlanReport != null && reportContent != null) {
TestPlanReportBuildResultDTO reportBuildResultDTO = testPlanService.buildPlanReport(testPlanReport, reportContent);
reportContent.setApiBaseCount(JSONObject.toJSONString(reportBuildResultDTO.getTestPlanSimpleReportDTO()));
reportContent.setApiBaseCount(JSON.toJSONString(reportBuildResultDTO.getTestPlanSimpleReportDTO()));
}
}

View File

@ -1,7 +1,5 @@
package io.metersphere.plan.service;
import com.alibaba.fastjson.JSONObject;
import com.google.gson.Gson;
import io.metersphere.base.domain.*;
import io.metersphere.base.mapper.*;
@ -37,7 +35,6 @@ import io.metersphere.plan.request.ui.RunUiScenarioRequest;
import io.metersphere.plan.service.remote.api.PlanApiAutomationService;
import io.metersphere.plan.service.remote.api.PlanTestPlanApiCaseService;
import io.metersphere.plan.service.remote.api.PlanTestPlanScenarioCaseService;
import io.metersphere.plan.service.remote.gateway.GatewayService;
import io.metersphere.plan.service.remote.performance.PerfExecService;
import io.metersphere.plan.service.remote.performance.PlanTestPlanLoadCaseService;
import io.metersphere.plan.service.remote.ui.PlanTestPlanUiScenarioCaseService;
@ -48,7 +45,6 @@ import io.metersphere.service.*;
import io.metersphere.utils.DiscoveryUtil;
import io.metersphere.utils.LoggerUtil;
import io.metersphere.xpack.track.dto.IssuesDao;
import io.metersphere.xpack.utils.XpackUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
@ -146,8 +142,6 @@ public class TestPlanService {
private TestPlanExecutionQueueService testPlanExecutionQueueService;
@Resource
private KafkaTemplate<String, String> kafkaTemplate;
@Resource
private GatewayService gatewayService;
public synchronized TestPlan addTestPlan(AddTestPlanRequest testPlan) {
if (getTestPlanByName(testPlan.getName()).size() > 0) {
@ -364,7 +358,7 @@ public class TestPlanService {
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanLoadCaseService::getExecResultByPlanId);
}
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
calcExecResultStatus(testPlan.getId(), testPlan, planTestPlanUiScenarioCaseService::getExecResultByPlanId);
}
@ -1092,7 +1086,7 @@ public class TestPlanService {
planTestPlanLoadCaseService.copyPlan(sourcePlanId, targetPlanId);
}
if (serviceIdSet.contains(MicroServiceName.UI_TEST) && XpackUtil.validateLicense()) {
if (serviceIdSet.contains(MicroServiceName.UI_TEST)) {
planTestPlanUiScenarioCaseService.copyPlan(sourcePlanId, targetPlanId);
}
@ -1103,7 +1097,7 @@ public class TestPlanService {
}
public String getShareReport() {
Object microServices = gatewayService.getMicroServices();
Object microServices = DiscoveryUtil.getServices();
return replaceSharReport(microServices);
}
@ -1301,7 +1295,7 @@ public class TestPlanService {
returnDTO.setTestPlanSimpleReportDTO(report);
if (apiBaseInfoChanged) {
testPlanReportContentWithBLOBs.setApiBaseCount(JSONObject.toJSONString(report));
testPlanReportContentWithBLOBs.setApiBaseCount(JSON.toJSONString(report));
returnDTO.setApiBaseInfoChanged(true);
}
return returnDTO;

View File

@ -1,19 +0,0 @@
package io.metersphere.plan.service.remote.gateway;
import io.metersphere.commons.constants.MicroServiceName;
import io.metersphere.dto.ServiceDTO;
import io.metersphere.service.RemoteService;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class GatewayService extends RemoteService {
public GatewayService() {
super(MicroServiceName.GATEWAY);
}
public List<ServiceDTO> getMicroServices() {
return microService.getForDataArray(serviceName, "/services", ServiceDTO.class);
}
}

View File

@ -2,8 +2,9 @@ package io.metersphere.utils;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.dto.ServiceDTO;
import io.metersphere.plan.service.remote.gateway.GatewayService;
import org.springframework.cloud.client.discovery.DiscoveryClient;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
@ -14,10 +15,16 @@ public class DiscoveryUtil {
}
public static Set<String> getServiceIdSet() {
GatewayService gatewayService = CommonBeanFactory.getBean(GatewayService.class);
return gatewayService.getMicroServices()
DiscoveryClient discoveryClient = CommonBeanFactory.getBean(DiscoveryClient.class);
return discoveryClient.getServices()
.stream()
.map(ServiceDTO::getServiceId)
.collect(Collectors.toSet());
}
public static List<ServiceDTO> getServices() {
DiscoveryClient discoveryClient = CommonBeanFactory.getBean(DiscoveryClient.class);
return discoveryClient.getServices().stream()
.map(service -> new ServiceDTO(service, discoveryClient.getInstances(service).get(0).getPort()))
.collect(Collectors.toList());
}
}