fix(接口测试): 修复对象为空时copyBean抛出异常问题

This commit is contained in:
fit2-zhao 2022-10-17 09:59:34 +08:00 committed by fit2-zhao
parent be930815e6
commit b7b467954e
3 changed files with 17 additions and 7 deletions

View File

@ -167,7 +167,9 @@ public class MsScenario extends MsTestElement {
if (environmentConfig != null) {
EnvJSR223Processor envProcessor = isPre ? environmentConfig.getPreStepProcessor() : environmentConfig.getPostStepProcessor();
MsJSR223Processor processor = new MsJSR223Processor();
BeanUtils.copyBean(processor, envProcessor);
if (envProcessor != null) {
BeanUtils.copyBean(processor, envProcessor);
}
if (processor != null && StringUtils.isNotEmpty(processor.getScript())) {
processor.setType(ElementConstants.JSR223);
processor.setClazzName(MsJSR223Processor.class.getCanonicalName());

View File

@ -323,13 +323,17 @@ public class MsHTTPSamplerProxy extends MsTestElement {
HttpConfig httpConfig = config.matchConfig(this);
if (environmentConfig.getPreProcessor() != null) {
MsJSR223PreProcessor msJSR223PreProcessor = new MsJSR223PreProcessor();
BeanUtils.copyBean(msJSR223PreProcessor, environmentConfig.getPreProcessor());
httpConfig.setPreProcessor(msJSR223PreProcessor);
if (environmentConfig.getPreProcessor() != null) {
BeanUtils.copyBean(msJSR223PreProcessor, environmentConfig.getPreProcessor());
httpConfig.setPreProcessor(msJSR223PreProcessor);
}
}
if (environmentConfig.getPostProcessor() != null) {
MsJSR223PostProcessor postProcessor = new MsJSR223PostProcessor();
BeanUtils.copyBean(postProcessor, environmentConfig.getPostProcessor());
httpConfig.setPostProcessor(postProcessor);
if (environmentConfig.getPostProcessor() != null) {
BeanUtils.copyBean(postProcessor, environmentConfig.getPostProcessor());
httpConfig.setPostProcessor(postProcessor);
}
}
httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig());
if (CollectionUtils.isNotEmpty(environmentConfig.getAssertions())) {

View File

@ -35,7 +35,9 @@ public class JMeterScriptUtil {
public static MsJSR223PreProcessor getPreScript(EnvironmentConfig envConfig) {
if (envConfig != null && envConfig.getPreProcessor() != null && StringUtils.isNotEmpty(envConfig.getPreProcessor().getScript())) {
MsJSR223PreProcessor preProcessor = new MsJSR223PreProcessor();
BeanUtils.copyBean(preProcessor,envConfig.getPreProcessor());
if (envConfig.getPreProcessor() != null) {
BeanUtils.copyBean(preProcessor, envConfig.getPreProcessor());
}
return preProcessor;
} else {
return null;
@ -45,7 +47,9 @@ public class JMeterScriptUtil {
public static MsJSR223PostProcessor getPostScript(EnvironmentConfig envConfig) {
if (envConfig != null && envConfig.getPostProcessor() != null && StringUtils.isNotEmpty(envConfig.getPostProcessor().getScript())) {
MsJSR223PostProcessor post = new MsJSR223PostProcessor();
BeanUtils.copyBean(post,envConfig.getPostProcessor());
if (envConfig.getPostProcessor() != null) {
BeanUtils.copyBean(post, envConfig.getPostProcessor());
}
return post;
} else {
return null;