feat(接口自动化,接口定义): 增加前后置SQL请求步骤

--story=1001742 --user=宋天阳 增加前后置SQL请求步骤
https://www.tapd.cn/55049933/s/1025292
This commit is contained in:
song-tianyang 2021-07-13 17:50:25 +08:00 committed by 刘瑞斌
parent e071d3c063
commit c16df08616
17 changed files with 1143 additions and 15 deletions

View File

@ -13,7 +13,9 @@ import io.metersphere.api.dto.definition.request.controller.MsLoopController;
import io.metersphere.api.dto.definition.request.controller.MsTransactionController; import io.metersphere.api.dto.definition.request.controller.MsTransactionController;
import io.metersphere.api.dto.definition.request.extract.MsExtract; import io.metersphere.api.dto.definition.request.extract.MsExtract;
import io.metersphere.api.dto.definition.request.processors.MsJSR223Processor; import io.metersphere.api.dto.definition.request.processors.MsJSR223Processor;
import io.metersphere.api.dto.definition.request.processors.post.MsJDBCPostProcessor;
import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor; import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor;
import io.metersphere.api.dto.definition.request.processors.pre.MsJDBCPreProcessor;
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor; import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
import io.metersphere.api.dto.definition.request.sampler.MsDubboSampler; import io.metersphere.api.dto.definition.request.sampler.MsDubboSampler;
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy; import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
@ -59,6 +61,8 @@ import java.util.stream.Collectors;
@JsonSubTypes.Type(value = MsJSR223Processor.class, name = "JSR223Processor"), @JsonSubTypes.Type(value = MsJSR223Processor.class, name = "JSR223Processor"),
@JsonSubTypes.Type(value = MsJSR223PostProcessor.class, name = "JSR223PostProcessor"), @JsonSubTypes.Type(value = MsJSR223PostProcessor.class, name = "JSR223PostProcessor"),
@JsonSubTypes.Type(value = MsJSR223PreProcessor.class, name = "JSR223PreProcessor"), @JsonSubTypes.Type(value = MsJSR223PreProcessor.class, name = "JSR223PreProcessor"),
@JsonSubTypes.Type(value = MsJDBCPreProcessor.class, name = "JDBCPreProcessor"),
@JsonSubTypes.Type(value = MsJDBCPostProcessor.class, name = "JDBCPostProcessor"),
@JsonSubTypes.Type(value = MsTestPlan.class, name = "TestPlan"), @JsonSubTypes.Type(value = MsTestPlan.class, name = "TestPlan"),
@JsonSubTypes.Type(value = MsThreadGroup.class, name = "ThreadGroup"), @JsonSubTypes.Type(value = MsThreadGroup.class, name = "ThreadGroup"),
@JsonSubTypes.Type(value = MsAuthManager.class, name = "AuthManager"), @JsonSubTypes.Type(value = MsAuthManager.class, name = "AuthManager"),
@ -75,7 +79,7 @@ import java.util.stream.Collectors;
@JsonSubTypes.Type(value = MsJmeterElement.class, name = "JmeterElement"), @JsonSubTypes.Type(value = MsJmeterElement.class, name = "JmeterElement"),
}) })
@JSONType(seeAlso = {MsHTTPSamplerProxy.class, MsHeaderManager.class, MsJSR223Processor.class, MsJSR223PostProcessor.class, @JSONType(seeAlso = {MsHTTPSamplerProxy.class, MsHeaderManager.class, MsJSR223Processor.class, MsJSR223PostProcessor.class, MsJDBCPreProcessor.class, MsJDBCPostProcessor.class,
MsJSR223PreProcessor.class, MsTestPlan.class, MsThreadGroup.class, MsAuthManager.class, MsAssertions.class, MsJSR223PreProcessor.class, MsTestPlan.class, MsThreadGroup.class, MsAuthManager.class, MsAssertions.class,
MsExtract.class, MsTCPSampler.class, MsDubboSampler.class, MsJDBCSampler.class, MsConstantTimer.class, MsIfController.class, MsTransactionController.class, MsScenario.class, MsLoopController.class, MsJmeterElement.class}, typeKey = "type") MsExtract.class, MsTCPSampler.class, MsDubboSampler.class, MsJDBCSampler.class, MsConstantTimer.class, MsIfController.class, MsTransactionController.class, MsScenario.class, MsLoopController.class, MsJmeterElement.class}, typeKey = "type")
@Data @Data

View File

