From 87e917578b60538bbb1346fa070b66a3e0b2a601 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Thu, 24 Dec 2020 10:31:20 +0800 Subject: [PATCH] =?UTF-8?q?fix(=E6=8E=A5=E5=8F=A3=E8=87=AA=E5=8A=A8?= =?UTF-8?q?=E5=8C=96):=20=E4=BF=AE=E5=A4=8D=E8=AF=B7=E6=B1=82=E5=8F=82?= =?UTF-8?q?=E6=95=B0=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../request/sampler/MsHTTPSamplerProxy.java | 26 +++---------------- .../api/service/ApiAutomationService.java | 6 ----- 2 files changed, 4 insertions(+), 28 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java index 0edce5e72d..44c7cbdea7 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/sampler/MsHTTPSamplerProxy.java @@ -206,35 +206,17 @@ public class MsHTTPSamplerProxy extends MsTestElement { this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue -> keyValueMap.put(keyValue.getName(), keyValue.getValue()) ); - // 这块是否使用jmeter自身机制? - Map pubKeyValueMap = new HashMap<>(); - if (config != null && config.getVariables() != null) { - config.getVariables().stream().forEach(keyValue -> { - pubKeyValueMap.put(keyValue.getName(), keyValue.getValue()); - }); - } - for (String key : keyValueMap.keySet()) { - if (keyValueMap.get(key) != null && keyValueMap.get(key).startsWith("$")) { - String pubKey = keyValueMap.get(key).substring(2, keyValueMap.get(key).length() - 1); - keyValueMap.put(key, pubKeyValueMap.get(pubKey)); - } - } - - Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})"); - Matcher m = p.matcher(path); - StringBuffer sb = new StringBuffer(); try { + Pattern p = Pattern.compile("(\\{)([\\w]+)(\\})"); + Matcher m = p.matcher(path); while (m.find()) { String group = m.group(2); - //替换并且把替换好的值放到sb中 - m.appendReplacement(sb, keyValueMap.get(group)); + path = path.replace("{" + group + "}", keyValueMap.get(group)); } } catch (Exception ex) { ex.printStackTrace(); } - //把符合的数据追加到sb尾 - m.appendTail(sb); - return sb.toString(); + return path; } private String getPostQueryParameters(String path) { diff --git a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java index bfb5494e3b..e3d94e03af 100644 --- a/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java +++ b/backend/src/main/java/io/metersphere/api/service/ApiAutomationService.java @@ -30,9 +30,6 @@ import io.metersphere.service.ScheduleService; import io.metersphere.track.dto.TestPlanDTO; import io.metersphere.track.request.testcase.ApiCaseRelevanceRequest; import io.metersphere.track.request.testcase.QueryTestPlanRequest; -import io.metersphere.track.request.testcase.TestPlanApiCaseBatchRequest; -import io.metersphere.track.service.TestPlanApiCaseService; -import io.metersphere.track.service.TestPlanScenarioCaseService; import org.apache.commons.collections.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.ibatis.session.ExecutorType; @@ -46,8 +43,6 @@ import org.springframework.web.multipart.MultipartFile; import javax.annotation.Resource; import java.util.*; -import java.util.stream.Collectors; -import java.util.stream.Stream; @Service @Transactional(rollbackFor = Exception.class) @@ -339,7 +334,6 @@ public class ApiAutomationService { ParameterConfig config = new ParameterConfig(); config.setConfig(envConfig); HashTree hashTree = request.getTestElement().generateHashTree(config); - request.getTestElement().getJmx(hashTree); // 调用执行方法 jMeterService.runDefinition(request.getId(), hashTree, request.getReportId(), ApiRunMode.SCENARIO.name()); createAPIScenarioReportResult(request.getId(), ReportTriggerMode.MANUAL.name(), request.getExecuteType(), request.getProjectId(),