fix(接口自动化): 解决sql类型数据源 无法回显问题,并对历史数据进行兼容
This commit is contained in:
parent
540aba788c
commit
c0fb16571a
|
@ -1,14 +1,21 @@
|
|||
package io.metersphere.api.dto.definition.request.sampler;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
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.ApiTestEnvironmentService;
|
||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
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.sampler.JDBCSampler;
|
||||
|
@ -17,6 +24,7 @@ import org.apache.jmeter.testelement.TestElement;
|
|||
import org.apache.jorphan.collections.HashTree;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -40,6 +48,8 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
private String environmentId;
|
||||
@JSONField(ordinal = 27)
|
||||
private Object requestResult;
|
||||
@JSONField(ordinal = 28)
|
||||
private String dataSourceId;
|
||||
|
||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
||||
if (!this.isEnable()) {
|
||||
|
@ -48,6 +58,12 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
if (this.getReferenced() != null && this.getReferenced().equals("REF")) {
|
||||
this.getRefElement(this);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dataSourceId)) {
|
||||
initDataSource();
|
||||
}
|
||||
if (this.dataSource == null) {
|
||||
MSException.throwException("数据源为空无法执行");
|
||||
}
|
||||
final HashTree samplerHashTree = tree.add(jdbcSampler());
|
||||
tree.add(jdbcDataSource());
|
||||
tree.add(arguments(this.getName() + " Variables", this.getVariables()));
|
||||
|
@ -58,6 +74,20 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
private void initDataSource() {
|
||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(this.dataSourceId);
|
||||
if (environment != null && environment.getConfig() != null) {
|
||||
EnvironmentConfig config = JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
||||
if (CollectionUtils.isNotEmpty(config.getDatabaseConfigs())) {
|
||||
List<DatabaseConfig> databaseConfigs = config.getDatabaseConfigs().stream().filter((DatabaseConfig d) -> this.dataSourceId.equals(d.getId())).collect(Collectors.toList());
|
||||
if (CollectionUtils.isNotEmpty(databaseConfigs)) {
|
||||
this.dataSource = databaseConfigs.get(0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Arguments arguments(String name, List<KeyValue> variables) {
|
||||
Arguments arguments = new Arguments();
|
||||
if (!variables.isEmpty()) {
|
||||
|
|
|
@ -134,6 +134,7 @@ public class HistoricalDataUpgradeService {
|
|||
EnvironmentDTO dto = environmentDTOMap.get(request1.getDataSource());
|
||||
if (dto != null) {
|
||||
((MsJDBCSampler) element).setEnvironmentId(dto.getEnvironmentId());
|
||||
((MsJDBCSampler) element).setDataSourceId(dto.getDatabaseConfig().getId());
|
||||
((MsJDBCSampler) element).setDataSource(dto.getDatabaseConfig());
|
||||
}
|
||||
element.setType("JDBCSampler");
|
||||
|
|
|
@ -17,7 +17,9 @@ export default class JDBCSampler extends Sampler {
|
|||
this.type = "JDBCSampler";
|
||||
this.hashTree = [];
|
||||
this.variables = [];
|
||||
this.environmentId = undefined;
|
||||
this.dataSource = undefined;
|
||||
this.dataSourceId = undefined;
|
||||
this.query = undefined;
|
||||
this.queryType = undefined;
|
||||
this.queryArguments = undefined;
|
||||
|
|
|
@ -247,6 +247,7 @@
|
|||
},
|
||||
environmentChange(value) {
|
||||
this.request.dataSource = undefined;
|
||||
this.request.dataSourceId = "";
|
||||
for (let i in this.environments) {
|
||||
if (this.environments[i].id === value) {
|
||||
this.databaseConfigsOptions = [];
|
||||
|
|
Loading…
Reference in New Issue