@ -0,0 +1,283 @@
package io.metersphere.api.dto.definition.request.processors.post;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.metersphere.api.dto.definition.request.MsTestElement;
import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.scenario.DatabaseConfig;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.constants.RunModeConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
import org.apache.jmeter.protocol.jdbc.processor.JDBCPostProcessor;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author song.tianyang
* @Date 2021/7/13 11:08 上午
*/
@Data
@EqualsAndHashCode(callSuper = true)
@JSONType(typeName = "JDBCPostProcessor")
public class MsJDBCPostProcessor extends MsTestElement {
// type 必须放最前面以便能够转换正确的类
private String type = "JDBCPostProcessor";
@JSONField(ordinal = 20)
private DatabaseConfig dataSource;
@JSONField(ordinal = 21)
private String query;
@JSONField(ordinal = 22)
private long queryTimeout;
@JSONField(ordinal = 23)
private String resultVariable;
@JSONField(ordinal = 24)
private String variableNames;
@JSONField(ordinal = 25)
private List<KeyValue> variables;
@JSONField(ordinal = 26)
private String environmentId;
@JSONField(ordinal = 28)
private String dataSourceId;
@JSONField(ordinal = 29)
private String protocol = "SQL";
@JSONField(ordinal = 30)
private String useEnvironment;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable()) {
return;
}
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
this.setRefElement();
}
if (config.getConfig() == null) {
// 单独接口执行
this.setProjectId(config.getProjectId());
config.setConfig(getEnvironmentConfig(StringUtils.isNotEmpty(useEnvironment) ? useEnvironment : environmentId));
}
// 数据兼容处理
if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) {
// 1.8 之后 当前正常数据
} else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 前后 混合数据
this.setProjectId(getParentProjectId());
} else {
// 1.8 之前 数据
if (config.getConfig() != null) {
if (config.getConfig().containsKey(RunModeConstants.HIS_PRO_ID.toString())) {
this.setProjectId(RunModeConstants.HIS_PRO_ID.toString());
} else {
// 测试计划执行
Iterator<String> it = config.getConfig().keySet().iterator();
if (it.hasNext()) {
this.setProjectId(it.next());
}
}
}
}
//如果当前数据源为null则获取已选环境的数据源
if(this.dataSource == null){
// 自选了数据源
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
this.initDataSource();
} else {
// 取当前环境下默认的一个数据源
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
}
}
}
if (this.dataSource == null) {
// 用自身的数据
if (StringUtils.isNotEmpty(dataSourceId)) {
this.dataSource = null;
this.initDataSource();
}
if (this.dataSource == null) {
MSException.throwException("数据源为空无法执行");
}
}
final HashTree samplerHashTree = tree.add(jdbcPostProcessor(config));
tree.add(jdbcDataSource());
Arguments arguments = arguments(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments", this.getVariables());
if (arguments != null) {
tree.add(arguments);
}
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {
el.toHashTree(samplerHashTree, el.getHashTree(), config);
});
}
}
private boolean isDataSource(List<DatabaseConfig> databaseConfigs) {
List<String> ids = databaseConfigs.stream().map(DatabaseConfig::getId).collect(Collectors.toList());
if (StringUtils.isNotEmpty(this.dataSourceId) && ids.contains(this.dataSourceId)) {
return true;
}
return false;
}
private String getParentProjectId() {
MsTestElement parent = this.getParent();
while (parent != null) {
if (StringUtils.isNotBlank(parent.getProjectId())) {
return parent.getProjectId();
}
parent = parent.getParent();
}
return "";
}
private void setRefElement() {
try {
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MsJDBCPostProcessor proxy = null;
if (StringUtils.equals(this.getRefType(), "CASE")) {
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
if (bloBs != null) {
this.setName(bloBs.getName());
this.setProjectId(bloBs.getProjectId());
proxy = mapper.readValue(bloBs.getRequest(), new TypeReference<MsJDBCPostProcessor>() {
});
}
} else {
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
if (apiDefinition != null) {
this.setProjectId(apiDefinition.getProjectId());
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsJDBCPostProcessor>() {
});
this.setName(apiDefinition.getName());
}
}
if (proxy != null) {
this.setHashTree(proxy.getHashTree());
this.setDataSource(proxy.getDataSource());
this.setDataSourceId(proxy.getDataSourceId());
this.setQuery(proxy.getQuery());
this.setVariables(proxy.getVariables());
this.setVariableNames(proxy.getVariableNames());
this.setResultVariable(proxy.getResultVariable());
this.setQueryTimeout(proxy.getQueryTimeout());
}
} catch (Exception ex) {
ex.printStackTrace();
LogUtil.error(ex.getMessage());
}
}
private void initDataSource() {
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId);
if (environment != null && environment.getConfig() != null) {
EnvironmentConfig envConfig = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) {
envConfig.getDatabaseConfigs().forEach(item -> {
if (item.getId().equals(this.dataSourceId)) {
this.dataSource = item;
return;
}
});
}
}
}
private Arguments arguments(String name, List<KeyValue> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
Arguments arguments = new Arguments();
arguments.setEnabled(true);
arguments.setName(name + "JDBC_Argument");
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(), "=")
);
return arguments;
}
return null;
}
private JDBCPostProcessor jdbcPostProcessor(ParameterConfig config) {
JDBCPostProcessor jdbcPostProcessor = new JDBCPostProcessor();
jdbcPostProcessor.setEnabled(this.isEnable());
jdbcPostProcessor.setName(this.getName());
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
jdbcPostProcessor.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
jdbcPostProcessor.setProperty(TestElement.TEST_CLASS, JDBCPostProcessor.class.getName());
jdbcPostProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
jdbcPostProcessor.setProperty("MS-ID", this.getId());
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
jdbcPostProcessor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
// request.getDataSource() 是ID需要转换为Name
jdbcPostProcessor.setProperty("dataSource", this.dataSource.getName());
jdbcPostProcessor.setProperty("query", this.getQuery());
jdbcPostProcessor.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
jdbcPostProcessor.setProperty("resultVariable", this.getResultVariable());
jdbcPostProcessor.setProperty("variableNames", this.getVariableNames());
jdbcPostProcessor.setProperty("resultSetHandler", "Store as String");
jdbcPostProcessor.setProperty("queryType", "Callable Statement");
return jdbcPostProcessor;
}
private DataSourceElement jdbcDataSource() {
DataSourceElement dataSourceElement = new DataSourceElement();
dataSourceElement.setEnabled(true);
dataSourceElement.setName(this.getName() + " JDBCDataSource");
dataSourceElement.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName());
dataSourceElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
dataSourceElement.setProperty("autocommit", true);
dataSourceElement.setProperty("keepAlive", true);
dataSourceElement.setProperty("preinit", false);
dataSourceElement.setProperty("dataSource", dataSource.getName());
dataSourceElement.setProperty("dbUrl", dataSource.getDbUrl());
dataSourceElement.setProperty("driver", dataSource.getDriver());
dataSourceElement.setProperty("username", dataSource.getUsername());
dataSourceElement.setProperty("password", dataSource.getPassword());
dataSourceElement.setProperty("poolMax", dataSource.getPoolMax());
dataSourceElement.setProperty("timeout", String.valueOf(dataSource.getTimeout()));
dataSourceElement.setProperty("connectionAge", 5000);
dataSourceElement.setProperty("trimInterval", 6000);
dataSourceElement.setProperty("transactionIsolation", "DEFAULT");
return dataSourceElement;
}
}

View File

