fix(接口测试): 修复历史数据模块匹配错误问题

This commit is contained in:
fit2-zhao 2022-01-04 10:28:05 +08:00 committed by fit2-zhao
parent b1c58eb655
commit aee7a7b501
1 changed files with 20 additions and 45 deletions

View File

@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.ObjectMapper;
import io.metersphere.api.dto.definition.parse.JMeterScriptUtil; import io.metersphere.api.dto.definition.parse.JMeterScriptUtil;
import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ElementUtil;
import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
import io.metersphere.api.dto.definition.request.auth.MsAuthManager; import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager; import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager;
import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor; import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor;
@ -38,7 +37,6 @@ import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.exception.MSException; import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory; import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.FileUtils; import io.metersphere.commons.utils.FileUtils;
import io.metersphere.commons.utils.HashTreeUtil;
import io.metersphere.commons.utils.LogUtil; import io.metersphere.commons.utils.LogUtil;
import io.metersphere.constants.RunModeConstants; import io.metersphere.constants.RunModeConstants;
import io.metersphere.jmeter.utils.ScriptEngineUtils; import io.metersphere.jmeter.utils.ScriptEngineUtils;
@ -282,20 +280,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
this.setScript(httpConfig, httpSamplerTree, config, false); this.setScript(httpConfig, httpSamplerTree, config, false);
} }
HashTreeUtil hashTreeUtil = new HashTreeUtil();
//增加误报断言
if (httpConfig != null) {
if (CollectionUtils.isNotEmpty(httpConfig.getErrorReportAssertions())) {
for (MsAssertions assertion : httpConfig.getErrorReportAssertions()) {
assertion.toHashTree(httpSamplerTree, assertion.getHashTree(), config);
}
}
if (CollectionUtils.isNotEmpty(httpConfig.getAssertions())) {
for (MsAssertions assertion : httpConfig.getAssertions()) {
assertion.toHashTree(httpSamplerTree, assertion.getHashTree(), config);
}
}
}
if (CollectionUtils.isNotEmpty(hashTree)) { if (CollectionUtils.isNotEmpty(hashTree)) {
for (MsTestElement el : hashTree) { for (MsTestElement el : hashTree) {
if (el.getEnvironmentId() == null) { if (el.getEnvironmentId() == null) {
@ -305,10 +289,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
el.setEnvironmentId(this.getEnvironmentId()); el.setEnvironmentId(this.getEnvironmentId());
} }
} }
if (el instanceof MsAssertions) {
//断言设置需要和全局断言误报进行去重
el = hashTreeUtil.duplicateRegexInAssertions(httpConfig.getAssertions(), (MsAssertions) el);
}
el.toHashTree(httpSamplerTree, el.getHashTree(), config); el.toHashTree(httpSamplerTree, el.getHashTree(), config);
} }
} }
@ -406,10 +386,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
httpConfig.setPreProcessor(environmentConfig.getPreProcessor()); httpConfig.setPreProcessor(environmentConfig.getPreProcessor());
httpConfig.setPostProcessor(environmentConfig.getPostProcessor()); httpConfig.setPostProcessor(environmentConfig.getPostProcessor());
httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig()); httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig());
httpConfig.setAssertions(environmentConfig.getAssertions());
if (environmentConfig.isUseErrorCode()) {
httpConfig.setErrorReportAssertions(HashTreeUtil.getErrorReportByProjectId(this.getProjectId()));
}
return httpConfig; return httpConfig;
} }
} }
@ -429,13 +405,12 @@ public class MsHTTPSamplerProxy extends MsTestElement {
this.useEnvironment = config.getConfig().get(this.getProjectId()).getApiEnvironmentid(); this.useEnvironment = config.getConfig().get(this.getProjectId()).getApiEnvironmentid();
} }
String url = httpConfig.getProtocol() + "://" + httpConfig.getSocket(); String url = httpConfig.getProtocol() + "://" + httpConfig.getSocket();
// 补充如果是完整URL 则用自身URL
if (isUrl()) {
// 补充如果是完整URL 则用自身URL
if (StringUtils.isNotEmpty(this.getUrl()) && ElementUtil.isURL(this.getUrl())) { if (StringUtils.isNotEmpty(this.getUrl()) && ElementUtil.isURL(this.getUrl())) {
url = this.getUrl(); url = this.getUrl();
} }
if (isUrl()) {
if (this.isCustomizeReq()) { if (this.isCustomizeReq()) {
url = this.getUrl(); url = this.getUrl();
sampler.setProperty("HTTPSampler.path", url); sampler.setProperty("HTTPSampler.path", url);
@ -657,9 +632,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
return true; return true;
} }
if (StringUtils.isNotEmpty(this.getUrl()) && ElementUtil.isURL(this.getUrl())) {
return true;
}
return false; return false;
} }
@ -836,6 +808,8 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
} else { } else {
apiDefinition = apiDefinitionService.get(this.getId()); apiDefinition = apiDefinitionService.get(this.getId());
apiDefinition = apiDefinition == null ? apiDefinitionService.get(this.getName()) : apiDefinition;
if (apiDefinition == null) {
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.get(this.getId()); ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.get(this.getId());
if (apiTestCaseWithBLOBs == null) { if (apiTestCaseWithBLOBs == null) {
apiTestCaseWithBLOBs = apiTestCaseService.get(this.getName()); apiTestCaseWithBLOBs = apiTestCaseService.get(this.getName());
@ -853,6 +827,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
} }
} }
} }
}
if (apiDefinition != null) { if (apiDefinition != null) {
HttpConfig config = httpConfig.getModuleCondition(apiDefinition.getModuleId(), item); HttpConfig config = httpConfig.getModuleCondition(apiDefinition.getModuleId(), item);
if (config != null) { if (config != null) {