From c1317bed18622cf21f7cb3d511c9164638fdc379 Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Wed, 11 Jan 2023 17:21:49 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E5=AE=9A=E4=B9=89):=20?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E8=87=AA=E5=AE=9A=E4=B9=89=E8=AF=B7=E6=B1=82?= =?UTF-8?q?=E8=BF=90=E8=A1=8C=E6=97=B6=E6=8F=90=E7=A4=BA=E9=80=89=E7=8E=AF?= =?UTF-8?q?=E5=A2=83=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1021889 --user=王孝刚 【接口测试】场景中仅有一个自定义sql请求-未勾选引用环境-调试时仍提示选择一个运行环境 https://www.tapd.cn/55049933/s/1326341 --- .../request/sampler/MsTCPSampler.java | 1 + .../exec/scenario/ApiScenarioEnvService.java | 63 ++++++++++++------- .../scenario/common/CustomizeReqInfo.vue | 12 ++++ .../components/response/ResponseResult.vue | 6 +- 4 files changed, 58 insertions(+), 24 deletions(-) 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 45f033856a..47ecd17556 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 @@ -78,6 +78,7 @@ public class MsTCPSampler extends MsTestElement { private String jsonDataStruct; private String rawDataStruct; private boolean customizeReq; + private Boolean isRefEnvironment; @Override public void toHashTree(HashTree tree, List hashTree, MsParameter msParameter) { 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 0ab6797e00..2b6fa4155d 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 @@ -9,6 +9,8 @@ import io.metersphere.api.dto.definition.request.ElementUtil; import io.metersphere.api.dto.definition.request.MsScenario; import io.metersphere.api.dto.definition.request.ParameterConfig; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; +import io.metersphere.api.dto.definition.request.sampler.MsJDBCSampler; +import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler; import io.metersphere.api.dto.plan.TestPlanApiScenarioInfoDTO; import io.metersphere.api.dto.scenario.environment.EnvironmentConfig; import io.metersphere.api.dto.scenario.environment.item.MsScenarioEnv; @@ -69,24 +71,32 @@ public class ApiScenarioEnvService { // 过滤掉禁用的步骤 hashTree = hashTree.stream().filter(item -> item.isEnable()).collect(Collectors.toList()); } + List hasFullUrlList = new ArrayList<>(); for (MsTestElement testElement : hashTree) { - this.formatElement(testElement, env); - if (CollectionUtils.isNotEmpty(testElement.getHashTree())) { - getHashTree(testElement.getHashTree(), env); + this.formatElement(testElement, env, hasFullUrlList); + if (CollectionUtils.isNotEmpty(testElement.getHashTree()) && !hasFullUrlList.contains(false)) { + getHashTree(testElement.getHashTree(), env, hasFullUrlList); + } + if (hasFullUrlList.contains(false)) { + env.setFullUrl(false); + break; } } return env; } - private void getHashTree(List tree, ScenarioEnv env) { + private void getHashTree(List tree, ScenarioEnv env, List hasFullUrlList) { try { // 过滤掉禁用的步骤 tree = tree.stream().filter(item -> item.isEnable()).collect(Collectors.toList()); for (MsTestElement element : tree) { - this.formatElement(element, env); - if (CollectionUtils.isNotEmpty(element.getHashTree())) { - getHashTree(element.getHashTree(), env); + this.formatElement(element, env, hasFullUrlList); + if (CollectionUtils.isNotEmpty(element.getHashTree()) && !hasFullUrlList.contains(false)) { + getHashTree(element.getHashTree(), env, hasFullUrlList); + } + if (hasFullUrlList.contains(false)) { + break; } } } catch (Exception e) { @@ -94,7 +104,7 @@ public class ApiScenarioEnvService { } } - private void formatElement(MsTestElement testElement, ScenarioEnv env) { + private void formatElement(MsTestElement testElement, ScenarioEnv env, List hasFullUrlList) { if (StringUtils.equals(MsTestElementConstants.REF.name(), testElement.getReferenced())) { if (StringUtils.equals(testElement.getType(), ElementConstants.HTTP_SAMPLER)) { MsHTTPSamplerProxy http = (MsHTTPSamplerProxy) testElement; @@ -105,7 +115,7 @@ public class ApiScenarioEnvService { if (!StringUtils.equalsIgnoreCase(http.getReferenced(), ElementConstants.STEP_CREATED) || (http.getIsRefEnvironment() != null && http.getIsRefEnvironment())) { env.getProjectIds().add(http.getProjectId()); - env.setFullUrl(false); + hasFullUrlList.add(false); } } else if (StringUtils.equals(testElement.getType(), ElementConstants.JDBC_SAMPLER) || StringUtils.equals(testElement.getType(), ElementConstants.TCP_SAMPLER)) { @@ -114,18 +124,18 @@ public class ApiScenarioEnvService { ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(testElement.getId()); if (testCase != null) { env.getProjectIds().add(testCase.getProjectId()); - env.setFullUrl(false); + hasFullUrlList.add(false); } } else { ApiDefinition apiDefinition = apiDefinitionService.get(testElement.getId()); if (apiDefinition != null) { env.getProjectIds().add(apiDefinition.getProjectId()); - env.setFullUrl(false); + hasFullUrlList.add(false); } } } else { env.getProjectIds().add(testElement.getProjectId()); - env.setFullUrl(false); + hasFullUrlList.add(false); } } else if (StringUtils.equals(testElement.getType(), ElementConstants.SCENARIO) && StringUtils.isEmpty(testElement.getProjectId())) { ApiScenarioWithBLOBs apiScenario = apiScenarioMapper.selectByPrimaryKey(testElement.getId()); @@ -141,18 +151,14 @@ public class ApiScenarioEnvService { if (StringUtils.equals(testElement.getType(), ElementConstants.HTTP_SAMPLER)) { // 校验是否是全路径 MsHTTPSamplerProxy httpSamplerProxy = (MsHTTPSamplerProxy) testElement; - if (httpSamplerProxy.isCustomizeReq()) { - env.getProjectIds().add(httpSamplerProxy.getProjectId()); - env.setFullUrl(httpSamplerProxy.getIsRefEnvironment() == null ? true : !httpSamplerProxy.getIsRefEnvironment()); - } else if (!StringUtils.equalsIgnoreCase(httpSamplerProxy.getReferenced(), ElementConstants.STEP_CREATED) || (httpSamplerProxy.getIsRefEnvironment() != null && httpSamplerProxy.getIsRefEnvironment())) { - env.getProjectIds().add(httpSamplerProxy.getProjectId()); - env.setFullUrl(false); - } + checkCustomEnv(env, httpSamplerProxy.isCustomizeReq(), httpSamplerProxy.getProjectId(), httpSamplerProxy.getIsRefEnvironment(), httpSamplerProxy.getReferenced(), hasFullUrlList); - } else if (StringUtils.equals(testElement.getType(), ElementConstants.JDBC_SAMPLER) - || StringUtils.equals(testElement.getType(), ElementConstants.TCP_SAMPLER)) { - env.getProjectIds().add(testElement.getProjectId()); - env.setFullUrl(false); + } else if (StringUtils.equals(testElement.getType(), ElementConstants.TCP_SAMPLER)) { + MsTCPSampler tcpSampler = (MsTCPSampler) testElement; + checkCustomEnv(env, tcpSampler.isCustomizeReq(), tcpSampler.getProjectId(), tcpSampler.getIsRefEnvironment(), tcpSampler.getReferenced(), hasFullUrlList); + } else if (StringUtils.equals(testElement.getType(), ElementConstants.JDBC_SAMPLER)) { + MsJDBCSampler jdbcSampler = (MsJDBCSampler) testElement; + checkCustomEnv(env, jdbcSampler.isCustomizeReq(), jdbcSampler.getProjectId(), jdbcSampler.getIsRefEnvironment(), jdbcSampler.getReferenced(), hasFullUrlList); } } if (StringUtils.equals(testElement.getType(), ElementConstants.SCENARIO) @@ -161,6 +167,17 @@ public class ApiScenarioEnvService { } } + private void checkCustomEnv(ScenarioEnv env, boolean customizeReq, String projectId, Boolean isRefEnvironment, String referenced, List hasFullUrlList) { + if (customizeReq) { + env.getProjectIds().add(projectId); + hasFullUrlList.add(isRefEnvironment == null ? true : !isRefEnvironment); + } else if (!StringUtils.equalsIgnoreCase(referenced, ElementConstants.STEP_CREATED) + || (isRefEnvironment != null && isRefEnvironment)) { + env.getProjectIds().add(projectId); + hasFullUrlList.add(false); + } + } + /** * 设置场景的运行环境 环境组/环境JSON * diff --git a/api-test/frontend/src/business/automation/scenario/common/CustomizeReqInfo.vue b/api-test/frontend/src/business/automation/scenario/common/CustomizeReqInfo.vue index b0c8576297..a200c4bc04 100644 --- a/api-test/frontend/src/business/automation/scenario/common/CustomizeReqInfo.vue +++ b/api-test/frontend/src/business/automation/scenario/common/CustomizeReqInfo.vue @@ -72,6 +72,18 @@ + + + + {{ $t('api_test.request.refer_to_environment') }} + + + diff --git a/api-test/frontend/src/business/definition/components/response/ResponseResult.vue b/api-test/frontend/src/business/definition/components/response/ResponseResult.vue index 7320ce1a3e..ff3f83916d 100644 --- a/api-test/frontend/src/business/definition/components/response/ResponseResult.vue +++ b/api-test/frontend/src/business/definition/components/response/ResponseResult.vue @@ -179,7 +179,11 @@ export default { computed: { isSqlType() { return ( - this.currentProtocol === 'SQL' && this.response.responseResult.responseCode === '200' && this.mode === 'table' + this.currentProtocol === 'SQL' + && this.response + && this.response.responseResult + && this.response.responseResult.responseCode === '200' + && this.mode === 'table' ); }, responseResult() {