@ -0,0 +1,283 @@
package io.metersphere.api.dto.definition.request.processors.pre;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.annotation.JSONField;
import com.alibaba.fastjson.annotation.JSONType;
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import io.metersphere.api.dto.definition.request.MsTestElement;
import io.metersphere.api.dto.definition.request.ParameterConfig;
import io.metersphere.api.dto.scenario.DatabaseConfig;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
import io.metersphere.api.service.ApiDefinitionService;
import io.metersphere.api.service.ApiTestCaseService;
import io.metersphere.api.service.ApiTestEnvironmentService;
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
import io.metersphere.commons.constants.DelimiterConstants;
import io.metersphere.commons.constants.MsTestElementConstants;
import io.metersphere.commons.constants.RunModeConstants;
import io.metersphere.commons.exception.MSException;
import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.config.Arguments;
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
import org.apache.jmeter.protocol.jdbc.processor.JDBCPreProcessor;
import org.apache.jmeter.save.SaveService;
import org.apache.jmeter.testelement.TestElement;
import org.apache.jorphan.collections.HashTree;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.stream.Collectors;
/**
* @author song.tianyang
* @Date 2021/7/13 11:08 上午
*/
@Data
@EqualsAndHashCode(callSuper = true)
@JSONType(typeName = "JDBCPreProcessor")
public class MsJDBCPreProcessor extends MsTestElement {
// type 必须放最前面以便能够转换正确的类
private String type = "JDBCPreProcessor";
@JSONField(ordinal = 20)
private DatabaseConfig dataSource;
@JSONField(ordinal = 21)
private String query;
@JSONField(ordinal = 22)
private long queryTimeout;
@JSONField(ordinal = 23)
private String resultVariable;
@JSONField(ordinal = 24)
private String variableNames;
@JSONField(ordinal = 25)
private List<KeyValue> variables;
@JSONField(ordinal = 26)
private String environmentId;
@JSONField(ordinal = 28)
private String dataSourceId;
@JSONField(ordinal = 29)
private String protocol = "SQL";
@JSONField(ordinal = 30)
private String useEnvironment;
@Override
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
// 非导出操作且不是启用状态则跳过执行
if (!config.isOperating() && !this.isEnable()) {
return;
}
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
this.setRefElement();
}
if (config.getConfig() == null) {
// 单独接口执行
this.setProjectId(config.getProjectId());
config.setConfig(getEnvironmentConfig(StringUtils.isNotEmpty(useEnvironment) ? useEnvironment : environmentId));
}
// 数据兼容处理
if (config.getConfig() != null && StringUtils.isNotEmpty(this.getProjectId()) && config.getConfig().containsKey(this.getProjectId())) {
// 1.8 之后 当前正常数据
} else if (config.getConfig() != null && config.getConfig().containsKey(getParentProjectId())) {
// 1.8 前后 混合数据
this.setProjectId(getParentProjectId());
} else {
// 1.8 之前 数据
if (config.getConfig() != null) {
if (config.getConfig().containsKey(RunModeConstants.HIS_PRO_ID.toString())) {
this.setProjectId(RunModeConstants.HIS_PRO_ID.toString());
} else {
// 测试计划执行
Iterator<String> it = config.getConfig().keySet().iterator();
if (it.hasNext()) {
this.setProjectId(it.next());
}
}
}
}
//如果当前数据源为null则获取已选环境的数据源
if(this.dataSource == null){
// 自选了数据源
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())
&& isDataSource(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
this.initDataSource();
} else {
// 取当前环境下默认的一个数据源
if (config.isEffective(this.getProjectId()) && CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getDatabaseConfigs())) {
this.dataSource = config.getConfig().get(this.getProjectId()).getDatabaseConfigs().get(0);
}
}
}
if (this.dataSource == null) {
// 用自身的数据
if (StringUtils.isNotEmpty(dataSourceId)) {
this.dataSource = null;
this.initDataSource();
}
if (this.dataSource == null) {
MSException.throwException("数据源为空无法执行");
}
}
final HashTree samplerHashTree = tree.add(jdbcPreProcessor(config));
tree.add(jdbcDataSource());
Arguments arguments = arguments(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments", this.getVariables());
if (arguments != null) {
tree.add(arguments);
}
if (CollectionUtils.isNotEmpty(hashTree)) {
hashTree.forEach(el -> {
el.toHashTree(samplerHashTree, el.getHashTree(), config);
});
}
}
private boolean isDataSource(List<DatabaseConfig> databaseConfigs) {
List<String> ids = databaseConfigs.stream().map(DatabaseConfig::getId).collect(Collectors.toList());
if (StringUtils.isNotEmpty(this.dataSourceId) && ids.contains(this.dataSourceId)) {
return true;
}
return false;
}
private String getParentProjectId() {
MsTestElement parent = this.getParent();
while (parent != null) {
if (StringUtils.isNotBlank(parent.getProjectId())) {
return parent.getProjectId();
}
parent = parent.getParent();
}
return "";
}
private void setRefElement() {
try {
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
ObjectMapper mapper = new ObjectMapper();
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
MsJDBCPreProcessor proxy = null;
if (StringUtils.equals(this.getRefType(), "CASE")) {
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
if (bloBs != null) {
this.setName(bloBs.getName());
this.setProjectId(bloBs.getProjectId());
proxy = mapper.readValue(bloBs.getRequest(), new TypeReference<MsJDBCPreProcessor>() {
});
}
} else {
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
if (apiDefinition != null) {
this.setProjectId(apiDefinition.getProjectId());
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsJDBCPreProcessor>() {
});
this.setName(apiDefinition.getName());
}
}
if (proxy != null) {
this.setHashTree(proxy.getHashTree());
this.setDataSource(proxy.getDataSource());
this.setDataSourceId(proxy.getDataSourceId());
this.setQuery(proxy.getQuery());
this.setVariables(proxy.getVariables());
this.setVariableNames(proxy.getVariableNames());
this.setResultVariable(proxy.getResultVariable());
this.setQueryTimeout(proxy.getQueryTimeout());
}
} catch (Exception ex) {
ex.printStackTrace();
LogUtil.error(ex.getMessage());
}
}
private void initDataSource() {
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId);
if (environment != null && environment.getConfig() != null) {
EnvironmentConfig envConfig = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
if (CollectionUtils.isNotEmpty(envConfig.getDatabaseConfigs())) {
envConfig.getDatabaseConfigs().forEach(item -> {
if (item.getId().equals(this.dataSourceId)) {
this.dataSource = item;
return;
}
});
}
}
}
private Arguments arguments(String name, List<KeyValue> variables) {
if (CollectionUtils.isNotEmpty(variables)) {
Arguments arguments = new Arguments();
arguments.setEnabled(true);
arguments.setName(name + "JDBC_Argument");
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(), "=")
);
return arguments;
}
return null;
}
private JDBCPreProcessor jdbcPreProcessor(ParameterConfig config) {
JDBCPreProcessor jdbcPreProcessor = new JDBCPreProcessor();
jdbcPreProcessor.setEnabled(this.isEnable());
jdbcPreProcessor.setName(this.getName());
String name = this.getParentName(this.getParent());
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
jdbcPreProcessor.setName(this.getName() + DelimiterConstants.SEPARATOR.toString() + name);
}
jdbcPreProcessor.setProperty(TestElement.TEST_CLASS, JDBCPreProcessor.class.getName());
jdbcPreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
jdbcPreProcessor.setProperty("MS-ID", this.getId());
List<String> id_names = new LinkedList<>();
this.getScenarioSet(this, id_names);
jdbcPreProcessor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
// request.getDataSource() 是ID需要转换为Name
jdbcPreProcessor.setProperty("dataSource", this.dataSource.getName());
jdbcPreProcessor.setProperty("query", this.getQuery());
jdbcPreProcessor.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
jdbcPreProcessor.setProperty("resultVariable", this.getResultVariable());
jdbcPreProcessor.setProperty("variableNames", this.getVariableNames());
jdbcPreProcessor.setProperty("resultSetHandler", "Store as String");
jdbcPreProcessor.setProperty("queryType", "Callable Statement");
return jdbcPreProcessor;
}
private DataSourceElement jdbcDataSource() {
DataSourceElement dataSourceElement = new DataSourceElement();
dataSourceElement.setEnabled(true);
dataSourceElement.setName(this.getName() + " JDBCDataSource");
dataSourceElement.setProperty(TestElement.TEST_CLASS, DataSourceElement.class.getName());
dataSourceElement.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
dataSourceElement.setProperty("autocommit", true);
dataSourceElement.setProperty("keepAlive", true);
dataSourceElement.setProperty("preinit", false);
dataSourceElement.setProperty("dataSource", dataSource.getName());
dataSourceElement.setProperty("dbUrl", dataSource.getDbUrl());
dataSourceElement.setProperty("driver", dataSource.getDriver());
dataSourceElement.setProperty("username", dataSource.getUsername());
dataSourceElement.setProperty("password", dataSource.getPassword());
dataSourceElement.setProperty("poolMax", dataSource.getPoolMax());
dataSourceElement.setProperty("timeout", String.valueOf(dataSource.getTimeout()));
dataSourceElement.setProperty("connectionAge", 5000);
dataSourceElement.setProperty("trimInterval", 6000);
dataSourceElement.setProperty("transactionIsolation", "DEFAULT");
return dataSourceElement;
}
}

