From cacef79a5c6709e2167202a3ff1514d858a56a35 Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Fri, 14 Jan 2022 18:45:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E8=AF=AF=E6=8A=A5=E5=BA=93):=20TCP?= =?UTF-8?q?=E3=80=81SQL=E8=AF=B7=E6=B1=82=E5=A2=9E=E5=8A=A0=E8=AF=AF?= =?UTF-8?q?=E6=8A=A5=E5=BA=93=E7=AD=9B=E9=80=89=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit TCP、SQL请求增加误报库筛选功能 --- .../api/dto/ErrorReportLibraryParseDTO.java | 7 +----- .../request/sampler/MsJDBCSampler.java | 24 +++++++++++++++++++ .../request/sampler/MsTCPSampler.java | 24 +++++++++++++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java b/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java index d12a9efb3f..ab2cc3e514 100644 --- a/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java +++ b/backend/src/main/java/io/metersphere/api/dto/ErrorReportLibraryParseDTO.java @@ -20,12 +20,7 @@ public class ErrorReportLibraryParseDTO { public String getErrorCodeStr(){ if(CollectionUtils.isNotEmpty(this.errorCodeList)){ String errorCodeStr = StringUtils.join(this.errorCodeList,";"); - //控制字符串长度 - if(errorCodeStr.length() > 10){ - return errorCodeStr.substring(0,10)+"..."; - }else { - return errorCodeStr; - } + return errorCodeStr; }else { return ""; } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java index 1e91ae1055..e1194d2fce 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsJDBCSampler.java @@ -10,6 +10,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import io.metersphere.api.dto.definition.parse.JMeterScriptUtil; import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.definition.request.assertions.MsAssertions; import io.metersphere.api.dto.scenario.DatabaseConfig; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; @@ -23,6 +24,7 @@ import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs; 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.LogUtil; import io.metersphere.constants.RunModeConstants; import io.metersphere.plugin.core.MsParameter; @@ -154,6 +156,21 @@ public class MsJDBCSampler extends MsTestElement { tree.add(envArguments); } + //增加误报、全局断言 + if (envConfig != null) { + if (envConfig.isUseErrorCode()) { + List errorReportAssertion = HashTreeUtil.getErrorReportByProjectId(this.getProjectId()); + for (MsAssertions assertion : errorReportAssertion) { + assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config); + } + } + if (CollectionUtils.isNotEmpty(envConfig.getAssertions())) { + for (MsAssertions assertion : envConfig.getAssertions()) { + assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config); + } + } + } + //处理全局前后置脚本(步骤内) String enviromentId = this.getEnvironmentId(); if (enviromentId == null) { @@ -162,8 +179,15 @@ public class MsJDBCSampler extends MsTestElement { //根据配置将脚本放置在私有脚本之前 JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), enviromentId, config, false); + HashTreeUtil hashTreeUtil = new HashTreeUtil(); + if (CollectionUtils.isNotEmpty(hashTree)) { + EnvironmentConfig finalEnvConfig = envConfig; hashTree.forEach(el -> { + if (el instanceof MsAssertions) { + //断言设置需要和全局断言、误报进行去重 + el = hashTreeUtil.duplicateRegexInAssertions(finalEnvConfig.getAssertions(), (MsAssertions) el); + } el.toHashTree(samplerHashTree, el.getHashTree(), config); }); } diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java index cddc101bfb..26f09c41d6 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsTCPSampler.java @@ -12,6 +12,7 @@ import io.metersphere.api.dto.automation.TcpTreeTableDataStruct; import io.metersphere.api.dto.definition.parse.JMeterScriptUtil; import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.ParameterConfig; +import io.metersphere.api.dto.definition.request.assertions.MsAssertions; import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.scenario.KeyValue; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; @@ -22,6 +23,7 @@ import io.metersphere.base.domain.ApiDefinitionWithBLOBs; import io.metersphere.base.domain.ApiTestCaseWithBLOBs; import io.metersphere.commons.constants.MsTestElementConstants; import io.metersphere.commons.utils.CommonBeanFactory; +import io.metersphere.commons.utils.HashTreeUtil; import io.metersphere.commons.utils.LogUtil; import io.metersphere.jmeter.utils.ScriptEngineUtils; import io.metersphere.plugin.core.MsParameter; @@ -149,6 +151,21 @@ public class MsTCPSampler extends MsTestElement { samplerHashTree.add(tcpPreProcessor.getJSR223PreProcessor()); } + //增加误报、全局断言 + if (envConfig != null) { + if (envConfig.isUseErrorCode()) { + List errorReportAssertion =HashTreeUtil.getErrorReportByProjectId(this.getProjectId()); + for (MsAssertions assertion : errorReportAssertion) { + assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config); + } + } + if (CollectionUtils.isNotEmpty(envConfig.getAssertions())) { + for (MsAssertions assertion : envConfig.getAssertions()) { + assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config); + } + } + } + //处理全局前后置脚本(步骤内) String enviromentId = this.getEnvironmentId(); if (enviromentId == null) { @@ -157,8 +174,15 @@ public class MsTCPSampler extends MsTestElement { //根据配置将脚本放置在私有脚本之前 JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.TCP.name(), enviromentId, config, false); + HashTreeUtil hashTreeUtil = new HashTreeUtil(); + if (CollectionUtils.isNotEmpty(hashTree)) { + EnvironmentConfig finalEnvConfig = envConfig; hashTree.forEach(el -> { + if (el instanceof MsAssertions) { + //断言设置需要和全局断言、误报进行去重 + el = hashTreeUtil.duplicateRegexInAssertions(finalEnvConfig.getAssertions(), (MsAssertions) el); + } el.toHashTree(samplerHashTree, el.getHashTree(), config); }); }