refactor(接口测试): 前后置脚本解析添加项目ID参数

This commit is contained in:
AgAngle 2024-02-18 19:01:22 +08:00 committed by Craftsman
parent aeaa61c4f3
commit 3697ddd90c
3 changed files with 29 additions and 10 deletions

View File

@ -60,6 +60,7 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter<MsC
/**
* 添加断言
*
* @param tree
* @param element
* @param config
@ -82,6 +83,7 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter<MsC
/**
* 是否忽略状态码
*
* @param assertions
* @return
*/
@ -99,7 +101,7 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter<MsC
}
private void addProcessors(HashTree tree, MsCommonElement msCommonElement, ParameterConfig config,
EnvironmentInfoDTO envInfo, boolean isPre) {
EnvironmentInfoDTO envInfo, boolean isPre) {
MsProcessorConfig processorConfig = isPre ? msCommonElement.getPreProcessorConfig() : msCommonElement.getPostProcessorConfig();
if (processorConfig == null || processorConfig.getProcessors() == null) {
return;
@ -128,15 +130,22 @@ public class MsCommonElementConverter extends AbstractJmeterElementConverter<MsC
isPre ? MsProcessorConverterFactory::getPreConverter : MsProcessorConverterFactory::getPostConverter;
// 处理环境中步骤前处理器
beforeStepProcessors.forEach(processor ->
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config));
beforeStepProcessors.forEach(processor -> {
processor.setProjectId(msCommonElement.getProjectId());
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config);
});
processorConfig.getProcessors()
.forEach(processor -> getConverterFunc.apply(processor.getClass()).parse(tree, processor, config));
.forEach(processor -> {
processor.setProjectId(msCommonElement.getProjectId());
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config);
});
// 处理环境中步骤后处理器
afterStepProcessors.forEach(processor ->
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config));
afterStepProcessors.forEach(processor -> {
processor.setProjectId(msCommonElement.getProjectId());
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config);
});
}
private void addEnvProcessors(EnvProcessorConfig envProcessorConfig,

View File

@ -59,6 +59,7 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
/**
* 添加场景断言
*
* @param tree
* @param msScenario
* @param config
@ -130,8 +131,10 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
isPre ? MsProcessorConverterFactory::getPreConverter : MsProcessorConverterFactory::getPostConverter;
// 添加前后置
envScenarioProcessors.forEach(processor ->
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config));
envScenarioProcessors.forEach(processor -> {
processor.setProjectId(msScenario.getProjectId());
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config);
});
}
private void addScenarioProcessor(HashTree tree, MsScenario msScenario, ParameterConfig config, boolean isPre) {
@ -152,8 +155,10 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
isPre ? MsProcessorConverterFactory::getPreConverter : MsProcessorConverterFactory::getPostConverter;
// 添加场景前置处理器
scenarioPreProcessors.forEach(processor ->
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config));
scenarioPreProcessors.forEach(processor -> {
processor.setProjectId(msScenario.getProjectId());
getConverterFunc.apply(processor.getClass()).parse(tree, processor, config);
});
}
private boolean isRef(String refType) {

View File

@ -44,4 +44,9 @@ public abstract class MsProcessor {
* 是否启用
*/
private Boolean enable = true;
/**
* 项目ID
* 执行时设置
*/
private String projectId;
}