fix(接口测试): 修复导入JMX脚本中对于测试计划变量处理错误问题

--bug=1022923 --user=赵勇 【接口测试】TestPlan中带变量的jmx文件导入系统后,执行报错 https://www.tapd.cn/55049933/s/1334858
This commit is contained in:
fit2-zhao 2023-02-14 09:58:26 +08:00 committed by fit2-zhao
parent b5960f43bd
commit 4fa0d70196
2 changed files with 11 additions and 26 deletions

View File

@ -22,7 +22,6 @@ 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.BooleanUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
@ -226,7 +225,7 @@ public class ParameterConfig extends MsParameter {
}
public void margeVariables(List<ScenarioVariable> variables, List<ScenarioVariable> transferVariables) {
if (CollectionUtils.isNotEmpty(transferVariables)) {
if (CollectionUtils.isNotEmpty(transferVariables) && CollectionUtils.isNotEmpty(variables)) {
List<ScenarioVariable> constants = variables.stream()
.filter(ScenarioVariable::isConstantValid).collect(Collectors.toList());
@ -252,22 +251,4 @@ public class ParameterConfig extends MsParameter {
});
}
}
public void margeParentVariables(List<ScenarioVariable> variables, MsTestElement parent) {
// 取出父级场景且父场景不是顶级场景
MsScenario scenario = getScenario(parent);
if (scenario == null || BooleanUtils.isFalse(scenario.getMixEnable()) || CollectionUtils.isEmpty(scenario.getVariables())) {
return;
}
this.margeVariables(variables, scenario.getVariables());
}
private MsScenario getScenario(MsTestElement parent) {
if (parent != null && parent instanceof MsScenario) {
return parent.getParent() != null ? (MsScenario) parent : null;
} else if (parent != null && parent.getParent() != null) {
getScenario(parent.getParent());
}
return null;
}
}

View File

@ -3,10 +3,12 @@ package io.metersphere.api.dto.shell.filter;
import io.metersphere.commons.constants.ElementConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.plugin.core.utils.LogUtil;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.StringUtils;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.util.List;
public class ScriptFilter {
@ -17,12 +19,14 @@ public class ScriptFilter {
private static void blackList(StringBuffer buffer, String script, String path) {
try {
InputStream in = ScriptFilter.class.getResourceAsStream(path);
List<String> bks = IOUtils.readLines(in);
bks.forEach(item -> {
if (script.contains(item) && script.indexOf(item) != -1) {
buffer.append(item).append(",");
}
});
List<String> bks = IOUtils.readLines(in, Charset.defaultCharset());
if (CollectionUtils.isNotEmpty(bks)) {
bks.forEach(item -> {
if (script.contains(item) && script.indexOf(item) != -1) {
buffer.append(item).append(",");
}
});
}
} catch (Exception ex) {
LogUtil.error(ex.getMessage());
}