fix(接口测试): 修复jdbc请求头变量未生效问题

--bug=1013349 --user=赵勇 【接口测试】github#13765,sql前置脚本自定义变量,取随机值失败 https://www.tapd.cn/55049933/s/1162421
This commit is contained in:
fit2-zhao 2022-05-23 18:50:50 +08:00 committed by f2c-ci-robot[bot]
parent 6b017b52c0
commit 07c8511482
4 changed files with 16 additions and 3 deletions

View File

@ -26,6 +26,7 @@ import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.FileUtils;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.constants.RunModeConstants;
import io.metersphere.jmeter.utils.ScriptEngineUtils;
import io.metersphere.plugin.core.MsParameter;
import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.service.EnvironmentGroupProjectService;
@ -773,4 +774,16 @@ public class ElementUtil {
}
return elementList;
}
public static String getEvlValue(String evlValue) {
try {
if (StringUtils.startsWith(evlValue, "@")) {
return ScriptEngineUtils.calculate(evlValue);
} else {
return ScriptEngineUtils.buildFunctionCallString(evlValue);
}
} catch (Exception e) {
return evlValue;
}
}
}

View File

@ -239,7 +239,7 @@ public class MsJDBCPostProcessor extends MsTestElement {
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
arguments.addArgument(keyValue.getName(), ElementUtil.getEvlValue(keyValue.getValue()), "=")
);
return arguments;
}

View File

@ -239,7 +239,7 @@ public class MsJDBCPreProcessor extends MsTestElement {
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
variables.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
arguments.addArgument(keyValue.getName(), ElementUtil.getEvlValue(keyValue.getValue()), "=")
);
return arguments;
}

View File

@ -205,7 +205,7 @@ public class MsJDBCSampler extends MsTestElement {
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) {
config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
arguments.addArgument(keyValue.getName(), ElementUtil.getEvlValue(keyValue.getValue()), "=")
);
// 清空变量防止重复添加
config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().clear();