refactor(接口测试): 重构基本数据格式
This commit is contained in:
parent
8ae4743d42
commit
a3d3fc8366
|
@ -189,7 +189,7 @@ public class MsScenario extends MsTestElement {
|
|||
}
|
||||
});
|
||||
}
|
||||
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
|
||||
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
|
||||
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) {
|
||||
config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables().stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
||||
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
|
||||
|
|
|
@ -47,8 +47,10 @@ import org.apache.jorphan.collections.HashTree;
|
|||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.EXISTING_PROPERTY, property = "type")
|
||||
|
@ -166,7 +168,7 @@ public abstract class MsTestElement {
|
|||
}
|
||||
|
||||
public Arguments addArguments(ParameterConfig config) {
|
||||
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
|
||||
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
|
||||
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) {
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.setEnabled(true);
|
||||
|
@ -181,11 +183,14 @@ public abstract class MsTestElement {
|
|||
return null;
|
||||
}
|
||||
|
||||
protected EnvironmentConfig getEnvironmentConfig(String environmentId) {
|
||||
protected Map<String, EnvironmentConfig> getEnvironmentConfig(String environmentId) {
|
||||
ApiTestEnvironmentService environmentService = CommonBeanFactory.getBean(ApiTestEnvironmentService.class);
|
||||
ApiTestEnvironmentWithBLOBs environment = environmentService.get(environmentId);
|
||||
if (environment != null && environment.getConfig() != null) {
|
||||
return JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class);
|
||||
// 单独接口执行
|
||||
Map<String, EnvironmentConfig> map = new HashMap<>();
|
||||
map.put(this.getProjectId(), JSONObject.parseObject(environment.getConfig(), EnvironmentConfig.class));
|
||||
return map;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -269,7 +274,7 @@ public abstract class MsTestElement {
|
|||
getFullPath(element.getParent(), path);
|
||||
}
|
||||
|
||||
protected String getParentName(MsTestElement parent, ParameterConfig config) {
|
||||
protected String getParentName(MsTestElement parent) {
|
||||
if (parent != null) {
|
||||
if (MsTestElementConstants.LoopController.name().equals(parent.getType())) {
|
||||
MsLoopController loopController = (MsLoopController) parent;
|
||||
|
|
|
@ -30,4 +30,11 @@ public class ParameterConfig {
|
|||
* 项目ID,支持单接口执行
|
||||
*/
|
||||
private String projectId;
|
||||
|
||||
public boolean isEffective(String projectId) {
|
||||
if (this.config != null && this.config.get(projectId) != null) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -36,7 +36,7 @@ public class MsJSR223Processor extends MsTestElement {
|
|||
} else {
|
||||
processor.setName("JSR223Processor");
|
||||
}
|
||||
String name = this.getParentName(this.getParent(), config);
|
||||
String name = this.getParentName(this.getParent());
|
||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
||||
processor.setName(this.getName() + "<->" + name);
|
||||
}
|
||||
|
|
|
@ -76,7 +76,7 @@ public class MsDubboSampler extends MsTestElement {
|
|||
DubboSample sampler = new DubboSample();
|
||||
sampler.setEnabled(this.isEnable());
|
||||
sampler.setName(this.getName());
|
||||
String name = this.getParentName(this.getParent(), config);
|
||||
String name = this.getParentName(this.getParent());
|
||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
||||
sampler.setName(this.getName() + "<->" + name);
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
|
|||
import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager;
|
||||
import io.metersphere.api.dto.scenario.Body;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import io.metersphere.commons.utils.ScriptEngineUtils;
|
||||
|
@ -101,7 +100,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
HTTPSamplerProxy sampler = new HTTPSamplerProxy();
|
||||
sampler.setEnabled(this.isEnable());
|
||||
sampler.setName(this.getName());
|
||||
String name = this.getParentName(this.getParent(), config);
|
||||
String name = this.getParentName(this.getParent());
|
||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
||||
sampler.setName(this.getName() + "<->" + name);
|
||||
}
|
||||
|
@ -114,14 +113,10 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
sampler.setFollowRedirects(this.isFollowRedirects());
|
||||
sampler.setUseKeepAlive(true);
|
||||
sampler.setDoMultipart(this.isDoMultipartPost());
|
||||
if (config != null && config.getConfig() != null) {
|
||||
config.setConfig(config.getConfig());
|
||||
} else {
|
||||
if (config.getConfig() == null) {
|
||||
// 单独接口执行
|
||||
this.setProjectId(config.getProjectId());
|
||||
Map<String, EnvironmentConfig> map = new HashMap<>();
|
||||
map.put(this.getProjectId(), getEnvironmentConfig(useEnvironment));
|
||||
config.setConfig(map);
|
||||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||
}
|
||||
|
||||
// 添加环境中的公共变量
|
||||
|
@ -130,7 +125,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
tree.add(arguments);
|
||||
}
|
||||
try {
|
||||
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null) {
|
||||
if (config.isEffective(this.getProjectId())) {
|
||||
String url = config.getConfig().get(this.getProjectId()).getHttpConfig().getProtocol() + "://" + config.getConfig().get(this.getProjectId()).getHttpConfig().getSocket();
|
||||
// 补充如果是完整URL 则用自身URL
|
||||
boolean isUrl = false;
|
||||
|
@ -219,13 +214,13 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
|
||||
// 通用请求Headers
|
||||
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getHttpConfig() != null
|
||||
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getHttpConfig() != null
|
||||
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders())) {
|
||||
setHeader(httpSamplerTree, config.getConfig().get(this.getProjectId()).getHttpConfig().getHeaders());
|
||||
}
|
||||
|
||||
//判断是否要开启DNS
|
||||
if (config != null && config.getConfig() != null && config.getConfig().get(this.getProjectId()) != null && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
|
||||
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
|
||||
&& config.getConfig().get(this.getProjectId()).getCommonConfig().isEnableHost()) {
|
||||
MsDNSCacheManager.addEnvironmentVariables(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()));
|
||||
MsDNSCacheManager.addEnvironmentDNS(httpSamplerTree, this.getName(), config.getConfig().get(this.getProjectId()));
|
||||
|
|
|
@ -113,7 +113,7 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
JDBCSampler sampler = new JDBCSampler();
|
||||
sampler.setEnabled(this.isEnable());
|
||||
sampler.setName(this.getName());
|
||||
String name = this.getParentName(this.getParent(), config);
|
||||
String name = this.getParentName(this.getParent());
|
||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
||||
sampler.setName(this.getName() + "<->" + name);
|
||||
}
|
||||
|
|
|
@ -23,9 +23,7 @@ import org.apache.jmeter.testelement.property.StringProperty;
|
|||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
import java.util.*;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -59,7 +57,7 @@ public class MsTCPSampler extends MsTestElement {
|
|||
private String password = "";
|
||||
@JSONField(ordinal = 33)
|
||||
private String request;
|
||||
// @JSONField(ordinal = 34)
|
||||
// @JSONField(ordinal = 34)
|
||||
// private Object requestResult;
|
||||
@JSONField(ordinal = 35)
|
||||
private List<KeyValue> parameters;
|
||||
|
@ -77,7 +75,11 @@ public class MsTCPSampler extends MsTestElement {
|
|||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.getRefElement(this);
|
||||
}
|
||||
// config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||
if (config.getConfig() == null) {
|
||||
// 单独接口执行
|
||||
this.setProjectId(config.getProjectId());
|
||||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||
}
|
||||
parseEnvironment(config.getConfig().get(this.projectId));
|
||||
|
||||
// 添加环境中的公共变量
|
||||
|
@ -111,7 +113,7 @@ public class MsTCPSampler extends MsTestElement {
|
|||
TCPSampler tcpSampler = new TCPSampler();
|
||||
tcpSampler.setEnabled(this.isEnable());
|
||||
tcpSampler.setName(this.getName());
|
||||
String name = this.getParentName(this.getParent(), config);
|
||||
String name = this.getParentName(this.getParent());
|
||||
if (StringUtils.isNotEmpty(name) && !config.isOperating()) {
|
||||
tcpSampler.setName(this.getName() + "<->" + name);
|
||||
}
|
||||
|
|
|
@ -146,6 +146,9 @@
|
|||
if (!this.response.body) {
|
||||
this.response.body = "";
|
||||
}
|
||||
if(!this.response.responseResult.vars){
|
||||
this.response.responseResult.vars="";
|
||||
}
|
||||
this.reqMessages = this.$t('api_test.request.address') + ":\n" + this.response.url + "\n" +
|
||||
this.$t('api_test.scenario.headers') + ":\n" + this.response.headers + "\n" + "Cookies :\n" +
|
||||
this.response.cookies + "\n" + "Bpdy:" + "\n" + this.response.body;
|
||||
|
|
Loading…
Reference in New Issue