View File

@ -1,23 +1,25 @@
export const ELEMENTS = new Map([ export const ELEMENTS = new Map([
['ALL', ["scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "IfController","TransactionController", "LoopController", "ConstantTimer", "JSR223Processor", "CustomizeReq"]], ['ALL', ["scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "IfController","TransactionController", "LoopController", "ConstantTimer", "JSR223Processor", "CustomizeReq"]],
['scenario', ["HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "CASE", "OT_IMPORT", "IfController", "ConstantTimer", "JSR223Processor", "CustomizeReq"]], ['scenario', ["HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "CASE", "OT_IMPORT", "IfController", "ConstantTimer", "JSR223Processor", "CustomizeReq"]],
['HTTPSamplerProxy', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['HTTPSamplerProxy', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor',"Assertions", "Extract"]],
['DubboSampler', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['DubboSampler', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor',"Assertions", "Extract"]],
['JDBCSampler', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['JDBCSampler', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor', "Assertions", "Extract"]],
['TCPSampler', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['TCPSampler', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor', "Assertions", "Extract"]],
['OT_IMPORT', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['OT_IMPORT', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor', "Assertions", "Extract"]],
['IfController', ["IfController", "TransactionController","scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "ConstantTimer", "JSR223Processor", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract", "CustomizeReq"]], ['IfController', ["IfController", "TransactionController","scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "ConstantTimer", "JSR223Processor", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor',"Assertions", "Extract", "CustomizeReq"]],
['TransactionController', ["TransactionController", "scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "ConstantTimer", "JSR223Processor", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract", "CustomizeReq"]], ['TransactionController', ["TransactionController", "scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "ConstantTimer", "JSR223Processor", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor', "Assertions", "Extract", "CustomizeReq"]],
['LoopController', ["IfController", "TransactionController","scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "ConstantTimer", "JSR223Processor", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract", "CustomizeReq"]], ['LoopController', ["IfController", "TransactionController","scenario", "HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "OT_IMPORT", "ConstantTimer", "JSR223Processor", "JSR223PreProcessor", "JSR223PostProcessor", 'JDBCPreProcessor','JDBCPostProcessor', "Assertions", "Extract", "CustomizeReq"]],
['ConstantTimer', []], ['ConstantTimer', []],
['JSR223Processor', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['JSR223Processor', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]],
['JSR223PreProcessor', []], ['JSR223PreProcessor', []],
['JSR223PostProcessor', []], ['JSR223PostProcessor', []],
['JDBCPreProcessor', []],
['JDBCPostProcessor', []],
['Assertions', []], ['Assertions', []],
['Extract', []], ['Extract', []],
['JmeterElement', []], ['JmeterElement', []],
['CustomizeReq', ["ConstantTimer", "JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['CustomizeReq', ["ConstantTimer", "JSR223PreProcessor","JSR223PostProcessor", "JDBCPostProcessor", "JDBCPreProcessor", "Assertions", "Extract"]],
['MaxSamplerProxy', ["JSR223PreProcessor", "JSR223PostProcessor", "Assertions", "Extract"]], ['MaxSamplerProxy', ["JSR223PreProcessor", "JSR223PostProcessor", "JDBCPreProcessor","JDBCPostProcessor","Assertions", "Extract"]],
['AllSamplerProxy', ["HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler"]], ['AllSamplerProxy', ["HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler"]],
['AllCanExecType', ["HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "JSR223Processor"]] ['AllCanExecType', ["HTTPSamplerProxy", "DubboSampler", "JDBCSampler", "TCPSampler", "JSR223Processor"]]
]) ])
@ -32,6 +34,8 @@ export const ELEMENT_TYPE = {
JSR223Processor: "JSR223Processor", JSR223Processor: "JSR223Processor",
JSR223PreProcessor: "JSR223PreProcessor", JSR223PreProcessor: "JSR223PreProcessor",
JSR223PostProcessor: "JSR223PostProcessor", JSR223PostProcessor: "JSR223PostProcessor",
JDBCPostProcessor : "JDBCPostProcessor",
JDBCPreProcessor : "JDBCPreProcessor",
Assertions: "Assertions", Assertions: "Assertions",
Extract: "Extract", Extract: "Extract",
CustomizeReq: "CustomizeReq", CustomizeReq: "CustomizeReq",

View File

@ -0,0 +1,272 @@
<template>
<div v-loading="isReloadData">
<el-row>
<el-col :span="21" style="padding-bottom: 20px">
<div style="border:1px #DCDFE6 solid; height: 100%;border-radius: 4px ;width: 100% ;margin: 20px">
<el-form :model="request" :rules="rules" ref="request" label-width="100px" :disabled="isReadOnly" style="margin: 10px">
<el-row>
<el-col :span="8">
<el-form-item prop="environmentId" :label="$t('api_test.definition.request.run_env')">
<el-select v-model="request.environmentId" size="small" class="ms-htt-width"
:placeholder="$t('api_test.definition.request.run_env')"
@change="environmentChange" clearable>
<el-option v-for="(environment, index) in environments" :key="index"
:label="environment.name"
:value="environment.id"/>
<el-button class="environment-button" size="small" type="primary" @click="openEnvironmentConfig">
{{ $t('api_test.environment.environment_config') }}
</el-button>
<template v-slot:empty>
<div class="empty-environment">
<el-button class="environment-button" size="small" type="primary" @click="openEnvironmentConfig">
{{ $t('api_test.environment.environment_config') }}
</el-button>
</div>
</template>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item :label="$t('api_test.request.sql.dataSource')" prop="dataSourceId" style="margin-left: 10px">
<el-select v-model="request.dataSourceId" size="small" @change="reload">
<el-option v-for="(item, index) in databaseConfigsOptions" :key="index" :value="item.id" :label="item.name"/>
</el-select>
</el-form-item>
</el-col>
<el-col :span="8">
<el-form-item :label="$t('api_test.request.sql.timeout')" prop="queryTimeout" style="margin-left: 10px">
<el-input-number :disabled="isReadOnly" size="small" v-model="request.queryTimeout" :placeholder="$t('commons.millisecond')" :max="1000*10000000" :min="0"/>
</el-form-item>
</el-col>
</el-row>
<el-form-item :label="$t('api_test.request.sql.result_variable')" prop="resultVariable">
<el-input v-model="request.resultVariable" maxlength="500" show-word-limit size="small"/>
</el-form-item>
<el-form-item :label="$t('api_test.request.sql.variable_names')" prop="variableNames">
<el-input v-model="request.variableNames" maxlength="500" show-word-limit size="small"/>
</el-form-item>
<el-tabs v-model="activeName">
<el-tab-pane :label="$t('api_test.scenario.variables')" name="variables">
<ms-api-scenario-variables :is-read-only="isReadOnly" :items="request.variables"
:description="$t('api_test.scenario.kv_description')"/>
</el-tab-pane>
<el-tab-pane :label="$t('api_test.request.sql.sql_script')" name="sql">
<div class="sql-content">
<ms-code-edit mode="sql" :read-only="isReadOnly" :modes="['sql']" :data.sync="request.query" theme="eclipse" ref="codeEdit"/>
</div>
</el-tab-pane>
</el-tabs>
</el-form>
</div>
</el-col>
</el-row>
<!-- 环境 -->
<api-environment-config ref="environmentConfig" @close="environmentConfigClose"/>
</div>
</template>
<script>
import MsApiKeyValue from "@/business/components/api/definition/components/ApiKeyValue";
import ApiAssertions from "@/business/components/api/definition/components/assertion/ApiAssertions";
import MsApiExtract from "@/business/components/api/definition/components/extract/ApiExtract";
import ApiRequestMethodSelect from "@/business/components/api/definition/components/collapse/ApiRequestMethodSelect";
import MsCodeEdit from "@/business/components/common/components/MsCodeEdit";
import MsApiScenarioVariables from "@/business/components/api/definition/components/ApiScenarioVariables";
import {createComponent} from "@/business/components/api/definition/components/jmeter/components";
import {Assertions, Extract} from "@/business/components/api/definition/model/ApiTestModel";
import {parseEnvironment} from "@/business/components/api/definition/model/EnvironmentModel";
import ApiEnvironmentConfig from "@/business/components/api/test/components/ApiEnvironmentConfig";
import {getCurrentProjectID} from "@/common/js/utils";
import {getUUID} from "@/common/js/utils";
import MsJsr233Processor from "@/business/components/api/automation/scenario/component/Jsr233Processor";
export default {
name: "JdbcProcessorContent",
components: {
MsJsr233Processor,
MsApiScenarioVariables,
MsCodeEdit,
ApiRequestMethodSelect, MsApiExtract, MsApiKeyValue, ApiEnvironmentConfig
},
props: {
request: {},
basisData: {},
moduleOptions: Array,
showScript: {
type: Boolean,
default: true,
},
isReadOnly: {
type: Boolean,
default: false
},
},
data() {
return {
environments: [],
currentEnvironment: {},
databaseConfigsOptions: [],
isReloadData: false,
activeName: "variables",
rules: {},
}
},
watch: {
'request.dataSourceId'() {
this.setDataSource();
},
},
created() {
this.getEnvironments();
},
computed: {
projectId() {
return getCurrentProjectID();
},
},
methods: {
remove(row) {
let index = this.request.hashTree.indexOf(row);
this.request.hashTree.splice(index, 1);
this.reload();
},
copyRow(row) {
let obj = JSON.parse(JSON.stringify(row));
obj.id = getUUID();
this.request.hashTree.push(obj);
this.reload();
},
reload() {
this.isReloadData = true
this.$nextTick(() => {
this.isReloadData = false
})
},
validate() {
this.$refs['request'].validate((valid) => {
if (valid) {
this.$emit('callback');
}
})
},
saveApi() {
this.basisData.method = this.basisData.protocol;
this.$emit('saveApi', this.basisData);
},
runTest() {
},
getEnvironments() {
this.environments = [];
let id = this.request.projectId ? this.request.projectId : this.projectId;
this.$get('/api/environment/list/' + id, response => {
this.environments = response.data;
this.environments.forEach(environment => {
parseEnvironment(environment);
});
let hasEnvironment = false;
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
hasEnvironment = true;
break;
}
}
if (!hasEnvironment) {
this.request.environmentId = undefined;
}
if (!this.request.environmentId) {
this.request.dataSourceId = undefined;
}
this.initDataSource();
});
},
openEnvironmentConfig() {
this.$refs.environmentConfig.open(getCurrentProjectID());
},
initDataSource() {
let flag = false;
let environment = {};
for (let i in this.environments) {
if (this.environments[i].id === this.request.environmentId) {
environment = this.environments[i];
break;
}
}
this.databaseConfigsOptions = [];
environment.config.databaseConfigs.forEach(item => {
if (item.id === this.request.dataSourceId) {
flag = true;
}
this.databaseConfigsOptions.push(item);
});
if (!flag) {
this.request.dataSourceId = "";
}
},
setDataSource() {
this.initDataSource();
for (let item of this.databaseConfigsOptions) {
if (this.request.dataSourceId === item.id) {
this.request.dataSource = item;
break;
}
}
},
environmentChange(value) {
this.request.dataSource = undefined;
this.request.dataSourceId = "";
let environment = {};
for (let i in this.environments) {
if (this.environments[i].id === value) {
environment = this.environments[i];
break;
}
}
this.databaseConfigsOptions = [];
environment.config.databaseConfigs.forEach(item => {
this.databaseConfigsOptions.push(item);
})
},
environmentConfigClose() {
this.getEnvironments();
},
}
}
</script>
<style scoped>
.sql-content {
height: calc(100vh - 570px);
}
.one-row .el-form-item {
display: inline-block;
}
.one-row .el-form-item:nth-child(2) {
margin-left: 60px;
}
.ms-left-cell {
margin-top: 40px;
}
.ms-left-buttion {
margin: 6px 0px 8px 30px;
}
/deep/ .el-form-item {
margin-bottom: 15px;
}
</style>

View File

@ -21,10 +21,11 @@
import MsLoopController from "./LoopController"; import MsLoopController from "./LoopController";
import MsApiScenarioComponent from "./ApiScenarioComponent"; import MsApiScenarioComponent from "./ApiScenarioComponent";
import JmeterElementComponent from "./JmeterElementComponent"; import JmeterElementComponent from "./JmeterElementComponent";
import MsJdbcProcessor from "@/business/components/api/automation/scenario/component/JDBCProcessor";
export default { export default {
name: "ComponentConfig", name: "ComponentConfig",
components: {MsConstantTimer, MsIfController, MsTransactionController, MsJsr233Processor, MsApiAssertions, MsApiExtract, MsApiComponent, MsLoopController, MsApiScenarioComponent, JmeterElementComponent}, components: {MsConstantTimer, MsIfController, MsTransactionController, MsJsr233Processor, MsApiAssertions, MsApiExtract, MsApiComponent, MsLoopController, MsApiScenarioComponent, MsJdbcProcessor,JmeterElementComponent},
props: { props: {
type: String, type: String,
scenario: {}, scenario: {},
@ -77,6 +78,12 @@
case ELEMENT_TYPE.JSR223PostProcessor: case ELEMENT_TYPE.JSR223PostProcessor:
name = this.getComponent(ELEMENT_TYPE.JSR223PostProcessor); name = this.getComponent(ELEMENT_TYPE.JSR223PostProcessor);
break; break;
case ELEMENT_TYPE.JDBCPostProcessor:
name = this.getComponent(ELEMENT_TYPE.JDBCPostProcessor);
break;
case ELEMENT_TYPE.JDBCPreProcessor:
name = this.getComponent(ELEMENT_TYPE.JDBCPreProcessor);
break;
case ELEMENT_TYPE.Assertions: case ELEMENT_TYPE.Assertions:
name = "MsApiAssertions"; name = "MsApiAssertions";
break; break;
@ -116,6 +123,16 @@
this.titleColor = "#783887"; this.titleColor = "#783887";
this.backgroundColor = "#F2ECF3"; this.backgroundColor = "#F2ECF3";
return "MsJsr233Processor"; return "MsJsr233Processor";
}if (type === ELEMENT_TYPE.JDBCPreProcessor) {
this.title = this.$t('api_test.definition.request.pre_sql');
this.titleColor = "#FE6F71";
this.backgroundColor = "#F2ECF3";
return "MsJdbcProcessor";
} else if (type === ELEMENT_TYPE.JDBCPostProcessor) {
this.title = this.$t('api_test.definition.request.post_sql');
this.titleColor = "#1483F6";
this.backgroundColor = "#F2ECF3";
return "MsJdbcProcessor";
} else { } else {
this.title = this.$t('api_test.automation.customize_script'); this.title = this.$t('api_test.automation.customize_script');
this.titleColor = "#7B4D12"; this.titleColor = "#7B4D12";

View File

@ -0,0 +1,90 @@
<template>
<api-base-component
@copy="copyRow"
@remove="remove"
@active="active"
:data="request"
:draggable="draggable"
:color="color"
:is-max="isMax"
:show-btn="showBtn"
:background-color="backgroundColor"
:title="title" v-loading="loading">
<legend style="width: 100%">
<jdbc-processor-content
:showScript="false"
:request="request"/>
</legend>
</api-base-component>
</template>
<script>
import MsCodeEdit from "../../../../common/components/MsCodeEdit";
import MsInstructionsIcon from "../../../../common/components/MsInstructionsIcon";
import MsDropdown from "../../../../common/components/MsDropdown";
import ApiBaseComponent from "../common/ApiBaseComponent";
import JdbcProcessorContent from "@/business/components/api/automation/scenario/common/JDBCProcessorContent";
export default {
name: "MsJdbcProcessor",
components: {
JdbcProcessorContent,
ApiBaseComponent, MsDropdown, MsInstructionsIcon, MsCodeEdit
},
props: {
draggable: {
type: Boolean,
default: false,
},
isMax: {
type: Boolean,
default: false,
},
showBtn: {
type: Boolean,
default: true,
},
isReadOnly: {
type: Boolean,
default:
false
},
request:Object,
title: String,
color: String,
backgroundColor: String,
node: {},
},
created() {
},
data() {
return {loading: false};
},
methods: {
remove() {
this.$emit('remove', this.request, this.node);
},
copyRow() {
this.$emit('copyRow', this.request, this.node);
},
reload() {
this.loading = true;
this.$nextTick(() => {
this.loading = false;
});
},
active() {
this.request.active = !this.request.active;
this.reload();
},
}
};
</script>
<style scoped>
/deep/ .el-divider {
margin-bottom: 10px;
}
</style>

View File

@ -1,5 +1,5 @@
import {ELEMENT_TYPE} from "@/business/components/api/automation/scenario/Setting"; import {ELEMENT_TYPE} from "@/business/components/api/automation/scenario/Setting";
import {Assertions, ConstantTimer, Extract, IfController, JSR223Processor, LoopController, TransactionController} from "@/business/components/api/definition/model/ApiTestModel"; import {Assertions, ConstantTimer, Extract, IfController, JSR223Processor, JDBCProcessor,LoopController, TransactionController} from "@/business/components/api/definition/model/ApiTestModel";
export function buttons() { export function buttons() {
let buttons = [ let buttons = [
@ -33,6 +33,26 @@ export function buttons() {
this.addComponent('JSR223PreProcessor') this.addComponent('JSR223PreProcessor')
} }
}, },
{
title: this.$t('api_test.definition.request.post_sql'),
show: this.showButton("JDBCPostProcessor"),
titleColor: "#1483F6",
titleBgColor: "#F2ECF3",
icon: "skip_next",
click: () => {
this.addComponent('JDBCPostProcessor')
}
},
{
title: this.$t('api_test.definition.request.pre_sql'),
show: this.showButton("JDBCPreProcessor"),
titleColor: "#FE6F71",
titleBgColor: "#F9F1EA",
icon: "skip_previous",
click: () => {
this.addComponent('JDBCPreProcessor')
}
},
{ {
title: this.$t('api_test.automation.customize_script'), title: this.$t('api_test.automation.customize_script'),
show: this.showButton("JSR223Processor"), show: this.showButton("JSR223Processor"),
@ -147,6 +167,14 @@ export function setComponent(type, _this) {
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new JSR223Processor({type: "JSR223PostProcessor"})) : _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new JSR223Processor({type: "JSR223PostProcessor"})) :
_this.scenarioDefinition.push(new JSR223Processor({type: "JSR223PostProcessor"})); _this.scenarioDefinition.push(new JSR223Processor({type: "JSR223PostProcessor"}));
break; break;
case ELEMENT_TYPE.JDBCPreProcessor:
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new JDBCProcessor({type: "JDBCPreProcessor"})) :
_this.scenarioDefinition.push(new JDBCProcessor({type: "JDBCPreProcessor"}));
break;
case ELEMENT_TYPE.JDBCPostProcessor:
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new JDBCProcessor({type: "JDBCPostProcessor"})) :
_this.scenarioDefinition.push(new JDBCProcessor({type: "JDBCPostProcessor"}));
break;
case ELEMENT_TYPE.Assertions: case ELEMENT_TYPE.Assertions:
_this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Assertions()) : _this.selectedTreeNode !== undefined ? _this.selectedTreeNode.hashTree.push(new Assertions()) :
_this.scenarioDefinition.push(new Assertions()); _this.scenarioDefinition.push(new Assertions());

View File

@ -0,0 +1,38 @@
import PostProcessor from "../post-processor";
const DEFAULT_OPTIONS = {
options: {
attributes: {
guiclass: "TestBeanGUI",
testclass: "JDBCPostProcessor",
testname: "JDBC PostProcessor",
enabled: "true"
},
}
};
export default class JDBCPostProcessor extends PostProcessor {
constructor(options = DEFAULT_OPTIONS) {
super(options);
this.type = "JDBCPostProcessor";
this.hashTree = [];
this.variables = [];
this.environmentId = undefined;
this.dataSource = undefined;
this.dataSourceId = undefined;
this.query = undefined;
this.queryType = undefined;
this.queryArguments = undefined;
this.queryArgumentsTypes = undefined;
this.queryTimeout = undefined;
this.resultSetHandler = undefined;
this.resultSetMaxRows = undefined;
this.resultVariable = undefined;
this.variableNames = undefined;
this.enable = true;
}
}
export const schema = {
JDBCPostProcessor: JDBCPostProcessor
}

View File

@ -0,0 +1,38 @@
import PostProcessor from "../pre-processor";
const DEFAULT_OPTIONS = {
options: {
attributes: {
guiclass: "TestBeanGUI",
testclass: "JDBCPreProcessor",
testname: "JDBC PreProcessor",
enabled: "true"
},
}
};
export default class JDBCPreProcessor extends PostProcessor {
constructor(options = DEFAULT_OPTIONS) {
super(options);
this.type = "JDBCPreProcessor";
this.hashTree = [];
this.variables = [];
this.environmentId = undefined;
this.dataSource = undefined;
this.dataSourceId = undefined;
this.query = undefined;
this.queryType = undefined;
this.queryArguments = undefined;
this.queryArgumentsTypes = undefined;
this.queryTimeout = undefined;
this.resultSetHandler = undefined;
this.resultSetMaxRows = undefined;
this.resultVariable = undefined;
this.variableNames = undefined;
this.enable = true;
}
}
export const schema = {
JDBCPreProcessor: JDBCPreProcessor
}

View File

@ -4,6 +4,10 @@
<br/> <br/>
<el-button class="ms-left-buttion" size="small" @click="addPost">+{{$t('api_test.definition.request.post_script')}}</el-button> <el-button class="ms-left-buttion" size="small" @click="addPost">+{{$t('api_test.definition.request.post_script')}}</el-button>
<br/> <br/>
<el-button class="ms-left-buttion" size="small" @click="addPreSql">+{{$t('api_test.definition.request.pre_sql')}}</el-button>
<br/>
<el-button class="ms-left-buttion" size="small" @click="addPostSql">+{{$t('api_test.definition.request.post_sql')}}</el-button>
<br/>
<el-button class="ms-left-buttion" size="small" @click="addAssertions">+{{$t('api_test.definition.request.assertions_rule')}}</el-button> <el-button class="ms-left-buttion" size="small" @click="addAssertions">+{{$t('api_test.definition.request.assertions_rule')}}</el-button>
<br/> <br/>
<el-button class="ms-left-buttion" size="small" @click="addExtract">+{{$t('api_test.definition.request.extract_param')}}</el-button> <el-button class="ms-left-buttion" size="small" @click="addExtract">+{{$t('api_test.definition.request.extract_param')}}</el-button>
@ -39,6 +43,20 @@
} }
this.request.hashTree.push(jsr223PostProcessor); this.request.hashTree.push(jsr223PostProcessor);
}, },
addPreSql() {
let jdbcPreProcessor = createComponent("JDBCPreProcessor");
if (!this.request.hashTree) {
this.request.hashTree = [];
}
this.request.hashTree.push(jdbcPreProcessor);
},
addPostSql() {
let jdbcPostProcessor = createComponent("JDBCPostProcessor");
if (!this.request.hashTree) {
this.request.hashTree = [];
}
this.request.hashTree.push(jdbcPostProcessor);
},
addAssertions() { addAssertions() {
let assertions = new Assertions(); let assertions = new Assertions();
if (!this.request.hashTree) { if (!this.request.hashTree) {
@ -71,14 +89,24 @@
background-color: #F2ECF3; background-color: #F2ECF3;
border: #F2ECF3; border: #F2ECF3;
} }
.ms-left-cell .el-button:nth-of-type(3) { .ms-left-cell .el-button:nth-of-type(3) {
color: #FE6F71;
background-color: #F9F1EA;
border: #EBF2F2;
}
.ms-left-cell .el-button:nth-of-type(4) {
color: #1483F6;
background-color: #F2ECF3;
border: #F2ECF3;
}
.ms-left-cell .el-button:nth-of-type(5) {
color: #A30014; color: #A30014;
background-color: #F7E6E9; background-color: #F7E6E9;
border: #F7E6E9; border: #F7E6E9;
} }
.ms-left-cell .el-button:nth-of-type(4) { .ms-left-cell .el-button:nth-of-type(6) {
color: #015478; color: #015478;
background-color: #E6EEF2; background-color: #E6EEF2;
border: #E6EEF2; border: #E6EEF2;

View File

@ -70,6 +70,10 @@
<br/> <br/>
<el-button class="ms-left-buttion" size="small" style="color: #783887;background-color: #F2ECF3" @click="addPost">+{{$t('api_test.definition.request.post_script')}}</el-button> <el-button class="ms-left-buttion" size="small" style="color: #783887;background-color: #F2ECF3" @click="addPost">+{{$t('api_test.definition.request.post_script')}}</el-button>
<br/> <br/>
<el-button class="ms-left-buttion" size="small" style="color: #FE6F71;background-color: #F2ECF3" @click="addPreSql">+{{$t('api_test.definition.request.pre_sql')}}</el-button>
<br/>
<el-button class="ms-left-buttion" size="small" style="color: #1483F6;background-color: #F2ECF3" @click="addPostSql">+{{$t('api_test.definition.request.post_sql')}}</el-button>
<br/>
<el-button class="ms-left-buttion" size="small" style="color: #A30014;background-color: #F7E6E9" @click="addAssertions">+{{$t('api_test.definition.request.assertions_rule')}}</el-button> <el-button class="ms-left-buttion" size="small" style="color: #A30014;background-color: #F7E6E9" @click="addAssertions">+{{$t('api_test.definition.request.assertions_rule')}}</el-button>
<br/> <br/>
<el-button class="ms-left-buttion" size="small" style="color: #015478;background-color: #E6EEF2" @click="addExtract">+{{$t('api_test.definition.request.extract_param')}}</el-button> <el-button class="ms-left-buttion" size="small" style="color: #015478;background-color: #E6EEF2" @click="addExtract">+{{$t('api_test.definition.request.extract_param')}}</el-button>
@ -151,6 +155,14 @@
this.request.hashTree.push(jsr223PostProcessor); this.request.hashTree.push(jsr223PostProcessor);
this.reload(); this.reload();
}, },
addPreSql() {
let jdbcPreProcessor = createComponent("JDBCPreProcessor");
this.request.hashTree.push(jdbcPreProcessor);
},
addPostSql() {
let jdbcPostProcessor = createComponent("JDBCPostProcessor");
this.request.hashTree.push(jdbcPostProcessor);
},
addAssertions() { addAssertions() {
let assertions = new Assertions(); let assertions = new Assertions();
this.request.hashTree.push(assertions); this.request.hashTree.push(assertions);

View File

@ -13,6 +13,14 @@
<!--后置脚本--> <!--后置脚本-->
<ms-jsr233-processor v-if="row.label ==='JSR223 PostProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.post_script')" <ms-jsr233-processor v-if="row.label ==='JSR223 PostProcessor'" @copyRow="copyRow" @remove="remove" :is-read-only="false" :title="$t('api_test.definition.request.post_script')"
:jsr223-processor="row" color="#783887" background-color="#F2ECF3"/> :jsr223-processor="row" color="#783887" background-color="#F2ECF3"/>
<!--前置SQL-->
<ms-jdbc-processor v-if="row.label ==='JDBC PreProcessor'" :title="$t('api_test.definition.request.pre_sql')"
@copyRow="copyRow" @remove="remove" :is-read-only="false"
:request="row" :jdbc-processor="row" color="#783887" background-color="#F2ECF3"/>
<!--后置SQL-->
<ms-jdbc-processor v-if="row.label ==='JDBC PostProcessor'" :title="$t('api_test.definition.request.post_sql')"
@copyRow="copyRow" @remove="remove" :is-read-only="false"
:request="row" :jdbc-processor="row" color="#783887" background-color="#F2ECF3"/>
<!--断言规则--> <!--断言规则-->
<div style="margin-top: 10px"> <div style="margin-top: 10px">
<ms-api-assertions :response="response" v-if="row.type==='Assertions'" @copyRow="copyRow" @remove="remove" :is-read-only="isReadOnly" :assertions="row"/> <ms-api-assertions :response="response" v-if="row.type==='Assertions'" @copyRow="copyRow" @remove="remove" :is-read-only="isReadOnly" :assertions="row"/>
@ -35,10 +43,12 @@
import {getUUID} from "@/common/js/utils"; import {getUUID} from "@/common/js/utils";
import BatchAddParameter from "../basis/BatchAddParameter"; import BatchAddParameter from "../basis/BatchAddParameter";
import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor"; import MsJsr233Processor from "../../../automation/scenario/component/Jsr233Processor";
import MsJdbcProcessor from "@/business/components/api/automation/scenario/component/JDBCProcessor";
export default { export default {
name: "MsJmxStep", name: "MsJmxStep",
components: { components: {
MsJdbcProcessor,
MsJsr233Processor, MsJsr233Processor,
BatchAddParameter, BatchAddParameter,
MsApiExtract, MsApiExtract,

View File

@ -854,6 +854,21 @@ export class JSR223Processor extends BaseConfig {
} }
} }
export class JDBCProcessor extends BaseConfig {
constructor(options) {
super();
this.resourceId = uuid();
this.active = false;
this.type = "JDBCProcessor";
this.enable = true;
this.variables = [];
this.dataSourceId = "";
this.hashTree = [];
this.set(options);
}
}
export class Regex extends AssertionType { export class Regex extends AssertionType {
constructor(options) { constructor(options) {
super(ASSERTION_TYPE.REGEX); super(ASSERTION_TYPE.REGEX);

View File

@ -812,6 +812,8 @@ export default {
auth_config_info: "Request requires permission verification", auth_config_info: "Request requires permission verification",
pre_script: "Prescript", pre_script: "Prescript",
post_script: "Postscript", post_script: "Postscript",
pre_sql: "JDBC Preprocessor",
post_sql: "JDBC Postprocessor",
extract_param: "Extract parameters", extract_param: "Extract parameters",
add_module: "Add module", add_module: "Add module",
edit_api: "Edit Api", edit_api: "Edit Api",

View File

@ -813,6 +813,8 @@ export default {
auth_config_info: "请求需要进行权限校验", auth_config_info: "请求需要进行权限校验",
pre_script: "前置脚本", pre_script: "前置脚本",
post_script: "后置脚本", post_script: "后置脚本",
pre_sql: "前置SQL",
post_sql: "后置SQL",
extract_param: "提取参数", extract_param: "提取参数",
add_module: "创建模块", add_module: "创建模块",
edit_api: "编辑接口", edit_api: "编辑接口",

View File

@ -813,6 +813,8 @@ export default {
auth_config_info: "請求需要進行權限校驗", auth_config_info: "請求需要進行權限校驗",
pre_script: "前置腳本", pre_script: "前置腳本",
post_script: "後置腳本", post_script: "後置腳本",
pre_sql: "前置SQL",
post_sql: "後置SQL",
extract_param: "提取參數", extract_param: "提取參數",
add_module: "創建模塊", add_module: "創建模塊",
edit_api: "編輯接口", edit_api: "編輯接口",