fix(接口自动化): 环境相关缺陷修复
This commit is contained in:
parent
7ad9d840eb
commit
7b6de572b3
|
@ -17,7 +17,6 @@ import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
|||
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.FileUtils;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -202,6 +201,7 @@ public class MsScenario extends MsTestElement {
|
|||
}
|
||||
});
|
||||
}
|
||||
// HTTP放到请求中,按照域名匹配
|
||||
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 ->
|
||||
|
|
|
@ -5,9 +5,6 @@ import com.alibaba.fastjson.annotation.JSONField;
|
|||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.fasterxml.jackson.annotation.JsonSubTypes;
|
||||
import com.fasterxml.jackson.annotation.JsonTypeInfo;
|
||||
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.assertions.MsAssertions;
|
||||
import io.metersphere.api.dto.definition.request.auth.MsAuthManager;
|
||||
import io.metersphere.api.dto.definition.request.configurations.MsHeaderManager;
|
||||
|
@ -27,11 +24,7 @@ import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
|||
import io.metersphere.api.dto.mockconfig.MockConfigStaticData;
|
||||
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.LoopConstants;
|
||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
|
@ -158,35 +151,6 @@ public abstract class MsTestElement {
|
|||
return jmeterTestPlanHashTree;
|
||||
}
|
||||
|
||||
public void getRefElement(MsTestElement element) {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
if (StringUtils.equals(element.getRefType(), "CASE")) {
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(element.getId());
|
||||
if (bloBs != null) {
|
||||
element.setProjectId(bloBs.getProjectId());
|
||||
element = mapper.readValue(bloBs.getRequest(), new TypeReference<MsTestElement>() {
|
||||
});
|
||||
hashTree.add(element);
|
||||
}
|
||||
} else {
|
||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(element.getId());
|
||||
if (apiDefinition != null) {
|
||||
element.setProjectId(apiDefinition.getProjectId());
|
||||
element = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsTestElement>() {
|
||||
});
|
||||
hashTree.add(element);
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogUtil.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public Arguments addArguments(ParameterConfig config) {
|
||||
if (config.isEffective(this.getProjectId()) && config.getConfig().get(this.getProjectId()).getCommonConfig() != null
|
||||
&& CollectionUtils.isNotEmpty(config.getConfig().get(this.getProjectId()).getCommonConfig().getVariables())) {
|
||||
|
|
|
@ -3,6 +3,9 @@ package io.metersphere.api.dto.definition.request.sampler;
|
|||
import com.alibaba.fastjson.annotation.JSONField;
|
||||
import com.alibaba.fastjson.annotation.JSONType;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import io.github.ningyu.jmeter.plugin.dubbo.sample.DubboSample;
|
||||
import io.github.ningyu.jmeter.plugin.dubbo.sample.MethodArgument;
|
||||
import io.github.ningyu.jmeter.plugin.util.Constants;
|
||||
|
@ -12,7 +15,13 @@ import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConfigCenter;
|
|||
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConsumerAndService;
|
||||
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter;
|
||||
import io.metersphere.api.dto.scenario.KeyValue;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -29,7 +38,7 @@ import java.util.stream.Collectors;
|
|||
@EqualsAndHashCode(callSuper = true)
|
||||
@JSONType(typeName = "DubboSampler")
|
||||
public class MsDubboSampler extends MsTestElement {
|
||||
// type 必须放最前面,以便能够转换正确的类
|
||||
/** type 必须放最前面,以便能够转换正确的类 */
|
||||
private String type = "DubboSampler";
|
||||
|
||||
@JSONField(ordinal = 52)
|
||||
|
@ -55,9 +64,6 @@ public class MsDubboSampler extends MsTestElement {
|
|||
@JSONField(ordinal = 60)
|
||||
private String useEnvironment;
|
||||
|
||||
// @JSONField(ordinal = 60)
|
||||
// private Object requestResult;
|
||||
|
||||
@Override
|
||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, ParameterConfig config) {
|
||||
// 非导出操作,且不是启用状态则跳过执行
|
||||
|
@ -68,7 +74,7 @@ public class MsDubboSampler extends MsTestElement {
|
|||
return;
|
||||
}
|
||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.getRefElement(this);
|
||||
this.setRefElement();
|
||||
}
|
||||
|
||||
final HashTree testPlanTree = tree.add(dubboSample(config));
|
||||
|
@ -79,6 +85,51 @@ public class MsDubboSampler extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
private void setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
if (StringUtils.equals(this.getRefType(), "CASE")) {
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
|
||||
if (bloBs != null) {
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
MsDubboSampler proxy = mapper.readValue(bloBs.getRequest(), new TypeReference<MsDubboSampler>() {
|
||||
});
|
||||
this.setHashTree(proxy.getHashTree());
|
||||
this.setName(bloBs.getName());
|
||||
this.setMethod(proxy.getMethod());
|
||||
this.set_interface(proxy.get_interface());
|
||||
this.setAttachmentArgs(proxy.getAttachmentArgs());
|
||||
this.setArgs(proxy.getArgs());
|
||||
this.setConsumerAndService(proxy.getConsumerAndService());
|
||||
this.setRegistryCenter(proxy.getRegistryCenter());
|
||||
this.setConfigCenter(proxy.getConfigCenter());
|
||||
}
|
||||
} else {
|
||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||
if (apiDefinition != null) {
|
||||
this.setProjectId(apiDefinition.getProjectId());
|
||||
MsDubboSampler proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsDubboSampler>() {
|
||||
});
|
||||
this.setHashTree(proxy.getHashTree());
|
||||
this.setName(apiDefinition.getName());
|
||||
this.setMethod(proxy.getMethod());
|
||||
this.set_interface(proxy.get_interface());
|
||||
this.setAttachmentArgs(proxy.getAttachmentArgs());
|
||||
this.setArgs(proxy.getArgs());
|
||||
this.setConsumerAndService(proxy.getConsumerAndService());
|
||||
this.setRegistryCenter(proxy.getRegistryCenter());
|
||||
this.setConfigCenter(proxy.getConfigCenter());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogUtil.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private DubboSample dubboSample(ParameterConfig config) {
|
||||
DubboSample sampler = new DubboSample();
|
||||
sampler.setEnabled(this.isEnable());
|
||||
|
|
|
@ -105,7 +105,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
@JSONField(ordinal = 36)
|
||||
private MsAuthManager authManager;
|
||||
|
||||
public void setRefElement() {
|
||||
private void setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
|
@ -203,14 +203,9 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
// 添加环境中的公共变量
|
||||
Arguments arguments = this.addArguments(config);
|
||||
if (arguments != null) {
|
||||
tree.add(ParameterConfig.valueSupposeMock(arguments));
|
||||
}
|
||||
try {
|
||||
if (config.isEffective(this.getProjectId())) {
|
||||
HttpConfig httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig());
|
||||
HttpConfig httpConfig = getHttpConfig(config.getConfig().get(this.getProjectId()).getHttpConfig(), tree);
|
||||
if (httpConfig == null) {
|
||||
MSException.throwException("未匹配到环境,请检查环境配置");
|
||||
}
|
||||
|
@ -453,31 +448,74 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
|||
* @param httpConfig
|
||||
* @return
|
||||
*/
|
||||
private HttpConfig getHttpConfig(HttpConfig httpConfig) {
|
||||
private HttpConfig getHttpConfig(HttpConfig httpConfig, HashTree tree) {
|
||||
boolean isNext = true;
|
||||
if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) {
|
||||
for (HttpConfigCondition item : httpConfig.getConditions()) {
|
||||
if (item.getType().equals(ConditionType.NONE.name())) {
|
||||
return httpConfig.initHttpConfig(item);
|
||||
} else if (item.getType().equals(ConditionType.PATH.name())) {
|
||||
if (item.getType().equals(ConditionType.PATH.name())) {
|
||||
HttpConfig config = httpConfig.getPathCondition(this.getPath());
|
||||
if (config != null) {
|
||||
return config;
|
||||
isNext = false;
|
||||
httpConfig = config;
|
||||
break;
|
||||
}
|
||||
} else if (item.getType().equals(ConditionType.MODULE.name())) {
|
||||
ApiDefinition apiDefinition;
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ApiDefinition apiDefinition = apiDefinitionService.get(this.getId());
|
||||
if (StringUtils.isNotEmpty(this.getReferenced()) && this.getReferenced().equals("REF") && StringUtils.isNotEmpty(this.getRefType()) && this.getRefType().equals("CASE")) {
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(this.getId());
|
||||
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
||||
} else {
|
||||
apiDefinition = apiDefinitionService.get(this.getId());
|
||||
}
|
||||
if (apiDefinition != null) {
|
||||
HttpConfig config = httpConfig.getModuleCondition(apiDefinition.getModuleId());
|
||||
if (config != null) {
|
||||
return config;
|
||||
isNext = false;
|
||||
httpConfig = config;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (isNext) {
|
||||
for (HttpConfigCondition item : httpConfig.getConditions()) {
|
||||
if (item.getType().equals(ConditionType.NONE.name())) {
|
||||
httpConfig = httpConfig.initHttpConfig(item);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 环境中请求头
|
||||
Arguments arguments = arguments(httpConfig.getHeaders());
|
||||
if (arguments != null) {
|
||||
tree.add(ParameterConfig.valueSupposeMock(arguments));
|
||||
}
|
||||
return httpConfig;
|
||||
}
|
||||
|
||||
private Arguments arguments(List<KeyValue> headers) {
|
||||
Arguments arguments = new Arguments();
|
||||
arguments.setEnabled(true);
|
||||
arguments.setName(StringUtils.isNotEmpty(this.getName()) ? this.getName() : "Arguments");
|
||||
arguments.setProperty(TestElement.TEST_CLASS, Arguments.class.getName());
|
||||
arguments.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("ArgumentsPanel"));
|
||||
|
||||
// HTTP放到请求中,按照域名匹配
|
||||
if (CollectionUtils.isNotEmpty(headers)) {
|
||||
headers.stream().filter(KeyValue::isValid).filter(KeyValue::isEnable).forEach(keyValue ->
|
||||
arguments.addArgument(keyValue.getName(), keyValue.getValue(), "=")
|
||||
);
|
||||
}
|
||||
if (arguments.getArguments() != null && arguments.getArguments().size() > 0) {
|
||||
return arguments;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private boolean isRest() {
|
||||
return this.getRest().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).toArray().length > 0;
|
||||
}
|
||||
|
|
|
@ -3,16 +3,24 @@ 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 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.MsTestElementConstants;
|
||||
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;
|
||||
|
@ -46,8 +54,6 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
private List<KeyValue> variables;
|
||||
@JSONField(ordinal = 26)
|
||||
private String environmentId;
|
||||
// @JSONField(ordinal = 27)
|
||||
// private Object requestResult;
|
||||
@JSONField(ordinal = 28)
|
||||
private String dataSourceId;
|
||||
@JSONField(ordinal = 29)
|
||||
|
@ -63,7 +69,7 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
return;
|
||||
}
|
||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.getRefElement(this);
|
||||
this.setRefElement();
|
||||
}
|
||||
if (StringUtils.isNotEmpty(dataSourceId)) {
|
||||
this.dataSource = null;
|
||||
|
@ -85,6 +91,51 @@ public class MsJDBCSampler extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
private void setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
if (StringUtils.equals(this.getRefType(), "CASE")) {
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
|
||||
if (bloBs != null) {
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
MsJDBCSampler proxy = mapper.readValue(bloBs.getRequest(), new TypeReference<MsJDBCSampler>() {
|
||||
});
|
||||
this.setHashTree(proxy.getHashTree());
|
||||
this.setName(bloBs.getName());
|
||||
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());
|
||||
}
|
||||
} else {
|
||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||
if (apiDefinition != null) {
|
||||
this.setProjectId(apiDefinition.getProjectId());
|
||||
MsJDBCSampler proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsJDBCSampler>() {
|
||||
});
|
||||
this.setHashTree(proxy.getHashTree());
|
||||
this.setName(apiDefinition.getName());
|
||||
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);
|
||||
|
|
|
@ -2,13 +2,22 @@ package io.metersphere.api.dto.definition.request.sampler;
|
|||
|
||||
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.automation.EsbDataStruct;
|
||||
import io.metersphere.api.dto.definition.request.MsTestElement;
|
||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||
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.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.LogUtil;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
|
@ -24,7 +33,9 @@ import org.apache.jmeter.testelement.property.StringProperty;
|
|||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(callSuper = true)
|
||||
|
@ -58,8 +69,6 @@ public class MsTCPSampler extends MsTestElement {
|
|||
private String password = "";
|
||||
@JSONField(ordinal = 33)
|
||||
private String request;
|
||||
// @JSONField(ordinal = 34)
|
||||
// private Object requestResult;
|
||||
@JSONField(ordinal = 35)
|
||||
private List<KeyValue> parameters;
|
||||
@JSONField(ordinal = 36)
|
||||
|
@ -84,14 +93,14 @@ public class MsTCPSampler extends MsTestElement {
|
|||
return;
|
||||
}
|
||||
if (this.getReferenced() != null && MsTestElementConstants.REF.name().equals(this.getReferenced())) {
|
||||
this.getRefElement(this);
|
||||
this.setRefElement();
|
||||
}
|
||||
if (config.getConfig() == null) {
|
||||
// 单独接口执行
|
||||
this.setProjectId(config.getProjectId());
|
||||
config.setConfig(getEnvironmentConfig(useEnvironment));
|
||||
}
|
||||
if(config.getConfig()!=null){
|
||||
if (config.getConfig() != null) {
|
||||
parseEnvironment(config.getConfig().get(this.projectId));
|
||||
}
|
||||
|
||||
|
@ -115,6 +124,45 @@ public class MsTCPSampler extends MsTestElement {
|
|||
}
|
||||
}
|
||||
|
||||
private void setRefElement() {
|
||||
try {
|
||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||
ObjectMapper mapper = new ObjectMapper();
|
||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
if (StringUtils.equals(this.getRefType(), "CASE")) {
|
||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
|
||||
if (bloBs != null) {
|
||||
this.setProjectId(bloBs.getProjectId());
|
||||
MsTCPSampler proxy = mapper.readValue(bloBs.getRequest(), new TypeReference<MsTCPSampler>() {
|
||||
});
|
||||
this.setHashTree(proxy.getHashTree());
|
||||
this.setName(bloBs.getName());
|
||||
this.setClassname(proxy.getClassname());
|
||||
this.setServer(proxy.getServer());
|
||||
this.setPort(proxy.getPort());
|
||||
this.setRequest(proxy.getRequest());
|
||||
}
|
||||
} else {
|
||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||
if (apiDefinition != null) {
|
||||
this.setProjectId(apiDefinition.getProjectId());
|
||||
MsTCPSampler proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsTCPSampler>() {
|
||||
});
|
||||
this.setHashTree(proxy.getHashTree());
|
||||
this.setName(apiDefinition.getName());
|
||||
this.setClassname(proxy.getClassname());
|
||||
this.setServer(proxy.getServer());
|
||||
this.setPort(proxy.getPort());
|
||||
this.setRequest(proxy.getRequest());
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
ex.printStackTrace();
|
||||
LogUtil.error(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
private void parseEnvironment(EnvironmentConfig config) {
|
||||
if (!isCustomizeReq() && config != null && config.getTcpConfig() != null) {
|
||||
this.server = config.getTcpConfig().getServer();
|
||||
|
|
|
@ -12,4 +12,5 @@ public class HttpConfigCondition {
|
|||
private String socket;
|
||||
private String domain;
|
||||
private int port;
|
||||
private List<KeyValue> headers;
|
||||
}
|
||||
|
|
|
@ -280,8 +280,10 @@ public class APIBackendListenerClient extends AbstractBackendListenerClient impl
|
|||
|
||||
}
|
||||
}
|
||||
if (reportTask != null && StringUtils.equals(ReportTriggerMode.API.name(), reportTask.getTriggerMode()) || StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), reportTask.getTriggerMode())) {
|
||||
sendTask(reportTask, reportUrl, testResult);
|
||||
if (reportTask != null) {
|
||||
if (StringUtils.equals(ReportTriggerMode.API.name(), reportTask.getTriggerMode()) || StringUtils.equals(ReportTriggerMode.SCHEDULE.name(), reportTask.getTriggerMode())) {
|
||||
sendTask(reportTask, reportUrl, testResult);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -209,7 +209,7 @@
|
|||
<api-import v-if="type!=='detail'" ref="apiImport" :saved="false" @refresh="apiImport"/>
|
||||
|
||||
<!--步骤最大化-->
|
||||
<ms-drawer :visible="drawer" :size="100" @close="close" direction="right" :show-full-screen="false" :is-show-close="false" style="overflow: hidden">
|
||||
<ms-drawer :visible="drawer" :size="100" @close="close" direction="default" :show-full-screen="false" :is-show-close="false" style="overflow: hidden">
|
||||
<template v-slot:header>
|
||||
<scenario-header :currentScenario="currentScenario" :projectEnvMap="projectEnvMap" :projectIds.sync="projectIds" :projectList="projectList" :scenarioDefinition="scenarioDefinition" :enableCookieShare="enableCookieShare"
|
||||
:isFullUrl.sync="isFullUrl" @closePage="close" @unFullScreen="unFullScreen" @showAllBtn="showAllBtn" @runDebug="runDebug" @setProjectEnvMap="setProjectEnvMap" @showScenarioParameters="showScenarioParameters" @setCookieShare="setCookieShare"
|
||||
|
@ -668,7 +668,6 @@
|
|||
this.customizeRequest = {};
|
||||
this.sort();
|
||||
this.reload();
|
||||
// this.initProjectIds();
|
||||
},
|
||||
addScenario(arr) {
|
||||
if (arr && arr.length > 0) {
|
||||
|
@ -691,7 +690,6 @@
|
|||
this.isBtnHide = false;
|
||||
this.sort();
|
||||
this.reload();
|
||||
// this.initProjectIds();
|
||||
},
|
||||
setApiParameter(item, refType, referenced) {
|
||||
let request = {};
|
||||
|
@ -733,7 +731,6 @@
|
|||
this.isBtnHide = false;
|
||||
this.sort();
|
||||
this.reload();
|
||||
// this.initProjectIds();
|
||||
},
|
||||
getMaintainerOptions() {
|
||||
let workspaceId = localStorage.getItem(WORKSPACE_ID);
|
||||
|
@ -760,7 +757,6 @@
|
|||
hashTree.splice(index, 1);
|
||||
this.sort();
|
||||
this.reload();
|
||||
// this.initProjectIds();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -788,9 +784,6 @@
|
|||
this.$nextTick(() => {
|
||||
this.loading = false
|
||||
});
|
||||
// let definition = JSON.parse(JSON.stringify(this.currentScenario));
|
||||
// definition.hashTree = this.scenarioDefinition;
|
||||
// this.getEnv(JSON.stringify(definition));
|
||||
},
|
||||
runDebug() {
|
||||
/*触发执行操作*/
|
||||
|
@ -1055,8 +1048,6 @@
|
|||
}
|
||||
this.loading = false;
|
||||
this.sort();
|
||||
// this.initProjectIds();
|
||||
// this.getEnvironments();
|
||||
})
|
||||
}
|
||||
},
|
||||
|
@ -1125,19 +1116,8 @@
|
|||
})
|
||||
},
|
||||
refReload() {
|
||||
// this.initProjectIds();
|
||||
this.reload();
|
||||
},
|
||||
initProjectIds() {
|
||||
// // 加载环境配置
|
||||
// this.$nextTick(() => {
|
||||
// this.projectIds.clear();
|
||||
// this.scenarioDefinition.forEach(data => {
|
||||
// let arr = jsonPath.query(data, "$..projectId");
|
||||
// arr.forEach(a => this.projectIds.add(a));
|
||||
// })
|
||||
// })
|
||||
},
|
||||
detailRefresh(result) {
|
||||
// 把执行结果分发给各个请求
|
||||
this.debugResult = result;
|
||||
|
|
|
@ -35,11 +35,11 @@
|
|||
if (!this.result) {
|
||||
this.getExecResult();
|
||||
if (this.apiItem.isActive) {
|
||||
this.isActive = true;
|
||||
// this.isActive = true;
|
||||
}
|
||||
} else {
|
||||
this.response = this.result;
|
||||
this.isActive = true;
|
||||
// this.isActive = true;
|
||||
}
|
||||
},
|
||||
watch: {
|
||||
|
|
|
@ -111,11 +111,11 @@
|
|||
<style scoped>
|
||||
.ms-btn {
|
||||
width: 20%;
|
||||
margin-left: 20px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
|
||||
.ms-select {
|
||||
width: 10%;
|
||||
margin-left: 10px;
|
||||
width: 15%;
|
||||
margin-left: 5px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<template>
|
||||
<el-form :model="condition" :rules="rules" ref="httpConfig">
|
||||
<el-form :model="condition" :rules="rules" ref="httpConfig" class="ms-el-form-item__content">
|
||||
<el-form-item prop="socket">
|
||||
<span class="ms-env-span">{{$t('api_test.environment.socket')}}</span>
|
||||
<el-input v-model="condition.socket" style="width: 80%" :placeholder="$t('api_test.request.url_description')" clearable size="small">
|
||||
|
@ -34,15 +34,19 @@
|
|||
</template>
|
||||
</el-input>
|
||||
</div>
|
||||
|
||||
<p>{{$t('api_test.request.headers')}}</p>
|
||||
<ms-api-key-value :items="condition.headers" :isShowEnable="true" :suggestions="headerSuggestions"/>
|
||||
|
||||
</el-form-item>
|
||||
<div class="ms-border">
|
||||
<el-table :data="httpConfig.conditions" highlight-current-row @current-change="selectRow" v-if="!loading">
|
||||
<el-table-column prop="socket" :label="$t('load_test.domain')" width="180">
|
||||
<el-table-column prop="socket" :label="$t('load_test.domain')" show-overflow-tooltip width="180">
|
||||
<template v-slot:default="{row}">
|
||||
{{getUrl(row)}}
|
||||
</template>
|
||||
</el-table-column>
|
||||
<el-table-column prop="type" :label="$t('api_test.environment.condition_enable')" show-overflow-tooltip min-width="120px">
|
||||
<el-table-column prop="type" :label="$t('api_test.environment.condition_enable')" show-overflow-tooltip min-width="100px">
|
||||
<template v-slot:default="{row}">
|
||||
{{getName(row)}}
|
||||
</template>
|
||||
|
@ -65,8 +69,6 @@
|
|||
</el-table-column>
|
||||
</el-table>
|
||||
</div>
|
||||
<span>{{$t('api_test.request.headers')}}</span>
|
||||
<ms-api-key-value :items="httpConfig.headers" :isShowEnable="true" :suggestions="headerSuggestions"/>
|
||||
</el-form>
|
||||
</template>
|
||||
|
||||
|
@ -112,7 +114,7 @@
|
|||
},
|
||||
loading: false,
|
||||
pathDetails: new KeyValue({name: "", value: "contains"}),
|
||||
condition: {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0},
|
||||
condition: {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0, headers: [new KeyValue()]},
|
||||
};
|
||||
},
|
||||
watch: {
|
||||
|
@ -121,16 +123,17 @@
|
|||
},
|
||||
httpConfig: function (o) {
|
||||
// 历史数据处理
|
||||
if (this.httpConfig && this.httpConfig.socket) {
|
||||
if (this.httpConfig && this.httpConfig.socket && this.httpConfig.conditions && this.httpConfig.conditions.length === 0) {
|
||||
this.condition.type = "NONE";
|
||||
this.condition.socket = this.httpConfig.socket;
|
||||
this.condition.protocol = this.httpConfig.protocol;
|
||||
this.condition.port = this.httpConfig.port;
|
||||
this.condition.domain = this.httpConfig.domain;
|
||||
this.condition.time = new Date().getTime();
|
||||
this.condition.headers = this.httpConfig.headers;
|
||||
this.add();
|
||||
}
|
||||
this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0};
|
||||
this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", port: 0, headers: [new KeyValue()]};
|
||||
},
|
||||
},
|
||||
methods: {
|
||||
|
@ -172,6 +175,9 @@
|
|||
this.httpConfig.protocol = row.protocol;
|
||||
this.httpConfig.port = row.port;
|
||||
this.condition = row;
|
||||
if (!this.condition.headers) {
|
||||
this.condition.headers = [new KeyValue()];
|
||||
}
|
||||
if (row.type === "PATH" && row.details.length > 0) {
|
||||
this.pathDetails = JSON.parse(JSON.stringify(row.details[0]));
|
||||
} else if (row.type === "MODULE" && row.details.length > 0) {
|
||||
|
@ -216,7 +222,7 @@
|
|||
const index = this.httpConfig.conditions.findIndex((d) => d.id === this.condition.id);
|
||||
this.validateSocket(this.condition.socket);
|
||||
let obj = {
|
||||
id: this.condition.id, type: this.condition.type, domain: this.condition.domain, socket: this.condition.socket,
|
||||
id: this.condition.id, type: this.condition.type, domain: this.condition.domain, socket: this.condition.socket, headers: this.condition.headers,
|
||||
protocol: this.condition.protocol, details: this.condition.details, port: this.condition.port, time: this.condition.time
|
||||
};
|
||||
if (obj.type === "PATH") {
|
||||
|
@ -224,7 +230,7 @@
|
|||
}
|
||||
if (index !== -1) {
|
||||
Vue.set(this.httpConfig.conditions[index], obj, 1);
|
||||
this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "", socket: "", domain: ""};
|
||||
this.condition = {type: "NONE", details: [new KeyValue({name: "", value: "contains"})], protocol: "http", socket: "", domain: "", headers: [new KeyValue()]};
|
||||
this.reload();
|
||||
}
|
||||
},
|
||||
|
@ -235,8 +241,9 @@
|
|||
});
|
||||
},
|
||||
add() {
|
||||
this.validateSocket();
|
||||
let obj = {
|
||||
id: getUUID(), type: this.condition.type, socket: this.condition.socket, protocol: this.condition.protocol,
|
||||
id: getUUID(), type: this.condition.type, socket: this.condition.socket, protocol: this.condition.protocol, headers: this.condition.headers,
|
||||
domain: this.condition.domain, port: this.condition.port, time: new Date().getTime()
|
||||
};
|
||||
if (this.condition.type === "PATH") {
|
||||
|
@ -256,7 +263,7 @@
|
|||
},
|
||||
copy(row) {
|
||||
const index = this.httpConfig.conditions.findIndex((d) => d.id === row.id);
|
||||
let obj = {id: getUUID(), type: row.type, socket: row.socket, details: row.details, protocol: row.protocol, domain: row.domain, time: new Date().getTime()};
|
||||
let obj = {id: getUUID(), type: row.type, socket: row.socket, details: row.details, protocol: row.protocol, headers: JSON.parse(JSON.stringify(this.condition.headers)), domain: row.domain, time: new Date().getTime()};
|
||||
if (index != -1) {
|
||||
this.httpConfig.conditions.splice(index, 0, obj);
|
||||
} else {
|
||||
|
@ -306,4 +313,8 @@
|
|||
/deep/ .el-form-item {
|
||||
margin-bottom: 10px;
|
||||
}
|
||||
|
||||
.ms-el-form-item__content >>> .el-form-item__content {
|
||||
line-height: 20px;
|
||||
}
|
||||
</style>
|
||||
|
|
|
@ -5,6 +5,9 @@
|
|||
|
||||
<ms-right2-left-drag-bar v-if="direction == 'right'"/>
|
||||
|
||||
<ms-right2-left-drag-bar v-if="direction == 'default'"/>
|
||||
|
||||
|
||||
<div class="ms-drawer-header">
|
||||
<slot name="header"></slot>
|
||||
<i v-if="isShowClose" class="el-icon-close" @click="close"/>
|
||||
|
@ -120,6 +123,14 @@
|
|||
this.directionStyle = 'bottom-style';
|
||||
this.dragBarDirection = 'vertical';
|
||||
break;
|
||||
default:
|
||||
this.w = this.getWidthPercentage(this.size);
|
||||
this.h = this.getHeightPercentage(100);
|
||||
this.x = document.body.clientWidth - this.w;
|
||||
this.y = 0;
|
||||
this.directionStyle = 'right-style';
|
||||
this.dragBarDirection = 'horizontal';
|
||||
break;
|
||||
}
|
||||
},
|
||||
getWidthPercentage(per) {
|
||||
|
@ -156,6 +167,10 @@
|
|||
case 'bottom':
|
||||
this.w = document.documentElement.clientWidth;
|
||||
break;
|
||||
default:
|
||||
this.h = document.documentElement.clientHeight;
|
||||
this.w = document.documentElement.clientWidth;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue