diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java index 63d41812d6..4e1bbee2df 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/ParameterConfig.java @@ -6,12 +6,10 @@ import io.metersphere.api.dto.scenario.HttpConfig; import io.metersphere.api.dto.scenario.HttpConfigCondition; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; -import io.metersphere.service.definition.ApiDefinitionService; -import io.metersphere.service.definition.ApiTestCaseService; -import io.metersphere.service.plan.TestPlanApiCaseService; import io.metersphere.base.domain.ApiDefinition; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.TestPlanApiCase; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ConditionType; import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.constants.RunModeConstants; @@ -19,6 +17,9 @@ import io.metersphere.environment.ssl.MsKeyStore; import io.metersphere.jmeter.utils.ScriptEngineUtils; import io.metersphere.plugin.core.MsParameter; import io.metersphere.plugin.core.MsTestElement; +import io.metersphere.service.definition.ApiDefinitionService; +import io.metersphere.service.definition.ApiTestCaseService; +import io.metersphere.service.plan.TestPlanApiCaseService; import lombok.Data; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; @@ -130,7 +131,7 @@ public class ParameterConfig extends MsParameter { ApiDefinition apiDefinition = null; ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class); ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); - if (StringUtils.isNotEmpty(samplerProxy.getRefType()) && samplerProxy.getRefType().equals("CASE")) { + if (StringUtils.isNotEmpty(samplerProxy.getRefType()) && samplerProxy.getRefType().equals(CommonConstants.CASE)) { ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(samplerProxy.getId()); if (caseWithBLOBs != null) { apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java index 38f4fffc86..48a8a617bd 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/post/MsJDBCPostProcessor.java @@ -9,21 +9,22 @@ import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; -import io.metersphere.service.definition.ApiDefinitionService; -import io.metersphere.service.definition.ApiTestCaseService; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.JSONUtil; import io.metersphere.commons.utils.LogUtil; import io.metersphere.constants.RunModeConstants; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.plugin.core.MsParameter; import io.metersphere.plugin.core.MsTestElement; -import io.metersphere.commons.utils.JSONUtil; +import io.metersphere.service.definition.ApiDefinitionService; +import io.metersphere.service.definition.ApiTestCaseService; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -183,7 +184,7 @@ public class MsJDBCPostProcessor extends MsTestElement { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MsJDBCPostProcessor proxy = null; - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); if (bloBs != null) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java index c8595c36a9..8a3f4d4251 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/processors/pre/MsJDBCPreProcessor.java @@ -9,22 +9,23 @@ import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; -import io.metersphere.service.definition.ApiDefinitionService; -import io.metersphere.service.definition.ApiTestCaseService; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.constants.RequestTypeConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.JSONUtil; import io.metersphere.commons.utils.LogUtil; import io.metersphere.constants.RunModeConstants; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.plugin.core.MsParameter; import io.metersphere.plugin.core.MsTestElement; -import io.metersphere.commons.utils.JSONUtil; +import io.metersphere.service.definition.ApiDefinitionService; +import io.metersphere.service.definition.ApiTestCaseService; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -47,7 +48,6 @@ import java.util.stream.Collectors; */ @Data @EqualsAndHashCode(callSuper = true) - public class MsJDBCPreProcessor extends MsTestElement { // type 必须放最前面,以便能够转换正确的类 private String type = ElementConstants.JDBC_PRE; @@ -172,7 +172,7 @@ public class MsJDBCPreProcessor extends MsTestElement { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MsJDBCPreProcessor proxy = null; - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); if (bloBs != null) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java index 9781f78e1f..19bcbe1adb 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsDubboSampler.java @@ -17,17 +17,18 @@ import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.environment.GlobalScriptFilterRequest; import io.metersphere.api.parse.api.JMeterScriptUtil; -import io.metersphere.service.definition.ApiDefinitionService; -import io.metersphere.service.definition.ApiTestCaseService; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.JSONUtil; import io.metersphere.commons.utils.LogUtil; import io.metersphere.plugin.core.MsParameter; import io.metersphere.plugin.core.MsTestElement; -import io.metersphere.commons.utils.JSONUtil; +import io.metersphere.service.definition.ApiDefinitionService; +import io.metersphere.service.definition.ApiTestCaseService; import lombok.Data; import lombok.EqualsAndHashCode; import org.apache.commons.collections.CollectionUtils; @@ -43,42 +44,24 @@ import java.util.stream.Collectors; @Data @EqualsAndHashCode(callSuper = true) - public class MsDubboSampler extends MsTestElement { private String clazzName = MsDubboSampler.class.getCanonicalName(); - /** * type 必须放最前面,以便能够转换正确的类 */ private String type = ElementConstants.DUBBO_SAMPLER; - - private final String protocol = "dubbo://"; @JsonProperty(value = "interface") - private String _interface; - private String method; - - private MsConfigCenter configCenter; - private MsRegistryCenter registryCenter; - private MsConsumerAndService consumerAndService; - - private List args; - private List attachmentArgs; - - private String useEnvironment; - - private boolean customizeReq; - @Override public void toHashTree(HashTree tree, List hashTree, MsParameter msParameter) { ParameterConfig config = (ParameterConfig) msParameter; @@ -134,7 +117,7 @@ public class MsDubboSampler extends MsTestElement { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MsDubboSampler proxy = null; - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); if (bloBs != null) { @@ -155,7 +138,7 @@ public class MsDubboSampler extends MsTestElement { } } if (proxy != null) { - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ElementUtil.mergeHashTree(this, proxy.getHashTree()); } else { this.setHashTree(proxy.getHashTree()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 25db1e0bae..f2391cb22d 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -18,6 +18,7 @@ import io.metersphere.api.dto.scenario.environment.CommonConfig; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.parse.api.JMeterScriptUtil; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; @@ -82,6 +83,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { private Boolean isRefEnvironment; private String alias; private boolean customizeReq; + private final static String DEF_TIME_OUT = "60000"; @Override public void toHashTree(HashTree tree, List hashTree, MsParameter msParameter) { @@ -134,8 +136,8 @@ public class MsHTTPSamplerProxy extends MsTestElement { } config.compatible(this); this.initConnectAndResponseTimeout(config); - sampler.setConnectTimeout(this.getConnectTimeout() == null ? "60000" : this.getConnectTimeout()); - sampler.setResponseTimeout(this.getResponseTimeout() == null ? "60000" : this.getResponseTimeout()); + sampler.setConnectTimeout(this.getConnectTimeout() == null ? DEF_TIME_OUT : this.getConnectTimeout()); + sampler.setResponseTimeout(this.getResponseTimeout() == null ? DEF_TIME_OUT : this.getResponseTimeout()); HttpConfig httpConfig = getHttpConfig(config); setSamplerPath(config, httpConfig, sampler); // 请求体处理 @@ -246,7 +248,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MsHTTPSamplerProxy proxy = null; - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ApiTestCaseWithBLOBs bloBs = CommonBeanFactory.getBean(ApiTestCaseService.class).get(this.getId()); if (bloBs != null) { this.setProjectId(bloBs.getProjectId()); @@ -258,7 +260,7 @@ public class MsHTTPSamplerProxy extends MsTestElement { } } if (proxy != null) { - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ElementUtil.mergeHashTree(this, proxy.getHashTree()); } else { this.setHashTree(proxy.getHashTree()); @@ -285,12 +287,12 @@ public class MsHTTPSamplerProxy extends MsTestElement { } CommonConfig commonConfig = config.getConfig().get(this.getProjectId()).getCommonConfig(); if (commonConfig != null) { - if (this.getConnectTimeout() == null || StringUtils.equals(this.getConnectTimeout(), "60000")) { + if (this.getConnectTimeout() == null || StringUtils.equals(this.getConnectTimeout(), DEF_TIME_OUT)) { if (commonConfig.getRequestTimeout() != 0) { this.setConnectTimeout(String.valueOf(commonConfig.getRequestTimeout())); } } - if (this.getResponseTimeout() == null || StringUtils.equals(this.getResponseTimeout(), "60000")) { + if (this.getResponseTimeout() == null || StringUtils.equals(this.getResponseTimeout(), DEF_TIME_OUT)) { if (commonConfig.getResponseTimeout() != 0) { this.setResponseTimeout(String.valueOf(commonConfig.getResponseTimeout())); } diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index e1f5e85a33..a1e94acac9 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -3,29 +3,30 @@ package io.metersphere.api.dto.definition.request.sampler; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; -import io.metersphere.api.parse.api.JMeterScriptUtil; import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.environment.GlobalScriptFilterRequest; -import io.metersphere.service.definition.ApiDefinitionService; -import io.metersphere.service.definition.ApiTestCaseService; +import io.metersphere.api.parse.api.JMeterScriptUtil; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.HashTreeUtil; +import io.metersphere.commons.utils.JSONUtil; import io.metersphere.commons.utils.LogUtil; import io.metersphere.constants.RunModeConstants; import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.plugin.core.MsParameter; import io.metersphere.plugin.core.MsTestElement; -import io.metersphere.commons.utils.HashTreeUtil; -import io.metersphere.commons.utils.JSONUtil; +import io.metersphere.service.definition.ApiDefinitionService; +import io.metersphere.service.definition.ApiTestCaseService; import io.metersphere.utils.LoggerUtil; import lombok.Data; import lombok.EqualsAndHashCode; @@ -198,7 +199,7 @@ public class MsJDBCSampler extends MsTestElement { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MsJDBCSampler proxy = null; - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); if (bloBs != null) { @@ -219,7 +220,7 @@ public class MsJDBCSampler extends MsTestElement { } } if (proxy != null) { - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ElementUtil.mergeHashTree(this, proxy.getHashTree()); } else { this.setHashTree(proxy.getHashTree()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index 76d2d5502c..47a0644680 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -16,6 +16,7 @@ import io.metersphere.api.parse.api.JMeterScriptUtil; import io.metersphere.api.parse.scenario.TcpTreeTableDataParser; import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.CommonBeanFactory; @@ -183,7 +184,7 @@ public class MsTCPSampler extends MsTestElement { ObjectMapper mapper = new ObjectMapper(); mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); MsTCPSampler proxy = null; - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class); ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId()); if (bloBs != null) { @@ -204,7 +205,7 @@ public class MsTCPSampler extends MsTestElement { } } if (proxy != null) { - if (StringUtils.equals(this.getRefType(), "CASE")) { + if (StringUtils.equals(this.getRefType(), CommonConstants.CASE)) { ElementUtil.mergeHashTree(this, proxy.getHashTree()); } else { this.setHashTree(proxy.getHashTree()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseParallelExecuteService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseParallelExecuteService.java index dc06c62df8..9e7b56c8d0 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseParallelExecuteService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseParallelExecuteService.java @@ -1,11 +1,12 @@ package io.metersphere.api.exec.api; import io.metersphere.api.exec.queue.DBTestQueue; -import io.metersphere.commons.utils.GenerateHashTreeUtil; import io.metersphere.api.jmeter.JMeterService; import io.metersphere.api.jmeter.utils.SmoothWeighted; import io.metersphere.base.domain.ApiDefinitionExecResultWithBLOBs; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.GenerateHashTreeUtil; import io.metersphere.constants.RunModeConstants; import io.metersphere.dto.BaseSystemConfigDTO; import io.metersphere.dto.JmeterRunRequestDTO; @@ -45,7 +46,7 @@ public class ApiCaseParallelExecuteService { } ApiDefinitionExecResultWithBLOBs result = executeQueue.get(testId); String reportId = result.getId(); - JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testId, reportId, runMode, null); + JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(testId, reportId, runMode); runRequest.setPool(pool); runRequest.setTestPlanReportId(executionQueue.getReportId()); runRequest.setPoolId(config.getResourcePoolId()); @@ -57,7 +58,7 @@ public class ApiCaseParallelExecuteService { runRequest.setRetryEnable(config.isRetryEnable()); Map extendedParameters = new HashMap<>(); - extendedParameters.put("userId", result.getUserId()); + extendedParameters.put(CommonConstants.USER_ID, result.getUserId()); runRequest.setExtendedParameters(extendedParameters); if (MapUtils.isNotEmpty(executionQueue.getDetailMap())) { runRequest.setPlatformUrl(GenerateHashTreeUtil.getPlatformUrl(baseInfo, runRequest, executionQueue.getDetailMap().get(result.getId()))); diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java index 9282728e10..04ef901732 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiCaseSerialService.java @@ -23,6 +23,7 @@ import io.metersphere.base.mapper.ApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.enums.ApiReportStatus; @@ -99,7 +100,7 @@ public class ApiCaseSerialService { ApiDefinitionExecResultWithBLOBs execResult = apiDefinitionExecResultMapper.selectByPrimaryKey(queue.getReportId()); if (execResult != null) { runRequest.setExtendedParameters(new HashMap() {{ - this.put("userId", execResult.getUserId()); + this.put(CommonConstants.USER_ID, execResult.getUserId()); }}); execResult.setStartTime(System.currentTimeMillis()); execResult.setStatus(ApiReportStatus.RUNNING.name()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java index c83c9646b1..59b992971c 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/api/ApiExecuteService.java @@ -22,6 +22,7 @@ import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.ExtendedParameter; import io.metersphere.commons.enums.ApiReportStatus; @@ -254,7 +255,7 @@ public class ApiExecuteService { runRequest.setRunMode(runMode); runRequest.setExtendedParameters(new HashMap() {{ this.put(ExtendedParameter.SYNC_STATUS, request.isSyncResult()); - this.put("userId", SessionUtils.getUser().getId()); + this.put(CommonConstants.USER_ID, SessionUtils.getUser().getId()); this.put("userName", SessionUtils.getUser().getName()); }}); if (CollectionUtils.isNotEmpty(projectIds)) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java index b75ee363ba..f6c6ecc742 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioEnvService.java @@ -18,6 +18,7 @@ import io.metersphere.base.mapper.ApiTestEnvironmentMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.exception.MSException; @@ -32,7 +33,6 @@ import org.apache.commons.collections.CollectionUtils; import org.apache.commons.collections.MapUtils; import org.apache.commons.lang3.StringUtils; import org.json.JSONObject; -import org.springframework.context.annotation.Lazy; import org.springframework.stereotype.Service; import javax.annotation.Resource; @@ -53,7 +53,6 @@ public class ApiScenarioEnvService { private ApiTestEnvironmentMapper apiTestEnvironmentMapper; @Resource private ApiTestCaseMapper apiTestCaseMapper; - @Lazy @Resource private TestPlanApiScenarioMapper testPlanApiScenarioMapper; @Resource @@ -99,7 +98,7 @@ public class ApiScenarioEnvService { if (StringUtils.equals(testElement.getType(), ElementConstants.HTTP_SAMPLER)) { MsHTTPSamplerProxy http = (MsHTTPSamplerProxy) testElement; // 引用用例URL清空 - http.setUrl(StringUtils.equals(testElement.getRefType(), "CASE") ? null : http.getUrl()); + http.setUrl(StringUtils.equals(testElement.getRefType(), CommonConstants.CASE) ? null : http.getUrl()); // 非全路径校验 if (!StringUtils.equalsIgnoreCase(http.getReferenced(), "Created") || (http.getIsRefEnvironment() != null && http.getIsRefEnvironment())) { @@ -108,7 +107,7 @@ public class ApiScenarioEnvService { } } else if (StringUtils.equals(testElement.getType(), ElementConstants.JDBC_SAMPLER) || StringUtils.equals(testElement.getType(), ElementConstants.TCP_SAMPLER)) { if (StringUtils.isEmpty(testElement.getProjectId())) { - if (StringUtils.equals(testElement.getRefType(), "CASE")) { + if (StringUtils.equals(testElement.getRefType(), CommonConstants.CASE)) { ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(testElement.getId()); if (testCase != null) { env.getProjectIds().add(testCase.getProjectId()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java index 9895492153..6ce45300a9 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioParallelService.java @@ -59,7 +59,7 @@ public class ApiScenarioParallelService { protected JmeterRunRequestDTO getJmeterRunRequestDTO(RunScenarioRequest request, String serialReportId, DBTestQueue executionQueue, BaseSystemConfigDTO baseInfo, String reportId, RunModeDataDTO dataDTO) { - JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(dataDTO.getTestId(), StringUtils.isNotEmpty(serialReportId) ? serialReportId : reportId, request.getRunMode(), null); + JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(dataDTO.getTestId(), StringUtils.isNotEmpty(serialReportId) ? serialReportId : reportId, request.getRunMode()); runRequest.setReportType(StringUtils.isNotEmpty(serialReportId) ? RunModeConstants.SET_REPORT.toString() : RunModeConstants.INDEPENDENCE.toString()); runRequest.setQueueId(executionQueue.getId()); runRequest.setTestPlanReportId(request.getTestPlanReportId()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java index a214e6094f..fdd3883b1f 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java +++ b/api-test/backend/src/main/java/io/metersphere/api/exec/scenario/ApiScenarioSerialService.java @@ -12,14 +12,15 @@ import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ApiScenarioReportMapper; import io.metersphere.base.mapper.plan.TestPlanApiScenarioMapper; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.enums.ApiReportStatus; -import io.metersphere.commons.utils.JSON; -import io.metersphere.dto.JmeterRunRequestDTO; -import io.metersphere.environment.service.BaseEnvironmentService; import io.metersphere.commons.utils.GenerateHashTreeUtil; import io.metersphere.commons.utils.HashTreeUtil; -import io.metersphere.utils.LoggerUtil; +import io.metersphere.commons.utils.JSON; import io.metersphere.commons.utils.RequestParamsUtil; +import io.metersphere.dto.JmeterRunRequestDTO; +import io.metersphere.environment.service.BaseEnvironmentService; +import io.metersphere.utils.LoggerUtil; import org.apache.commons.lang3.StringUtils; import org.apache.jorphan.collections.HashTree; import org.springframework.context.annotation.Lazy; @@ -123,7 +124,7 @@ public class ApiScenarioSerialService { report.setCreateTime(System.currentTimeMillis()); report.setUpdateTime(System.currentTimeMillis()); runRequest.setExtendedParameters(new HashMap<>() {{ - this.put("userId", report.getCreateUser()); + this.put(CommonConstants.USER_ID, report.getCreateUser()); }}); apiScenarioReportMapper.updateByPrimaryKey(report); LoggerUtil.info("进入串行模式,准备执行资源:[ " + report.getName() + " ]", report.getId()); diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java index 4faf372385..0dd235f718 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/KafkaListenerTask.java @@ -3,10 +3,11 @@ package io.metersphere.api.jmeter; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.exec.queue.PoolExecBlockingQueueUtil; +import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.ExtendedParameter; +import io.metersphere.dto.ResultDTO; import io.metersphere.service.ApiExecutionQueueService; import io.metersphere.service.TestResultService; -import io.metersphere.commons.constants.ApiRunMode; -import io.metersphere.dto.ResultDTO; import io.metersphere.utils.LoggerUtil; import lombok.Data; import org.apache.commons.collections.CollectionUtils; @@ -54,10 +55,10 @@ public class KafkaListenerTask implements Runnable { if (dto == null) { return; } - if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey("TEST_END") - && (Boolean) dto.getArbitraryData().get("TEST_END")) { + if (dto.getArbitraryData() != null && dto.getArbitraryData().containsKey(ExtendedParameter.TEST_END) + && (Boolean) dto.getArbitraryData().get(ExtendedParameter.TEST_END)) { resultDTOS.add(dto); - LoggerUtil.info("KAFKA消费结果处理状态:" + dto.getArbitraryData().get("TEST_END"), String.valueOf(record.key())); + LoggerUtil.info("KAFKA消费结果处理状态:" + dto.getArbitraryData().get(ExtendedParameter.TEST_END), String.valueOf(record.key())); } // 携带结果 if (CollectionUtils.isNotEmpty(dto.getRequestResults())) { diff --git a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java index 033e0160ad..c9a288bc51 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java +++ b/api-test/backend/src/main/java/io/metersphere/api/jmeter/MsApiBackendListener.java @@ -162,6 +162,4 @@ public class MsApiBackendListener extends AbstractBackendListenerClient implemen } return reportId; } - - } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java b/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java index 0ac7d0b57d..40e10c3441 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/constants/CommonConstants.java @@ -8,5 +8,7 @@ public class CommonConstants { public static final String TRIGGER_MODE = "trigger_mode"; public static final String STATUS = "status"; - + public static final String USER_ID = "userId"; + public static final String METHODS_KEY = "methods"; + public static final String CASE = "CASE"; } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/constants/ExtendedParameter.java b/api-test/backend/src/main/java/io/metersphere/commons/constants/ExtendedParameter.java index 2967c71b46..0c995a916c 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/constants/ExtendedParameter.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/constants/ExtendedParameter.java @@ -4,4 +4,5 @@ public class ExtendedParameter { public static final String SYNC_STATUS = "SYN_RES"; public static final String SAVE_RESULT = "SAVE_RESULT"; public static final String PROJECT_ID = "projectId"; + public static final String TEST_END = "TEST_END"; } diff --git a/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java b/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java index 861d826107..ccbeb4c52a 100644 --- a/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java +++ b/api-test/backend/src/main/java/io/metersphere/commons/utils/RequestParamsUtil.java @@ -14,7 +14,7 @@ import io.metersphere.utils.LoggerUtil; public class RequestParamsUtil { public static JmeterRunRequestDTO init(ApiExecutionQueue executionQueue, ApiExecutionQueueDetail queue, String reportId) { - JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(queue.getTestId(), reportId, executionQueue.getRunMode(), null); + JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(queue.getTestId(), reportId, executionQueue.getRunMode()); runRequest.setRetryEnable(queue.getRetryEnable() == null ? false : queue.getRetryEnable()); runRequest.setRetryNum(queue.getRetryNumber()); runRequest.setReportType(executionQueue.getReportType()); diff --git a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java index 25f2632fbb..9c862ad4c4 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/ApiJMeterFileService.java @@ -65,7 +65,7 @@ public class ApiJMeterFileService { public byte[] downloadJmeterFiles(String runMode, String remoteTestId, String reportId, String reportType, String queueId) { Map planEnvMap = new HashMap<>(); - JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(remoteTestId, reportId, runMode, null); + JmeterRunRequestDTO runRequest = new JmeterRunRequestDTO(remoteTestId, reportId, runMode); runRequest.setReportType(reportType); runRequest.setQueueId(queueId); diff --git a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java index cf2eb6b29e..aac9fa3982 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java @@ -10,6 +10,7 @@ import io.metersphere.base.domain.Project; import io.metersphere.base.mapper.ApiScenarioMapper; import io.metersphere.base.mapper.ProjectMapper; import io.metersphere.base.mapper.ext.ExtApiScenarioMapper; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.ElementConstants; import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.utils.JSON; @@ -45,7 +46,7 @@ public class MsHashTreeService { @Resource private ProjectMapper projectMapper; - public static final String CASE = "CASE"; + public static final String CASE = CommonConstants.CASE; public static final String REFERENCED = "referenced"; public static final String REF = "REF"; public static final String COPY = "Copy"; @@ -77,8 +78,8 @@ public class MsHashTreeService { private static final String PRE = "PRE"; private static final String POST = "POST"; private static final String ASSERTIONS = ElementConstants.ASSERTIONS; - public static final String CUSTOMNUM = "customNum"; - public static final String SHOWCUSTOMNUM = "showCustomNum"; + public static final String CUSTOM_NUM = "customNum"; + public static final String SHOW_CUSTOM_NUM = "showCustomNum"; public void setHashTree(JSONArray hashTree) { // 将引用转成复制 @@ -218,8 +219,8 @@ public class MsHashTreeService { } //获取场景的当前项目是否开启了自定义id ProjectConfig projectApplication = baseProjectApplicationService.getSpecificTypeValue(scenarioWithBLOBs.getProjectId(), "SCENARIO_CUSTOM_NUM"); - element.put(SHOWCUSTOMNUM, projectApplication.getScenarioCustomNum()); - element.put(CUSTOMNUM, scenarioWithBLOBs.getCustomNum()); + element.put(SHOW_CUSTOM_NUM, projectApplication.getScenarioCustomNum()); + element.put(CUSTOM_NUM, scenarioWithBLOBs.getCustomNum()); this.setElement(element, scenarioWithBLOBs.getNum(), enable, scenarioWithBLOBs.getVersionName(), scenarioWithBLOBs.getVersionEnable()); } else { if (StringUtils.equalsIgnoreCase(element.optString(REFERENCED), REF)) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java index 09d8730850..104a97c77d 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionExecResultService.java @@ -9,6 +9,7 @@ import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; import io.metersphere.base.mapper.plan.TestPlanApiCaseMapper; import io.metersphere.commons.constants.ApiRunMode; +import io.metersphere.commons.constants.CommonConstants; import io.metersphere.commons.constants.NoticeConstants; import io.metersphere.commons.constants.TriggerMode; import io.metersphere.commons.enums.ApiReportStatus; @@ -96,14 +97,14 @@ public class ApiDefinitionExecResultService { apiExecutionInfoService.insertExecutionInfo(result); User user = null; if (MapUtils.isNotEmpty(dto.getExtendedParameters())) { - if (dto.getExtendedParameters().containsKey("userId") && dto.getExtendedParameters().containsKey("userName")) { + if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID) && dto.getExtendedParameters().containsKey("userName")) { user = new User() {{ - this.setId(dto.getExtendedParameters().get("userId").toString()); + this.setId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString()); this.setName(dto.getExtendedParameters().get("userName").toString()); }}; result.setUserId(user.getId()); - } else if (dto.getExtendedParameters().containsKey("userId")) { - result.setUserId(dto.getExtendedParameters().get("userId").toString()); + } else if (dto.getExtendedParameters().containsKey(CommonConstants.USER_ID)) { + result.setUserId(dto.getExtendedParameters().get(CommonConstants.USER_ID).toString()); } } //如果是测试计划用例,更新接口用例的上次执行结果 @@ -302,8 +303,8 @@ public class ApiDefinitionExecResultService { LoggerUtil.info("执行结果【 " + item.getName() + " 】入库存储"); if (!StringUtils.startsWithAny(item.getName(), "PRE_PROCESSOR_ENV_", "POST_PROCESSOR_ENV_")) { ApiDefinitionExecResult reportResult = this.editResult(item, dto.getReportId(), dto.getConsole(), dto.getRunMode(), dto.getTestId(), null); - if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey("userId")) { - reportResult.setUserId(String.valueOf(dto.getExtendedParameters().get("userId"))); + if (MapUtils.isNotEmpty(dto.getExtendedParameters()) && dto.getExtendedParameters().containsKey(CommonConstants.USER_ID)) { + reportResult.setUserId(String.valueOf(dto.getExtendedParameters().get(CommonConstants.USER_ID))); } String triggerMode = StringUtils.EMPTY; if (reportResult != null) { @@ -402,7 +403,7 @@ public class ApiDefinitionExecResultService { if (item.getStartTime() >= item.getEndTime()) { saveResult.setEndTime(System.currentTimeMillis()); } - if (StringUtils.isNotEmpty(saveResult.getTriggerMode()) && saveResult.getTriggerMode().equals("CASE")) { + if (StringUtils.isNotEmpty(saveResult.getTriggerMode()) && saveResult.getTriggerMode().equals(CommonConstants.CASE)) { saveResult.setTriggerMode(TriggerMode.MANUAL.name()); } if (batchMapper == null) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java index dfb80c4045..12a443b32a 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiDefinitionService.java @@ -68,7 +68,6 @@ import org.apache.commons.collections4.comparators.FixedOrderComparator; import org.apache.commons.lang3.BooleanUtils; import org.apache.commons.lang3.StringUtils; import org.apache.dubbo.common.URL; -import org.apache.dubbo.common.constants.CommonConstants; import org.apache.ibatis.session.ExecutorType; import org.apache.ibatis.session.SqlSession; import org.apache.ibatis.session.SqlSessionFactory; @@ -142,8 +141,6 @@ public class ApiDefinitionService { private EsbApiParamsMapper esbApiParamsMapper; @Resource private ApiExecutionInfoService apiExecutionInfoService; - @Resource - private ApiCaseExecutionInfoService apiCaseExecutionInfoService; @Lazy @Resource private ApiModuleService apiModuleService; @@ -1608,11 +1605,6 @@ public class ApiDefinitionService { return buildAPIReportResult(result); } - public ApiReportResult getByResultId(String reportId) { - ApiDefinitionExecResultWithBLOBs result = apiDefinitionExecResultMapper.selectByPrimaryKey(reportId); - return buildAPIReportResult(result); - } - public ApiReportResult getReportById(String testId) { ApiDefinitionExecResultWithBLOBs result = apiDefinitionExecResultMapper.selectByPrimaryKey(testId); return buildAPIReportResult(result); @@ -1626,12 +1618,14 @@ public class ApiDefinitionService { reportResult.setStatus(result.getStatus()); String contentStr = result.getContent(); try { - JSONObject content = JSONUtil.parseObject(result.getContent()); - if (StringUtils.isNotEmpty(result.getEnvConfig())) { - content.put("envName", this.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig())); + if (StringUtils.isNotBlank(contentStr)) { + JSONObject content = JSONUtil.parseObject(contentStr); + if (StringUtils.isNotEmpty(result.getEnvConfig())) { + content.put("envName", this.getEnvNameByEnvConfig(result.getProjectId(), result.getEnvConfig())); + } + contentStr = content.toString(); + reportResult.setContent(contentStr); } - contentStr = content.toString(); - reportResult.setContent(contentStr); } catch (Exception e) { LogUtil.error("解析content失败!", e); } @@ -2495,7 +2489,7 @@ public class ApiDefinitionService { }); } else if (StringUtils.isNotEmpty(request.getUserId())) { definitions.forEach(item -> { - DetailColumn column = new DetailColumn(DefinitionReference.definitionColumns.get("userId"), "userId", item.getUserId(), null); + DetailColumn column = new DetailColumn(DefinitionReference.definitionColumns.get(CommonConstants.USER_ID), CommonConstants.USER_ID, item.getUserId(), null); columns.add(column); }); } @@ -2521,26 +2515,11 @@ public class ApiDefinitionService { return null; } - public ApiDefinition selectUrlAndMethodById(String id) { - return extApiDefinitionMapper.selectUrlAndMethodById(id); - } - - public void removeToGcByExample(ApiDefinitionExampleWithOperation apiDefinitionExample) { - List apiList = apiDefinitionMapper.selectByExample(apiDefinitionExample); - List apiIdList = new ArrayList<>(); - apiList.forEach(item -> apiIdList.add(item.getId())); - this.removeToGc(apiIdList); - } - public ApiReportResult getTestPlanApiCaseReport(String testId, String type) { ApiDefinitionExecResultWithBLOBs result = extApiDefinitionExecResultMapper.selectPlanApiMaxResultByTestIdAndType(testId, type); return buildAPIReportResult(result); } - public void initOrderField() { - ServiceUtils.initOrderField(ApiDefinitionWithBLOBs.class, ApiDefinitionMapper.class, extApiDefinitionMapper::selectProjectIds, extApiDefinitionMapper::getIdsOrderByUpdateTime); - } - /** * 用例自定义排序 * diff --git a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiExecutionInfoService.java b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiExecutionInfoService.java index f081be9942..d262a6da43 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/definition/ApiExecutionInfoService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/definition/ApiExecutionInfoService.java @@ -4,7 +4,6 @@ import io.metersphere.base.domain.*; import io.metersphere.base.mapper.ApiCaseExecutionInfoMapper; import io.metersphere.base.mapper.ApiDefinitionMapper; import io.metersphere.base.mapper.ApiExecutionInfoMapper; -import io.metersphere.base.mapper.ApiTestCaseMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionExecResultMapper; import io.metersphere.base.mapper.ext.ExtApiDefinitionMapper; import io.metersphere.base.mapper.ext.ExtApiTestCaseMapper; @@ -36,8 +35,6 @@ public class ApiExecutionInfoService { private ExtTestPlanApiCaseMapper extTestPlanApiCaseMapper; @Resource private ApiDefinitionMapper apiDefinitionMapper; - @Resource - private ApiTestCaseMapper apiTestCaseMapper; @Lazy public void insertExecutionInfo(ApiDefinitionExecResult result) { diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java index def8a05a0d..cf92740aa6 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioReportService.java @@ -264,7 +264,7 @@ public class ApiScenarioReportService { report.setProjectId(projectId); report.setScenarioName(scenarioNames); report.setScenarioId(scenarioIds); - if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) { + if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals(CommonConstants.CASE)) { report.setTriggerMode(TriggerMode.MANUAL.name()); } apiScenarioReportMapper.insert(report); @@ -280,14 +280,14 @@ public class ApiScenarioReportService { if (StringUtils.equals(reportType, RunModeConstants.SET_REPORT.toString())) { return report; } - if (StringUtils.equals(runMode, "CASE")) { + if (StringUtils.equals(runMode, CommonConstants.CASE)) { report.setTriggerMode(TriggerMode.MANUAL.name()); } report.setStatus(status); report.setName(report.getScenarioName() + "-" + DateUtils.getTimeStr(System.currentTimeMillis())); report.setEndTime(System.currentTimeMillis()); report.setUpdateTime(System.currentTimeMillis()); - if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) { + if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals(CommonConstants.CASE)) { report.setTriggerMode(TriggerMode.MANUAL.name()); } apiScenarioReportMapper.updateByPrimaryKeySelective(report); @@ -309,7 +309,7 @@ public class ApiScenarioReportService { report.setStatus(test.getStatus()); report.setUserId(test.getUserId()); report.setExecuteType(test.getExecuteType()); - if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals("CASE")) { + if (StringUtils.isNotEmpty(report.getTriggerMode()) && report.getTriggerMode().equals(CommonConstants.CASE)) { report.setTriggerMode(TriggerMode.MANUAL.name()); } apiScenarioReportMapper.updateByPrimaryKeySelective(report); diff --git a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java index 80858793e4..a1b7a64f98 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/scenario/ApiScenarioService.java @@ -1345,7 +1345,7 @@ public class ApiScenarioService { String context = SessionUtils.getUserId().concat(Translator.get("update_scenario")).concat(":").concat(apiScenario.getName()); Map paramMap = new HashMap<>(); getParamMap(paramMap, apiScenario.getProjectId(), SessionUtils.getUserId(), apiScenario.getId(), apiScenario.getName(), apiScenario.getCreateUser()); - paramMap.put("userId", apiScenario.getUserId()); + paramMap.put(CommonConstants.USER_ID, apiScenario.getUserId()); NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiScenario.getId()).subject(Translator.get("scenario_update_notice")).paramMap(paramMap).excludeSelf(true).event(NoticeConstants.Event.UPDATE).build(); noticeSendService.send(NoticeConstants.TaskType.API_AUTOMATION_TASK, noticeModel); } @@ -1354,7 +1354,7 @@ public class ApiScenarioService { String context = SessionUtils.getUserId().concat(Translator.get("create_scenario")).concat(":").concat(apiScenario.getName()); Map paramMap = new HashMap<>(); getParamMap(paramMap, apiScenario.getProjectId(), SessionUtils.getUserId(), apiScenario.getId(), apiScenario.getName(), apiScenario.getCreateUser()); - paramMap.put("userId", apiScenario.getUserId()); + paramMap.put(CommonConstants.USER_ID, apiScenario.getUserId()); NoticeModel noticeModel = NoticeModel.builder().operator(SessionUtils.getUserId()).context(context).testId(apiScenario.getId()).subject(Translator.get("scenario_create_notice")).paramMap(paramMap).excludeSelf(true).event(NoticeConstants.Event.CREATE).build(); noticeSendService.send(NoticeConstants.TaskType.API_AUTOMATION_TASK, noticeModel); } @@ -1563,7 +1563,7 @@ public class ApiScenarioService { // 检测引用对象是否存在,若果不存在则改成复制对象 String refType = object.optString("refType"); if (StringUtils.isNotEmpty(refType)) { - if (refType.equals("CASE")) { + if (refType.equals(CommonConstants.CASE)) { if (object.optJSONArray(ElementConstants.HASH_TREE) == null || object.optJSONArray(ElementConstants.HASH_TREE).length() == 0) { ApiTestCaseInfo model = extApiTestCaseMapper.selectApiCaseInfoByPrimaryKey(object.optString("id")); if (model != null) { @@ -2127,7 +2127,7 @@ public class ApiScenarioService { // 检测引用对象是否存在,若果不存在则改成复制对象 String refType = object.optString("refType"); if (StringUtils.isNotEmpty(refType)) { - if (refType.equals("CASE")) { + if (refType.equals(CommonConstants.CASE)) { ApiScenarioImportUtil.checkCase(object, versionId, projectId, apiScenarioParamDto); } else { checkAutomation(object); diff --git a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java index c819172dc3..e594a13d7d 100644 --- a/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java +++ b/framework/sdk-parent/jmeter/src/main/java/io/metersphere/dto/JmeterRunRequestDTO.java @@ -93,6 +93,15 @@ public class JmeterRunRequestDTO { public JmeterRunRequestDTO() { } + public JmeterRunRequestDTO(String testId, String reportId, String runMode) { + this.testId = testId; + this.reportId = reportId; + this.runMode = runMode; + this.reportType = RunModeConstants.INDEPENDENCE.name(); + this.pool = new BooleanPool(); + this.extendedParameters = new LinkedHashMap<>(); + } + public JmeterRunRequestDTO(String testId, String reportId, String runMode, HashTree hashTree) { this.testId = testId; this.reportId = reportId;