fix(接口测试): 环境场景级SQL前后置执行结果有误
--bug=1041364 --user=陈建星 【场景】场景中普通步骤被禁用后,普通步骤后的循环控制器不执行 https://www.tapd.cn/55049933/s/1523177
This commit is contained in:
parent
93b2793d88
commit
753ee87b9c
|
@ -7,6 +7,7 @@ package io.metersphere.api.constants;
|
||||||
public class ApiConstants {
|
public class ApiConstants {
|
||||||
public static final String HTTP_PROTOCOL = "HTTP";
|
public static final String HTTP_PROTOCOL = "HTTP";
|
||||||
public static final String CONTENT_TYPE = "Content-Type";
|
public static final String CONTENT_TYPE = "Content-Type";
|
||||||
|
public static final String ASSOCIATE_RESULT_PROCESSOR_PREFIX = "ASSOCIATE_RESULT_PROCESSOR_";
|
||||||
|
|
||||||
private ApiConstants() {}
|
private ApiConstants() {}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,9 +19,11 @@ import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||||
import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter;
|
import io.metersphere.plugin.api.spi.AbstractJmeterElementConverter;
|
||||||
import io.metersphere.project.api.assertion.MsAssertion;
|
import io.metersphere.project.api.assertion.MsAssertion;
|
||||||
import io.metersphere.project.api.processor.MsProcessor;
|
import io.metersphere.project.api.processor.MsProcessor;
|
||||||
|
import io.metersphere.project.api.processor.SQLProcessor;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
import io.metersphere.project.dto.environment.EnvironmentConfig;
|
||||||
import io.metersphere.project.dto.environment.EnvironmentInfoDTO;
|
import io.metersphere.project.dto.environment.EnvironmentInfoDTO;
|
||||||
import io.metersphere.project.dto.environment.processors.EnvProcessorConfig;
|
import io.metersphere.project.dto.environment.processors.EnvProcessorConfig;
|
||||||
|
import io.metersphere.project.dto.environment.processors.EnvScenarioSqlProcessor;
|
||||||
import io.metersphere.project.dto.environment.variables.CommonVariables;
|
import io.metersphere.project.dto.environment.variables.CommonVariables;
|
||||||
import io.metersphere.sdk.util.BeanUtils;
|
import io.metersphere.sdk.util.BeanUtils;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
@ -42,6 +44,7 @@ import java.util.function.Function;
|
||||||
import java.util.function.Predicate;
|
import java.util.function.Predicate;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
import static io.metersphere.api.constants.ApiConstants.ASSOCIATE_RESULT_PROCESSOR_PREFIX;
|
||||||
import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.COOKIE_PANEL;
|
import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.COOKIE_PANEL;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -278,6 +281,16 @@ public class MsScenarioConverter extends AbstractJmeterElementConverter<MsScenar
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 处理环境场景级别的SQL处理器
|
||||||
|
for (int i = 0; i < envScenarioProcessors.size(); i++) {
|
||||||
|
MsProcessor msProcessor = envScenarioProcessors.get(i);
|
||||||
|
if (msProcessor instanceof SQLProcessor) {
|
||||||
|
EnvScenarioSqlProcessor envScenarioSqlProcessor = BeanUtils.copyBean(new EnvScenarioSqlProcessor(), msProcessor);
|
||||||
|
envScenarioSqlProcessor.setName(ASSOCIATE_RESULT_PROCESSOR_PREFIX + false);
|
||||||
|
envScenarioProcessors.set(i, envScenarioSqlProcessor);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
Function<Class<?>, MsProcessorConverter<MsProcessor>> getConverterFunc =
|
Function<Class<?>, MsProcessorConverter<MsProcessor>> getConverterFunc =
|
||||||
isPre ? MsProcessorConverterFactory::getPreConverter : MsProcessorConverterFactory::getPostConverter;
|
isPre ? MsProcessorConverterFactory::getPreConverter : MsProcessorConverterFactory::getPostConverter;
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,7 @@ import io.metersphere.project.api.processor.ScriptProcessor;
|
||||||
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
import io.metersphere.project.api.processor.TimeWaitingProcessor;
|
||||||
import io.metersphere.project.dto.environment.processors.EnvRequestScriptProcessor;
|
import io.metersphere.project.dto.environment.processors.EnvRequestScriptProcessor;
|
||||||
import io.metersphere.project.dto.environment.processors.EnvScenarioScriptProcessor;
|
import io.metersphere.project.dto.environment.processors.EnvScenarioScriptProcessor;
|
||||||
|
import io.metersphere.project.dto.environment.processors.EnvScenarioSqlProcessor;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
@ -25,6 +26,7 @@ public class MsProcessorConverterFactory {
|
||||||
preConverterMap.put(TimeWaitingProcessor.class, new TimeWaitingProcessorConverter());
|
preConverterMap.put(TimeWaitingProcessor.class, new TimeWaitingProcessorConverter());
|
||||||
preConverterMap.put(EnvRequestScriptProcessor.class, new ScriptPreProcessorConverter());
|
preConverterMap.put(EnvRequestScriptProcessor.class, new ScriptPreProcessorConverter());
|
||||||
preConverterMap.put(EnvScenarioScriptProcessor.class, new ScenarioScriptProcessorConverter());
|
preConverterMap.put(EnvScenarioScriptProcessor.class, new ScenarioScriptProcessorConverter());
|
||||||
|
preConverterMap.put(EnvScenarioSqlProcessor.class, new ScenarioSqlProcessorConverter());
|
||||||
|
|
||||||
postConverterMap.put(ScriptProcessor.class, new ScriptPostProcessorConverter());
|
postConverterMap.put(ScriptProcessor.class, new ScriptPostProcessorConverter());
|
||||||
postConverterMap.put(SQLProcessor.class, new SqlPostProcessorConverter());
|
postConverterMap.put(SQLProcessor.class, new SqlPostProcessorConverter());
|
||||||
|
@ -32,6 +34,7 @@ public class MsProcessorConverterFactory {
|
||||||
postConverterMap.put(ExtractPostProcessor.class, new ExtractPostProcessorConverter());
|
postConverterMap.put(ExtractPostProcessor.class, new ExtractPostProcessorConverter());
|
||||||
postConverterMap.put(EnvRequestScriptProcessor.class, new ScriptPostProcessorConverter());
|
postConverterMap.put(EnvRequestScriptProcessor.class, new ScriptPostProcessorConverter());
|
||||||
postConverterMap.put(EnvScenarioScriptProcessor.class, new ScenarioScriptProcessorConverter());
|
postConverterMap.put(EnvScenarioScriptProcessor.class, new ScenarioScriptProcessorConverter());
|
||||||
|
postConverterMap.put(EnvScenarioSqlProcessor.class, new ScenarioSqlProcessorConverter());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static MsProcessorConverter getPreConverter(Class<?> processorClass) {
|
public static MsProcessorConverter getPreConverter(Class<?> processorClass) {
|
||||||
|
|
|
@ -10,6 +10,8 @@ import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
|
import static io.metersphere.api.constants.ApiConstants.ASSOCIATE_RESULT_PROCESSOR_PREFIX;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 环境场景级前置处理器处理
|
* 环境场景级前置处理器处理
|
||||||
*
|
*
|
||||||
|
@ -40,7 +42,7 @@ public class ScenarioScriptProcessorConverter extends ScriptProcessorConverter {
|
||||||
.ifPresent(hashTree::add);
|
.ifPresent(hashTree::add);
|
||||||
|
|
||||||
// 标记当前处理器是否关联场景结果
|
// 标记当前处理器是否关联场景结果
|
||||||
processor.setName("ASSOCIATE_RESULT_PROCESSOR_" + associateScenarioResult);
|
processor.setName(ASSOCIATE_RESULT_PROCESSOR_PREFIX + associateScenarioResult);
|
||||||
hashTree.add(processor);
|
hashTree.add(processor);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,20 @@
|
||||||
|
package io.metersphere.api.parser.jmeter.processor;
|
||||||
|
|
||||||
|
import io.metersphere.plugin.api.dto.ParameterConfig;
|
||||||
|
import io.metersphere.project.api.processor.SQLProcessor;
|
||||||
|
import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
|
||||||
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 环境场景级前后置SQL处理器
|
||||||
|
*
|
||||||
|
* @Author: jianxing
|
||||||
|
* @CreateTime: 2023-12-26 14:49
|
||||||
|
*/
|
||||||
|
public class ScenarioSqlProcessorConverter extends SqlProcessorConverter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void parse(HashTree hashTree, SQLProcessor sqlProcessor, ParameterConfig config) {
|
||||||
|
parse(hashTree, sqlProcessor, config, JDBCSampler.class);
|
||||||
|
}
|
||||||
|
}
|
|
@ -15,7 +15,6 @@ import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.extractor.JSR223PostProcessor;
|
import org.apache.jmeter.extractor.JSR223PostProcessor;
|
||||||
import org.apache.jmeter.modifiers.JSR223PreProcessor;
|
import org.apache.jmeter.modifiers.JSR223PreProcessor;
|
||||||
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
||||||
import org.apache.jmeter.protocol.jdbc.processor.AbstractJDBCProcessor;
|
|
||||||
import org.apache.jmeter.protocol.jdbc.processor.JDBCPreProcessor;
|
import org.apache.jmeter.protocol.jdbc.processor.JDBCPreProcessor;
|
||||||
import org.apache.jmeter.save.SaveService;
|
import org.apache.jmeter.save.SaveService;
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
|
@ -32,7 +31,7 @@ import static io.metersphere.api.parser.jmeter.constants.JmeterAlias.TEST_BEAN_G
|
||||||
*/
|
*/
|
||||||
public abstract class SqlProcessorConverter extends MsProcessorConverter<SQLProcessor> {
|
public abstract class SqlProcessorConverter extends MsProcessorConverter<SQLProcessor> {
|
||||||
|
|
||||||
public <T extends AbstractJDBCProcessor> void parse(HashTree hashTree,
|
public <T extends TestElement> void parse(HashTree hashTree,
|
||||||
SQLProcessor sqlProcessor,
|
SQLProcessor sqlProcessor,
|
||||||
ParameterConfig config,
|
ParameterConfig config,
|
||||||
Class<T> jdbcProcessorClass) {
|
Class<T> jdbcProcessorClass) {
|
||||||
|
@ -52,8 +51,8 @@ public abstract class SqlProcessorConverter extends MsProcessorConverter<SQLProc
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// 添加前后置处理器
|
// 添加前后置处理器
|
||||||
T jdbcProcessor = jdbcProcessorClass.getDeclaredConstructor().newInstance();
|
TestElement jdbcProcessor = jdbcProcessorClass.getDeclaredConstructor().newInstance();
|
||||||
getJdbcProcessor(sqlProcessor, jdbcProcessor, dataSource);
|
jdbcProcessor = getJdbcProcessor(sqlProcessor, jdbcProcessor, dataSource);
|
||||||
hashTree.add(jdbcProcessor);
|
hashTree.add(jdbcProcessor);
|
||||||
List<KeyValueParam> extractParams = sqlProcessor.getExtractParams()
|
List<KeyValueParam> extractParams = sqlProcessor.getExtractParams()
|
||||||
.stream()
|
.stream()
|
||||||
|
@ -62,9 +61,9 @@ public abstract class SqlProcessorConverter extends MsProcessorConverter<SQLProc
|
||||||
// 添加提取的变量
|
// 添加提取的变量
|
||||||
TestElement jdbcPostProcessor;
|
TestElement jdbcPostProcessor;
|
||||||
if (jdbcProcessor instanceof JDBCPreProcessor) {
|
if (jdbcProcessor instanceof JDBCPreProcessor) {
|
||||||
jdbcPostProcessor = getJdbcProcessor(sqlProcessor.getName(), extractParams, JSR223PreProcessor.class);
|
jdbcPostProcessor = getExtractParamProcessor(sqlProcessor.getName(), extractParams, JSR223PreProcessor.class);
|
||||||
} else {
|
} else {
|
||||||
jdbcPostProcessor = getJdbcProcessor(sqlProcessor.getName(), extractParams, JSR223PostProcessor.class);
|
jdbcPostProcessor = getExtractParamProcessor(sqlProcessor.getName(), extractParams, JSR223PostProcessor.class);
|
||||||
}
|
}
|
||||||
if (jdbcPostProcessor != null) {
|
if (jdbcPostProcessor != null) {
|
||||||
hashTree.add(jdbcPostProcessor);
|
hashTree.add(jdbcPostProcessor);
|
||||||
|
@ -75,7 +74,7 @@ public abstract class SqlProcessorConverter extends MsProcessorConverter<SQLProc
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public <T extends TestElement> T getJdbcProcessor(String name, List<KeyValueParam> extractParams, Class<T> elementType) {
|
public <T extends TestElement> T getExtractParamProcessor(String name, List<KeyValueParam> extractParams, Class<T> elementType) {
|
||||||
if (CollectionUtils.isNotEmpty(extractParams)) {
|
if (CollectionUtils.isNotEmpty(extractParams)) {
|
||||||
T processor;
|
T processor;
|
||||||
try {
|
try {
|
||||||
|
@ -124,12 +123,11 @@ public abstract class SqlProcessorConverter extends MsProcessorConverter<SQLProc
|
||||||
return CollectionUtils.isEmpty(dataSourceResults) ? null : dataSourceResults.get(0);
|
return CollectionUtils.isEmpty(dataSourceResults) ? null : dataSourceResults.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected AbstractJDBCProcessor getJdbcProcessor(SQLProcessor sqlProcessor, AbstractJDBCProcessor jdbcProcessor, DataSource dataSource) {
|
protected TestElement getJdbcProcessor(SQLProcessor sqlProcessor, TestElement jdbcProcessor, DataSource dataSource) {
|
||||||
jdbcProcessor.setEnabled(sqlProcessor.getEnable());
|
jdbcProcessor.setEnabled(sqlProcessor.getEnable());
|
||||||
jdbcProcessor.setName(sqlProcessor.getName() == null ? jdbcProcessor.getClass().getSimpleName() : sqlProcessor.getName());
|
jdbcProcessor.setName(sqlProcessor.getName() == null ? jdbcProcessor.getClass().getSimpleName() : sqlProcessor.getName());
|
||||||
jdbcProcessor.setProperty(TestElement.TEST_CLASS, jdbcProcessor.getClass().getSimpleName());
|
jdbcProcessor.setProperty(TestElement.TEST_CLASS, jdbcProcessor.getClass().getSimpleName());
|
||||||
jdbcProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
jdbcProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
||||||
jdbcProcessor.setDataSource(sqlProcessor.getName());
|
|
||||||
jdbcProcessor.setProperty("dataSource", dataSource.getDataSource());
|
jdbcProcessor.setProperty("dataSource", dataSource.getDataSource());
|
||||||
jdbcProcessor.setProperty("query", sqlProcessor.getScript());
|
jdbcProcessor.setProperty("query", sqlProcessor.getScript());
|
||||||
jdbcProcessor.setProperty("queryTimeout", String.valueOf(sqlProcessor.getQueryTimeout()));
|
jdbcProcessor.setProperty("queryTimeout", String.valueOf(sqlProcessor.getQueryTimeout()));
|
||||||
|
|
|
@ -0,0 +1,12 @@
|
||||||
|
package io.metersphere.project.dto.environment.processors;
|
||||||
|
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.annotation.JsonTypeName;
|
||||||
|
import io.metersphere.project.api.processor.SQLProcessor;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@JsonTypeName("ENV_SCENARIO_SQL")
|
||||||
|
public class EnvScenarioSqlProcessor extends SQLProcessor {
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue