Merge branch 'master' of https://github.com/metersphere/metersphere
This commit is contained in:
commit
555d60fb07
|
@ -265,7 +265,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
private Arguments httpArguments(List<KeyValue> list) {
|
private Arguments httpArguments(List<KeyValue> list) {
|
||||||
Arguments arguments = new Arguments();
|
Arguments arguments = new Arguments();
|
||||||
list.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> {
|
list.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue -> {
|
||||||
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), keyValue.getValue() != null && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.calculate(keyValue.getValue()) : keyValue.getValue());
|
HTTPArgument httpArgument = new HTTPArgument(keyValue.getName(), StringUtils.isNotEmpty(keyValue.getValue()) && keyValue.getValue().startsWith("@") ? ScriptEngineUtils.calculate(keyValue.getValue()) : keyValue.getValue());
|
||||||
httpArgument.setAlwaysEncoded(keyValue.isEncode());
|
httpArgument.setAlwaysEncoded(keyValue.isEncode());
|
||||||
if (StringUtils.isNotBlank(keyValue.getContentType())) {
|
if (StringUtils.isNotBlank(keyValue.getContentType())) {
|
||||||
httpArgument.setContentType(keyValue.getContentType());
|
httpArgument.setContentType(keyValue.getContentType());
|
||||||
|
|
|
@ -1,14 +1,21 @@
|
||||||
package io.metersphere.api.dto.definition.request.sampler;
|
package io.metersphere.api.dto.definition.request.sampler;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.annotation.JSONField;
|
import com.alibaba.fastjson.annotation.JSONField;
|
||||||
import com.alibaba.fastjson.annotation.JSONType;
|
import com.alibaba.fastjson.annotation.JSONType;
|
||||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
import io.metersphere.api.dto.scenario.DatabaseConfig;
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
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.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.config.Arguments;
|
import org.apache.jmeter.config.Arguments;
|
||||||
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
import org.apache.jmeter.protocol.jdbc.config.DataSourceElement;
|
||||||
import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
|
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 org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = true)
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@ -40,6 +48,8 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
private String environmentId;
|
private String environmentId;
|
||||||
@JSONField(ordinal = 27)
|
@JSONField(ordinal = 27)
|
||||||
private Object requestResult;
|
private Object requestResult;
|
||||||
|
@JSONField(ordinal = 28)
|
||||||
|
private String dataSourceId;
|
||||||
|
|
||||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
||||||
if (!this.isEnable()) {
|
if (!this.isEnable()) {
|
||||||
|
@ -48,6 +58,12 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
if (this.getReferenced() != null && this.getReferenced().equals("REF")) {
|
if (this.getReferenced() != null && this.getReferenced().equals("REF")) {
|
||||||
this.getRefElement(this);
|
this.getRefElement(this);
|
||||||
}
|
}
|
||||||
|
if (StringUtils.isNotEmpty(dataSourceId)) {
|
||||||
|
initDataSource();
|
||||||
|
}
|
||||||
|
if (this.dataSource == null) {
|
||||||
|
MSException.throwException("数据源为空无法执行");
|
||||||
|
}
|
||||||
final HashTree samplerHashTree = tree.add(jdbcSampler());
|
final HashTree samplerHashTree = tree.add(jdbcSampler());
|
||||||
tree.add(jdbcDataSource());
|
tree.add(jdbcDataSource());
|
||||||
tree.add(arguments(this.getName() + " Variables", this.getVariables()));
|
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) {
|
private Arguments arguments(String name, List<KeyValue> variables) {
|
||||||
Arguments arguments = new Arguments();
|
Arguments arguments = new Arguments();
|
||||||
if (!variables.isEmpty()) {
|
if (!variables.isEmpty()) {
|
||||||
|
|
|
@ -49,7 +49,7 @@ public class KeyValue {
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isValid() {
|
public boolean isValid() {
|
||||||
return (StringUtils.isNotBlank(name) || StringUtils.isNotBlank(value)) && !StringUtils.equalsIgnoreCase(type, "file");
|
return (StringUtils.isNotBlank(name) && StringUtils.isNotBlank(value)) && !StringUtils.equalsIgnoreCase(type, "file");
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isFile() {
|
public boolean isFile() {
|
||||||
|
|
|
@ -134,6 +134,7 @@ public class HistoricalDataUpgradeService {
|
||||||
EnvironmentDTO dto = environmentDTOMap.get(request1.getDataSource());
|
EnvironmentDTO dto = environmentDTOMap.get(request1.getDataSource());
|
||||||
if (dto != null) {
|
if (dto != null) {
|
||||||
((MsJDBCSampler) element).setEnvironmentId(dto.getEnvironmentId());
|
((MsJDBCSampler) element).setEnvironmentId(dto.getEnvironmentId());
|
||||||
|
((MsJDBCSampler) element).setDataSourceId(dto.getDatabaseConfig().getId());
|
||||||
((MsJDBCSampler) element).setDataSource(dto.getDatabaseConfig());
|
((MsJDBCSampler) element).setDataSource(dto.getDatabaseConfig());
|
||||||
}
|
}
|
||||||
element.setType("JDBCSampler");
|
element.setType("JDBCSampler");
|
||||||
|
|
|
@ -17,7 +17,9 @@ export default class JDBCSampler extends Sampler {
|
||||||
this.type = "JDBCSampler";
|
this.type = "JDBCSampler";
|
||||||
this.hashTree = [];
|
this.hashTree = [];
|
||||||
this.variables = [];
|
this.variables = [];
|
||||||
|
this.environmentId = undefined;
|
||||||
this.dataSource = undefined;
|
this.dataSource = undefined;
|
||||||
|
this.dataSourceId = undefined;
|
||||||
this.query = undefined;
|
this.query = undefined;
|
||||||
this.queryType = undefined;
|
this.queryType = undefined;
|
||||||
this.queryArguments = undefined;
|
this.queryArguments = undefined;
|
||||||
|
|
|
@ -247,6 +247,7 @@
|
||||||
},
|
},
|
||||||
environmentChange(value) {
|
environmentChange(value) {
|
||||||
this.request.dataSource = undefined;
|
this.request.dataSource = undefined;
|
||||||
|
this.request.dataSourceId = "";
|
||||||
for (let i in this.environments) {
|
for (let i in this.environments) {
|
||||||
if (this.environments[i].id === value) {
|
if (this.environments[i].id === value) {
|
||||||
this.databaseConfigsOptions = [];
|
this.databaseConfigsOptions = [];
|
||||||
|
|
Loading…
Reference in New Issue