refactor(接口测试): Sampler相关代码优化
This commit is contained in:
parent
70faafe07a
commit
0efab80872
|
@ -3,8 +3,10 @@ package io.metersphere.api.dto.definition.parse;
|
||||||
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
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.MsJSR223PreProcessor;
|
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||||
|
import io.metersphere.api.dto.scenario.HttpConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.GlobalScriptConfig;
|
import io.metersphere.api.dto.scenario.environment.GlobalScriptConfig;
|
||||||
|
import io.metersphere.api.dto.scenario.environment.GlobalScriptFilterRequest;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
@ -83,10 +85,48 @@ public class JMeterScriptUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void addItemHashTree(MsTestElement element, HashTree samplerHashTree, ParameterConfig config, String enviromentId) {
|
private static void addItemHashTree(MsTestElement element, HashTree samplerHashTree, ParameterConfig config, String environmentId) {
|
||||||
if (element != null) {
|
if (element != null) {
|
||||||
element.setEnvironmentId(element.getEnvironmentId() == null ? enviromentId : element.getEnvironmentId());
|
element.setEnvironmentId(element.getEnvironmentId() == null ? environmentId : element.getEnvironmentId());
|
||||||
element.toHashTree(samplerHashTree, element.getHashTree(), config);
|
element.toHashTree(samplerHashTree, element.getHashTree(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setHttpScript(HttpConfig httpConfig, HashTree httpSamplerTree, ParameterConfig config, String useEnvironment, String environmentId) {
|
||||||
|
MsJSR223PreProcessor preProcessor = httpConfig.getPreProcessor();
|
||||||
|
MsJSR223PostProcessor postProcessor = httpConfig.getPostProcessor();
|
||||||
|
GlobalScriptConfig globalScriptConfig = httpConfig.getGlobalScriptConfig();
|
||||||
|
List<String> filterPreProtocal = globalScriptConfig == null ? null : globalScriptConfig.getFilterRequestPreScript();
|
||||||
|
List<String> filterPostProtocal = globalScriptConfig == null ? null : globalScriptConfig.getFilterRequestPostScript();
|
||||||
|
|
||||||
|
boolean filterPre = JMeterScriptUtil.isScriptFilter(filterPreProtocal, GlobalScriptFilterRequest.HTTP.name());
|
||||||
|
boolean filterPost = JMeterScriptUtil.isScriptFilter(filterPostProtocal, GlobalScriptFilterRequest.HTTP.name());
|
||||||
|
boolean isPreScriptExecAfterPrivateScript = globalScriptConfig == null ? false : globalScriptConfig.isPreScriptExecAfterPrivateScript();
|
||||||
|
boolean isPostScriptExecAfterPrivateScript = globalScriptConfig == null ? false : globalScriptConfig.isPostScriptExecAfterPrivateScript();
|
||||||
|
|
||||||
|
if (!filterPre && preProcessor != null && StringUtils.isNotEmpty(preProcessor.getScript())) {
|
||||||
|
if ((isPreScriptExecAfterPrivateScript) || (!isPreScriptExecAfterPrivateScript)) {
|
||||||
|
if (preProcessor.getEnvironmentId() == null) {
|
||||||
|
if (environmentId == null) {
|
||||||
|
preProcessor.setEnvironmentId(useEnvironment);
|
||||||
|
} else {
|
||||||
|
preProcessor.setEnvironmentId(useEnvironment);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
preProcessor.toHashTree(httpSamplerTree, preProcessor.getHashTree(), config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!filterPost && postProcessor != null && StringUtils.isNotEmpty(postProcessor.getScript())) {
|
||||||
|
if ((isPostScriptExecAfterPrivateScript) || (!isPostScriptExecAfterPrivateScript)) {
|
||||||
|
if (postProcessor.getEnvironmentId() == null) {
|
||||||
|
if (environmentId == null) {
|
||||||
|
postProcessor.setEnvironmentId(useEnvironment);
|
||||||
|
} else {
|
||||||
|
postProcessor.setEnvironmentId(environmentId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
postProcessor.toHashTree(httpSamplerTree, postProcessor.getHashTree(), config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,6 +28,7 @@ import io.metersphere.constants.RunModeConstants;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
import io.metersphere.service.EnvironmentGroupProjectService;
|
import io.metersphere.service.EnvironmentGroupProjectService;
|
||||||
|
import io.metersphere.utils.LoggerUtil;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
import org.apache.jmeter.config.Arguments;
|
import org.apache.jmeter.config.Arguments;
|
||||||
|
@ -36,6 +37,7 @@ import org.apache.jmeter.config.RandomVariableConfig;
|
||||||
import org.apache.jmeter.modifiers.CounterConfig;
|
import org.apache.jmeter.modifiers.CounterConfig;
|
||||||
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
|
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
|
||||||
import org.apache.jmeter.save.SaveService;
|
import org.apache.jmeter.save.SaveService;
|
||||||
|
import org.apache.jmeter.testelement.AbstractTestElement;
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
|
@ -181,16 +183,6 @@ public class ElementUtil {
|
||||||
return getFullPath(element.getParent(), path);
|
return getFullPath(element.getParent(), path);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void getScenarioSet(MsTestElement element, List<String> id_names) {
|
|
||||||
if (StringUtils.equals(element.getType(), "scenario")) {
|
|
||||||
id_names.add(element.getResourceId() + "_" + element.getName());
|
|
||||||
}
|
|
||||||
if (element.getParent() == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getScenarioSet(element.getParent(), id_names);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getParentName(MsTestElement parent) {
|
public static String getParentName(MsTestElement parent) {
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
// 获取全路径以备后面使用
|
// 获取全路径以备后面使用
|
||||||
|
@ -581,4 +573,10 @@ public class ElementUtil {
|
||||||
}
|
}
|
||||||
return resourceId + "_" + ElementUtil.getFullIndexPath(parent, indexPath);
|
return resourceId + "_" + ElementUtil.getFullIndexPath(parent, indexPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setBaseParams(AbstractTestElement sampler, MsTestElement parent, ParameterConfig config, String id, String indexPath) {
|
||||||
|
sampler.setProperty("MS-ID", id);
|
||||||
|
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(id, config, parent, indexPath));
|
||||||
|
LoggerUtil.debug("mqtt sampler resourceId :" + sampler.getPropertyAsString("MS-RESOURCE-ID"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,30 @@
|
||||||
package io.metersphere.api.dto.definition.request;
|
package io.metersphere.api.dto.definition.request;
|
||||||
|
|
||||||
|
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||||
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
import io.metersphere.api.dto.definition.request.variable.ScenarioVariable;
|
||||||
|
import io.metersphere.api.dto.scenario.HttpConfig;
|
||||||
|
import io.metersphere.api.dto.scenario.HttpConfigCondition;
|
||||||
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.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.api.dto.ssl.MsKeyStore;
|
import io.metersphere.api.dto.ssl.MsKeyStore;
|
||||||
|
import io.metersphere.api.service.ApiDefinitionService;
|
||||||
|
import io.metersphere.api.service.ApiTestCaseService;
|
||||||
|
import io.metersphere.base.domain.ApiDefinition;
|
||||||
|
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||||
|
import io.metersphere.base.domain.TestPlanApiCase;
|
||||||
|
import io.metersphere.commons.constants.ConditionType;
|
||||||
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
|
import io.metersphere.constants.RunModeConstants;
|
||||||
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
|
import io.metersphere.track.service.TestPlanApiCaseService;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
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 java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
public class ParameterConfig extends MsParameter {
|
public class ParameterConfig extends MsParameter {
|
||||||
|
@ -74,4 +86,108 @@ public class ParameterConfig extends MsParameter {
|
||||||
return arguments;
|
return arguments;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public HttpConfig matchConfig(MsHTTPSamplerProxy samplerProxy) {
|
||||||
|
HttpConfig httpConfig = this.getConfig().get(samplerProxy.getProjectId()).getHttpConfig();
|
||||||
|
boolean isNext = true;
|
||||||
|
if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) {
|
||||||
|
for (HttpConfigCondition item : httpConfig.getConditions()) {
|
||||||
|
if (item.getType().equals(ConditionType.PATH.name())) {
|
||||||
|
HttpConfig config = httpConfig.getPathCondition(samplerProxy.getPath(), item);
|
||||||
|
if (config != null) {
|
||||||
|
isNext = false;
|
||||||
|
httpConfig = config;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
} else if (item.getType().equals(ConditionType.MODULE.name())) {
|
||||||
|
ApiDefinition apiDefinition = null;
|
||||||
|
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||||
|
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||||
|
if (StringUtils.isNotEmpty(samplerProxy.getRefType()) && samplerProxy.getRefType().equals("CASE")) {
|
||||||
|
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(samplerProxy.getId());
|
||||||
|
if (caseWithBLOBs != null) {
|
||||||
|
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
apiDefinition = apiDefinitionService.get(samplerProxy.getId());
|
||||||
|
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.get(samplerProxy.getId());
|
||||||
|
if (apiTestCaseWithBLOBs == null) {
|
||||||
|
apiTestCaseWithBLOBs = apiTestCaseService.get(samplerProxy.getName());
|
||||||
|
}
|
||||||
|
if (apiTestCaseWithBLOBs != null) {
|
||||||
|
apiDefinition = apiDefinitionService.get(apiTestCaseWithBLOBs.getApiDefinitionId());
|
||||||
|
} else {
|
||||||
|
TestPlanApiCaseService testPlanApiCaseService = CommonBeanFactory.getBean(TestPlanApiCaseService.class);
|
||||||
|
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(samplerProxy.getId());
|
||||||
|
if (testPlanApiCase != null) {
|
||||||
|
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(testPlanApiCase.getApiCaseId());
|
||||||
|
if (caseWithBLOBs != null) {
|
||||||
|
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (apiDefinition != null) {
|
||||||
|
HttpConfig config = httpConfig.getModuleCondition(apiDefinition.getModuleId(), item);
|
||||||
|
if (config != null) {
|
||||||
|
isNext = false;
|
||||||
|
httpConfig = config;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (isNext) {
|
||||||
|
for (HttpConfigCondition item : httpConfig.getConditions()) {
|
||||||
|
if (item.getType().equals(ConditionType.NONE.name())) {
|
||||||
|
httpConfig = httpConfig.initHttpConfig(item);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return httpConfig;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getParentProjectId(MsHTTPSamplerProxy samplerProxy) {
|
||||||
|
MsTestElement parent = samplerProxy.getParent();
|
||||||
|
while (parent != null) {
|
||||||
|
if (StringUtils.isNotBlank(parent.getProjectId())) {
|
||||||
|
return parent.getProjectId();
|
||||||
|
}
|
||||||
|
parent = parent.getParent();
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
public void compatible(MsHTTPSamplerProxy samplerProxy) {
|
||||||
|
if (samplerProxy.isCustomizeReq() && samplerProxy.getIsRefEnvironment() == null) {
|
||||||
|
if (StringUtils.isNotBlank(samplerProxy.getUrl())) {
|
||||||
|
samplerProxy.setIsRefEnvironment(false);
|
||||||
|
} else {
|
||||||
|
samplerProxy.setIsRefEnvironment(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// 数据兼容处理
|
||||||
|
if (this.getConfig() != null && StringUtils.isNotEmpty(samplerProxy.getProjectId()) && this.getConfig().containsKey(samplerProxy.getProjectId())) {
|
||||||
|
// 1.8 之后 当前正常数据
|
||||||
|
} else if (this.getConfig() != null && this.getConfig().containsKey(getParentProjectId(samplerProxy))) {
|
||||||
|
// 1.8 前后 混合数据
|
||||||
|
samplerProxy.setProjectId(getParentProjectId(samplerProxy));
|
||||||
|
} else {
|
||||||
|
// 1.8 之前 数据
|
||||||
|
if (this.getConfig() != null) {
|
||||||
|
if (!this.getConfig().containsKey(RunModeConstants.HIS_PRO_ID.toString())) {
|
||||||
|
// 测试计划执行
|
||||||
|
Iterator<String> it = this.getConfig().keySet().iterator();
|
||||||
|
if (it.hasNext()) {
|
||||||
|
samplerProxy.setProjectId(it.next());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
samplerProxy.setProjectId(RunModeConstants.HIS_PRO_ID.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
package io.metersphere.api.dto.definition.request.processors;
|
package io.metersphere.api.dto.definition.request.processors;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSON;
|
|
||||||
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.RunningParamKeys;
|
import io.metersphere.api.dto.RunningParamKeys;
|
||||||
|
@ -20,7 +19,6 @@ import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@Data
|
@Data
|
||||||
|
@ -78,13 +76,7 @@ public class MsJSR223Processor extends MsTestElement {
|
||||||
} else {
|
} else {
|
||||||
processor.setName("JSR223Processor");
|
processor.setName("JSR223Processor");
|
||||||
}
|
}
|
||||||
processor.setProperty("MS-ID", this.getId());
|
ElementUtil.setBaseParams(processor, this.getParent(), config, this.getId(), this.getIndex());
|
||||||
String indexPath = this.getIndex();
|
|
||||||
processor.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getResourceId(), config, this.getParent(), indexPath));
|
|
||||||
List<String> id_names = new LinkedList<>();
|
|
||||||
ElementUtil.getScenarioSet(this, id_names);
|
|
||||||
processor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
|
|
||||||
|
|
||||||
processor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
|
processor.setProperty(TestElement.TEST_CLASS, JSR223Sampler.class.getName());
|
||||||
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
processor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
processor.setProperty("scriptLanguage", this.getScriptLanguage());
|
processor.setProperty("scriptLanguage", this.getScriptLanguage());
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -245,13 +244,8 @@ public class MsJDBCPostProcessor extends MsTestElement {
|
||||||
jdbcPostProcessor.setName(this.getName() == null? "JDBCPostProcessor" : this.getName());
|
jdbcPostProcessor.setName(this.getName() == null? "JDBCPostProcessor" : this.getName());
|
||||||
jdbcPostProcessor.setProperty(TestElement.TEST_CLASS, JDBCPostProcessor.class.getName());
|
jdbcPostProcessor.setProperty(TestElement.TEST_CLASS, JDBCPostProcessor.class.getName());
|
||||||
jdbcPostProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
jdbcPostProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
jdbcPostProcessor.setProperty("MS-ID", this.getId());
|
|
||||||
String indexPath = this.getIndex();
|
|
||||||
jdbcPostProcessor.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + ElementUtil.getFullIndexPath(this.getParent(), indexPath));
|
|
||||||
List<String> id_names = new LinkedList<>();
|
|
||||||
ElementUtil.getScenarioSet(this, id_names);
|
|
||||||
jdbcPostProcessor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
|
|
||||||
|
|
||||||
|
ElementUtil.setBaseParams(jdbcPostProcessor, this.getParent(), config, this.getId(), this.getIndex());
|
||||||
// request.getDataSource() 是ID,需要转换为Name
|
// request.getDataSource() 是ID,需要转换为Name
|
||||||
jdbcPostProcessor.setProperty("dataSource", this.dataSource.getName());
|
jdbcPostProcessor.setProperty("dataSource", this.dataSource.getName());
|
||||||
jdbcPostProcessor.setProperty("query", this.getQuery());
|
jdbcPostProcessor.setProperty("query", this.getQuery());
|
||||||
|
|
|
@ -37,7 +37,6 @@ import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -245,14 +244,9 @@ public class MsJDBCPreProcessor extends MsTestElement {
|
||||||
jdbcPreProcessor.setName(this.getName() == null? "JDBCPreProcessor" : this.getName());
|
jdbcPreProcessor.setName(this.getName() == null? "JDBCPreProcessor" : this.getName());
|
||||||
jdbcPreProcessor.setProperty(TestElement.TEST_CLASS, JDBCPreProcessor.class.getName());
|
jdbcPreProcessor.setProperty(TestElement.TEST_CLASS, JDBCPreProcessor.class.getName());
|
||||||
jdbcPreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
jdbcPreProcessor.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
jdbcPreProcessor.setProperty("MS-ID", this.getId());
|
|
||||||
String indexPath = this.getIndex();
|
|
||||||
jdbcPreProcessor.setProperty("MS-RESOURCE-ID", this.getResourceId() + "_" + ElementUtil.getFullIndexPath(this.getParent(), indexPath));
|
|
||||||
List<String> id_names = new LinkedList<>();
|
|
||||||
ElementUtil.getScenarioSet(this, id_names);
|
|
||||||
jdbcPreProcessor.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
|
|
||||||
|
|
||||||
// request.getDataSource() 是ID,需要转换为Name
|
ElementUtil.setBaseParams(jdbcPreProcessor, this.getParent(), config, this.getId(), this.getIndex());
|
||||||
|
|
||||||
jdbcPreProcessor.setProperty("dataSource", this.dataSource.getName());
|
jdbcPreProcessor.setProperty("dataSource", this.dataSource.getName());
|
||||||
jdbcPreProcessor.setProperty("query", this.getQuery());
|
jdbcPreProcessor.setProperty("query", this.getQuery());
|
||||||
jdbcPreProcessor.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
|
jdbcPreProcessor.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
|
||||||
|
|
|
@ -36,7 +36,6 @@ import org.apache.jmeter.save.SaveService;
|
||||||
import org.apache.jmeter.testelement.TestElement;
|
import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -166,12 +165,7 @@ public class MsDubboSampler extends MsTestElement {
|
||||||
sampler.setProperty(TestElement.TEST_CLASS, DubboSample.class.getName());
|
sampler.setProperty(TestElement.TEST_CLASS, DubboSample.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("DubboSampleGui"));
|
||||||
}
|
}
|
||||||
sampler.setProperty("MS-ID", this.getId());
|
ElementUtil.setBaseParams(sampler, this.getParent(), config, this.getId(), this.getIndex());
|
||||||
String indexPath = this.getIndex();
|
|
||||||
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
|
|
||||||
List<String> id_names = new LinkedList<>();
|
|
||||||
ElementUtil.getScenarioSet(this, id_names);
|
|
||||||
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
|
|
||||||
sampler.addTestElement(configCenter(this.getConfigCenter()));
|
sampler.addTestElement(configCenter(this.getConfigCenter()));
|
||||||
sampler.addTestElement(registryCenter(this.getRegistryCenter()));
|
sampler.addTestElement(registryCenter(this.getRegistryCenter()));
|
||||||
sampler.addTestElement(consumerAndService(this.getConsumerAndService()));
|
sampler.addTestElement(consumerAndService(this.getConsumerAndService()));
|
||||||
|
|
|
@ -13,38 +13,28 @@ import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
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.auth.MsAuthManager;
|
||||||
import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager;
|
import io.metersphere.api.dto.definition.request.dns.MsDNSCacheManager;
|
||||||
import io.metersphere.api.dto.definition.request.processors.post.MsJSR223PostProcessor;
|
|
||||||
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
|
||||||
import io.metersphere.api.dto.scenario.Body;
|
import io.metersphere.api.dto.scenario.Body;
|
||||||
import io.metersphere.api.dto.scenario.HttpConfig;
|
import io.metersphere.api.dto.scenario.HttpConfig;
|
||||||
import io.metersphere.api.dto.scenario.HttpConfigCondition;
|
|
||||||
import io.metersphere.api.dto.scenario.KeyValue;
|
import io.metersphere.api.dto.scenario.KeyValue;
|
||||||
import io.metersphere.api.dto.scenario.environment.CommonConfig;
|
import io.metersphere.api.dto.scenario.environment.CommonConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.api.dto.scenario.environment.GlobalScriptConfig;
|
|
||||||
import io.metersphere.api.dto.scenario.environment.GlobalScriptFilterRequest;
|
|
||||||
import io.metersphere.api.dto.ssl.KeyStoreConfig;
|
import io.metersphere.api.dto.ssl.KeyStoreConfig;
|
||||||
import io.metersphere.api.dto.ssl.KeyStoreFile;
|
import io.metersphere.api.dto.ssl.KeyStoreFile;
|
||||||
import io.metersphere.api.dto.ssl.MsKeyStore;
|
import io.metersphere.api.dto.ssl.MsKeyStore;
|
||||||
import io.metersphere.api.service.ApiDefinitionService;
|
import io.metersphere.api.service.ApiDefinitionService;
|
||||||
import io.metersphere.api.service.ApiTestCaseService;
|
import io.metersphere.api.service.ApiTestCaseService;
|
||||||
import io.metersphere.api.service.CommandService;
|
import io.metersphere.api.service.CommandService;
|
||||||
import io.metersphere.base.domain.ApiDefinition;
|
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||||
import io.metersphere.base.domain.TestPlanApiCase;
|
|
||||||
import io.metersphere.commons.constants.ConditionType;
|
|
||||||
import io.metersphere.commons.constants.MsTestElementConstants;
|
import io.metersphere.commons.constants.MsTestElementConstants;
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||||
import io.metersphere.commons.utils.FileUtils;
|
import io.metersphere.commons.utils.FileUtils;
|
||||||
import io.metersphere.commons.utils.HashTreeUtil;
|
import io.metersphere.commons.utils.HashTreeUtil;
|
||||||
import io.metersphere.commons.utils.LogUtil;
|
import io.metersphere.commons.utils.LogUtil;
|
||||||
import io.metersphere.constants.RunModeConstants;
|
|
||||||
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
import io.metersphere.jmeter.utils.ScriptEngineUtils;
|
||||||
import io.metersphere.plugin.core.MsParameter;
|
import io.metersphere.plugin.core.MsParameter;
|
||||||
import io.metersphere.plugin.core.MsTestElement;
|
import io.metersphere.plugin.core.MsTestElement;
|
||||||
import io.metersphere.track.service.TestPlanApiCaseService;
|
|
||||||
import io.metersphere.utils.LoggerUtil;
|
import io.metersphere.utils.LoggerUtil;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import lombok.EqualsAndHashCode;
|
import lombok.EqualsAndHashCode;
|
||||||
|
@ -64,7 +54,10 @@ import org.apache.jorphan.collections.HashTree;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.net.URLDecoder;
|
import java.net.URLDecoder;
|
||||||
import java.net.URLEncoder;
|
import java.net.URLEncoder;
|
||||||
import java.util.*;
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.UUID;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
@ -134,52 +127,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
@JSONField(ordinal = 39)
|
@JSONField(ordinal = 39)
|
||||||
private boolean customizeReq;
|
private boolean customizeReq;
|
||||||
|
|
||||||
private boolean setRefElement() {
|
|
||||||
try {
|
|
||||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
|
||||||
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
|
||||||
MsHTTPSamplerProxy proxy = null;
|
|
||||||
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());
|
|
||||||
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
|
||||||
ElementUtil.dataFormatting(element);
|
|
||||||
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsHTTPSamplerProxy>() {
|
|
||||||
});
|
|
||||||
this.setName(bloBs.getName());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
|
||||||
if (apiDefinition != null) {
|
|
||||||
this.setName(apiDefinition.getName());
|
|
||||||
this.setProjectId(apiDefinition.getProjectId());
|
|
||||||
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsHTTPSamplerProxy>() {
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (proxy != null) {
|
|
||||||
if (StringUtils.equals(this.getRefType(), "CASE")) {
|
|
||||||
ElementUtil.mergeHashTree(this, proxy.getHashTree());
|
|
||||||
} else {
|
|
||||||
this.setHashTree(proxy.getHashTree());
|
|
||||||
}
|
|
||||||
this.setPath(proxy.getPath());
|
|
||||||
this.setMethod(proxy.getMethod());
|
|
||||||
this.setBody(proxy.getBody());
|
|
||||||
this.setRest(proxy.getRest());
|
|
||||||
this.setArguments(proxy.getArguments());
|
|
||||||
this.setHeaders(proxy.getHeaders());
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
} catch (Exception ex) {
|
|
||||||
LogUtil.error(ex);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
public void toHashTree(HashTree tree, List<MsTestElement> hashTree, MsParameter msParameter) {
|
||||||
ParameterConfig config = (ParameterConfig) msParameter;
|
ParameterConfig config = (ParameterConfig) msParameter;
|
||||||
|
@ -213,13 +160,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
}
|
}
|
||||||
sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
|
sampler.setProperty(TestElement.TEST_CLASS, HTTPSamplerProxy.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("HttpTestSampleGui"));
|
||||||
sampler.setProperty("MS-ID", this.getId());
|
ElementUtil.setBaseParams(sampler, this.getParent(), config, this.getId(), this.getIndex());
|
||||||
String indexPath = this.getIndex();
|
|
||||||
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
|
|
||||||
List<String> id_names = new LinkedList<>();
|
|
||||||
ElementUtil.getScenarioSet(this, id_names);
|
|
||||||
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
|
|
||||||
|
|
||||||
sampler.setMethod(this.getMethod());
|
sampler.setMethod(this.getMethod());
|
||||||
sampler.setContentEncoding("UTF-8");
|
sampler.setContentEncoding("UTF-8");
|
||||||
sampler.setFollowRedirects(this.isFollowRedirects());
|
sampler.setFollowRedirects(this.isFollowRedirects());
|
||||||
|
@ -231,7 +172,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
config.setConfig(ElementUtil.getEnvironmentConfig(this.useEnvironment, this.getProjectId(), this.isMockEnvironment()));
|
config.setConfig(ElementUtil.getEnvironmentConfig(this.useEnvironment, this.getProjectId(), this.isMockEnvironment()));
|
||||||
}
|
}
|
||||||
|
|
||||||
compatible(config);
|
config.compatible(this);
|
||||||
|
|
||||||
this.initConnectAndResponseTimeout(config);
|
this.initConnectAndResponseTimeout(config);
|
||||||
sampler.setConnectTimeout(this.getConnectTimeout() == null ? "60000" : this.getConnectTimeout());
|
sampler.setConnectTimeout(this.getConnectTimeout() == null ? "60000" : this.getConnectTimeout());
|
||||||
|
@ -239,7 +180,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
|
|
||||||
HttpConfig httpConfig = getHttpConfig(config);
|
HttpConfig httpConfig = getHttpConfig(config);
|
||||||
|
|
||||||
|
|
||||||
setSamplerPath(config, httpConfig, sampler);
|
setSamplerPath(config, httpConfig, sampler);
|
||||||
|
|
||||||
// 请求体处理
|
// 请求体处理
|
||||||
|
@ -291,14 +231,10 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
|
|
||||||
addCertificate(config, httpSamplerTree);
|
addCertificate(config, httpSamplerTree);
|
||||||
|
|
||||||
|
if (httpConfig != null) {
|
||||||
//根据配置增加全局前后至脚本
|
//根据配置增加全局前后至脚本
|
||||||
if (httpConfig != null) {
|
JMeterScriptUtil.setHttpScript(httpConfig, httpSamplerTree, config, useEnvironment, this.getEnvironmentId());
|
||||||
this.setScript(httpConfig, httpSamplerTree, config, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
HashTreeUtil hashTreeUtil = new HashTreeUtil();
|
|
||||||
//增加误报、断言
|
//增加误报、断言
|
||||||
if (httpConfig != null) {
|
|
||||||
if (CollectionUtils.isNotEmpty(httpConfig.getErrorReportAssertions())) {
|
if (CollectionUtils.isNotEmpty(httpConfig.getErrorReportAssertions())) {
|
||||||
for (MsAssertions assertion : httpConfig.getErrorReportAssertions()) {
|
for (MsAssertions assertion : httpConfig.getErrorReportAssertions()) {
|
||||||
assertion.toHashTree(httpSamplerTree, assertion.getHashTree(), config);
|
assertion.toHashTree(httpSamplerTree, assertion.getHashTree(), config);
|
||||||
|
@ -319,56 +255,60 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
el.setEnvironmentId(this.getEnvironmentId());
|
el.setEnvironmentId(this.getEnvironmentId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (el instanceof MsAssertions) {
|
|
||||||
//断言设置需要和全局断言、误报进行去重
|
|
||||||
el = hashTreeUtil.duplicateRegexInAssertions(httpConfig.getAssertions(), (MsAssertions) el);
|
|
||||||
}
|
|
||||||
el.toHashTree(httpSamplerTree, el.getHashTree(), config);
|
el.toHashTree(httpSamplerTree, el.getHashTree(), config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//根据配置增加全局前后至脚本
|
//根据配置增加全局前后至脚本
|
||||||
if (httpConfig != null) {
|
if (httpConfig != null) {
|
||||||
this.setScript(httpConfig, httpSamplerTree, config, true);
|
JMeterScriptUtil.setHttpScript(httpConfig, httpSamplerTree, config, useEnvironment, this.getEnvironmentId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setScript(HttpConfig httpConfig, HashTree httpSamplerTree, ParameterConfig config, boolean isAfterPrivateScript) {
|
private boolean setRefElement() {
|
||||||
MsJSR223PreProcessor preProcessor = httpConfig.getPreProcessor();
|
try {
|
||||||
MsJSR223PostProcessor postProcessor = httpConfig.getPostProcessor();
|
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
||||||
GlobalScriptConfig globalScriptConfig = httpConfig.getGlobalScriptConfig();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
List<String> filterPreProtocal = globalScriptConfig == null ? null : globalScriptConfig.getFilterRequestPreScript();
|
mapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||||
List<String> filterPostProtocal = globalScriptConfig == null ? null : globalScriptConfig.getFilterRequestPostScript();
|
MsHTTPSamplerProxy proxy = null;
|
||||||
|
if (StringUtils.equals(this.getRefType(), "CASE")) {
|
||||||
boolean filterPre = JMeterScriptUtil.isScriptFilter(filterPreProtocal, GlobalScriptFilterRequest.HTTP.name());
|
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
||||||
boolean filterPost = JMeterScriptUtil.isScriptFilter(filterPostProtocal, GlobalScriptFilterRequest.HTTP.name());
|
ApiTestCaseWithBLOBs bloBs = apiTestCaseService.get(this.getId());
|
||||||
boolean isPreScriptExecAfterPrivateScript = globalScriptConfig == null ? false : globalScriptConfig.isPreScriptExecAfterPrivateScript();
|
if (bloBs != null) {
|
||||||
boolean isPostScriptExecAfterPrivateScript = globalScriptConfig == null ? false : globalScriptConfig.isPostScriptExecAfterPrivateScript();
|
this.setProjectId(bloBs.getProjectId());
|
||||||
|
JSONObject element = JSON.parseObject(bloBs.getRequest());
|
||||||
if (!filterPre && preProcessor != null && StringUtils.isNotEmpty(preProcessor.getScript())) {
|
ElementUtil.dataFormatting(element);
|
||||||
if ((isPreScriptExecAfterPrivateScript && isAfterPrivateScript) || (!isPreScriptExecAfterPrivateScript && !isAfterPrivateScript)) {
|
proxy = mapper.readValue(element.toJSONString(), new TypeReference<MsHTTPSamplerProxy>() {
|
||||||
if (preProcessor.getEnvironmentId() == null) {
|
});
|
||||||
if (this.getEnvironmentId() == null) {
|
this.setName(bloBs.getName());
|
||||||
preProcessor.setEnvironmentId(useEnvironment);
|
}
|
||||||
} else {
|
} else {
|
||||||
preProcessor.setEnvironmentId(this.getEnvironmentId());
|
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionService.getBLOBs(this.getId());
|
||||||
|
if (apiDefinition != null) {
|
||||||
|
this.setName(apiDefinition.getName());
|
||||||
|
this.setProjectId(apiDefinition.getProjectId());
|
||||||
|
proxy = mapper.readValue(apiDefinition.getRequest(), new TypeReference<MsHTTPSamplerProxy>() {
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
preProcessor.toHashTree(httpSamplerTree, preProcessor.getHashTree(), config);
|
if (proxy != null) {
|
||||||
}
|
if (StringUtils.equals(this.getRefType(), "CASE")) {
|
||||||
}
|
ElementUtil.mergeHashTree(this, proxy.getHashTree());
|
||||||
if (!filterPost && postProcessor != null && StringUtils.isNotEmpty(postProcessor.getScript())) {
|
|
||||||
if ((isPostScriptExecAfterPrivateScript && isAfterPrivateScript) || (!isPostScriptExecAfterPrivateScript && !isAfterPrivateScript)) {
|
|
||||||
if (postProcessor.getEnvironmentId() == null) {
|
|
||||||
if (this.getEnvironmentId() == null) {
|
|
||||||
postProcessor.setEnvironmentId(useEnvironment);
|
|
||||||
} else {
|
} else {
|
||||||
postProcessor.setEnvironmentId(this.getEnvironmentId());
|
this.setHashTree(proxy.getHashTree());
|
||||||
}
|
}
|
||||||
|
this.setPath(proxy.getPath());
|
||||||
|
this.setMethod(proxy.getMethod());
|
||||||
|
this.setBody(proxy.getBody());
|
||||||
|
this.setRest(proxy.getRest());
|
||||||
|
this.setArguments(proxy.getArguments());
|
||||||
|
this.setHeaders(proxy.getHeaders());
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
postProcessor.toHashTree(httpSamplerTree, postProcessor.getHashTree(), config);
|
} catch (Exception ex) {
|
||||||
}
|
LogUtil.error(ex);
|
||||||
}
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void initConnectAndResponseTimeout(ParameterConfig config) {
|
private void initConnectAndResponseTimeout(ParameterConfig config) {
|
||||||
|
@ -416,7 +356,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) {
|
if (StringUtils.isNotEmpty(useEvnId) && !StringUtils.equals(useEvnId, this.getEnvironmentId())) {
|
||||||
this.setEnvironmentId(useEvnId);
|
this.setEnvironmentId(useEvnId);
|
||||||
}
|
}
|
||||||
HttpConfig httpConfig = matchConfig(config);
|
HttpConfig httpConfig = config.matchConfig(this);
|
||||||
httpConfig.setPreProcessor(environmentConfig.getPreProcessor());
|
httpConfig.setPreProcessor(environmentConfig.getPreProcessor());
|
||||||
httpConfig.setPostProcessor(environmentConfig.getPostProcessor());
|
httpConfig.setPostProcessor(environmentConfig.getPostProcessor());
|
||||||
httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig());
|
httpConfig.setGlobalScriptConfig(environmentConfig.getGlobalScriptConfig());
|
||||||
|
@ -630,38 +570,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// 兼容旧数据
|
|
||||||
private void compatible(ParameterConfig config) {
|
|
||||||
if (this.isCustomizeReq() && this.isRefEnvironment == null) {
|
|
||||||
if (StringUtils.isNotBlank(this.url)) {
|
|
||||||
this.isRefEnvironment = false;
|
|
||||||
} else {
|
|
||||||
this.isRefEnvironment = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// 数据兼容处理
|
|
||||||
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())) {
|
|
||||||
// 测试计划执行
|
|
||||||
Iterator<String> it = config.getConfig().keySet().iterator();
|
|
||||||
if (it.hasNext()) {
|
|
||||||
this.setProjectId(it.next());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
this.setProjectId(RunModeConstants.HIS_PRO_ID.toString());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isUrl() {
|
private boolean isUrl() {
|
||||||
// 自定义字段没有引用环境则非url
|
// 自定义字段没有引用环境则非url
|
||||||
if (this.isCustomizeReq()) {
|
if (this.isCustomizeReq()) {
|
||||||
|
@ -688,17 +596,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
return false;
|
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 String getRestParameters(String path) {
|
private String getRestParameters(String path) {
|
||||||
StringBuffer stringBuffer = new StringBuffer();
|
StringBuffer stringBuffer = new StringBuffer();
|
||||||
stringBuffer.append(path);
|
stringBuffer.append(path);
|
||||||
|
@ -820,74 +717,6 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 按照环境规则匹配环境
|
|
||||||
*
|
|
||||||
* @param parameterConfig
|
|
||||||
* @return
|
|
||||||
*/
|
|
||||||
private HttpConfig matchConfig(ParameterConfig parameterConfig) {
|
|
||||||
HttpConfig httpConfig = parameterConfig.getConfig().get(this.getProjectId()).getHttpConfig();
|
|
||||||
boolean isNext = true;
|
|
||||||
if (CollectionUtils.isNotEmpty(httpConfig.getConditions())) {
|
|
||||||
for (HttpConfigCondition item : httpConfig.getConditions()) {
|
|
||||||
if (item.getType().equals(ConditionType.PATH.name())) {
|
|
||||||
HttpConfig config = httpConfig.getPathCondition(this.getPath(), item);
|
|
||||||
if (config != null) {
|
|
||||||
isNext = false;
|
|
||||||
httpConfig = config;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} else if (item.getType().equals(ConditionType.MODULE.name())) {
|
|
||||||
ApiDefinition apiDefinition = null;
|
|
||||||
ApiDefinitionService apiDefinitionService = CommonBeanFactory.getBean(ApiDefinitionService.class);
|
|
||||||
ApiTestCaseService apiTestCaseService = CommonBeanFactory.getBean(ApiTestCaseService.class);
|
|
||||||
if (StringUtils.isNotEmpty(this.getRefType()) && this.getRefType().equals("CASE")) {
|
|
||||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(this.getId());
|
|
||||||
if (caseWithBLOBs != null) {
|
|
||||||
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
apiDefinition = apiDefinitionService.get(this.getId());
|
|
||||||
ApiTestCaseWithBLOBs apiTestCaseWithBLOBs = apiTestCaseService.get(this.getId());
|
|
||||||
if (apiTestCaseWithBLOBs == null) {
|
|
||||||
apiTestCaseWithBLOBs = apiTestCaseService.get(this.getName());
|
|
||||||
}
|
|
||||||
if (apiTestCaseWithBLOBs != null) {
|
|
||||||
apiDefinition = apiDefinitionService.get(apiTestCaseWithBLOBs.getApiDefinitionId());
|
|
||||||
} else {
|
|
||||||
TestPlanApiCaseService testPlanApiCaseService = CommonBeanFactory.getBean(TestPlanApiCaseService.class);
|
|
||||||
TestPlanApiCase testPlanApiCase = testPlanApiCaseService.getById(this.getId());
|
|
||||||
if (testPlanApiCase != null) {
|
|
||||||
ApiTestCaseWithBLOBs caseWithBLOBs = apiTestCaseService.get(testPlanApiCase.getApiCaseId());
|
|
||||||
if (caseWithBLOBs != null) {
|
|
||||||
apiDefinition = apiDefinitionService.get(caseWithBLOBs.getApiDefinitionId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (apiDefinition != null) {
|
|
||||||
HttpConfig config = httpConfig.getModuleCondition(apiDefinition.getModuleId(), item);
|
|
||||||
if (config != null) {
|
|
||||||
isNext = false;
|
|
||||||
httpConfig = config;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (isNext) {
|
|
||||||
for (HttpConfigCondition item : httpConfig.getConditions()) {
|
|
||||||
if (item.getType().equals(ConditionType.NONE.name())) {
|
|
||||||
httpConfig = httpConfig.initHttpConfig(item);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return httpConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 环境通用变量,这里只适用用接口定义和用例,场景自动化会加到场景中
|
* 环境通用变量,这里只适用用接口定义和用例,场景自动化会加到场景中
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -42,7 +42,6 @@ import org.apache.jmeter.testelement.TestElement;
|
||||||
import org.apache.jorphan.collections.HashTree;
|
import org.apache.jorphan.collections.HashTree;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@ -162,19 +161,7 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
//增加误报、全局断言
|
//增加误报、全局断言
|
||||||
if (envConfig != null) {
|
HashTreeUtil.addPositive(envConfig, samplerHashTree, config, this.getProjectId());
|
||||||
if (envConfig.isUseErrorCode()) {
|
|
||||||
List<MsAssertions> errorReportAssertion = HashTreeUtil.getErrorReportByProjectId(this.getProjectId());
|
|
||||||
for (MsAssertions assertion : errorReportAssertion) {
|
|
||||||
assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(envConfig.getAssertions())) {
|
|
||||||
for (MsAssertions assertion : envConfig.getAssertions()) {
|
|
||||||
assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//处理全局前后置脚本(步骤内)
|
//处理全局前后置脚本(步骤内)
|
||||||
String environmentId = this.getEnvironmentId();
|
String environmentId = this.getEnvironmentId();
|
||||||
|
@ -184,15 +171,8 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
//根据配置将脚本放置在私有脚本之前
|
//根据配置将脚本放置在私有脚本之前
|
||||||
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), environmentId, config, false);
|
JMeterScriptUtil.setScript(envConfig, samplerHashTree, GlobalScriptFilterRequest.JDBC.name(), environmentId, config, false);
|
||||||
|
|
||||||
HashTreeUtil hashTreeUtil = new HashTreeUtil();
|
|
||||||
|
|
||||||
if (CollectionUtils.isNotEmpty(hashTree)) {
|
if (CollectionUtils.isNotEmpty(hashTree)) {
|
||||||
EnvironmentConfig finalEnvConfig = envConfig;
|
|
||||||
hashTree.forEach(el -> {
|
hashTree.forEach(el -> {
|
||||||
if (el instanceof MsAssertions) {
|
|
||||||
//断言设置需要和全局断言、误报进行去重
|
|
||||||
el = hashTreeUtil.duplicateRegexInAssertions(finalEnvConfig.getAssertions(), (MsAssertions) el);
|
|
||||||
}
|
|
||||||
el.toHashTree(samplerHashTree, el.getHashTree(), config);
|
el.toHashTree(samplerHashTree, el.getHashTree(), config);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -337,14 +317,7 @@ public class MsJDBCSampler extends MsTestElement {
|
||||||
}
|
}
|
||||||
sampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName());
|
sampler.setProperty(TestElement.TEST_CLASS, JDBCSampler.class.getName());
|
||||||
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
sampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TestBeanGUI"));
|
||||||
sampler.setProperty("MS-ID", this.getId());
|
ElementUtil.setBaseParams(sampler, this.getParent(), config, this.getId(), this.getIndex());
|
||||||
String indexPath = this.getIndex();
|
|
||||||
sampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
|
|
||||||
List<String> id_names = new LinkedList<>();
|
|
||||||
ElementUtil.getScenarioSet(this, id_names);
|
|
||||||
sampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
|
|
||||||
|
|
||||||
// request.getDataSource() 是ID,需要转换为Name
|
|
||||||
sampler.setProperty("dataSource", this.dataSource.getName());
|
sampler.setProperty("dataSource", this.dataSource.getName());
|
||||||
sampler.setProperty("query", this.getQuery());
|
sampler.setProperty("query", this.getQuery());
|
||||||
sampler.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
|
sampler.setProperty("queryTimeout", String.valueOf(this.getQueryTimeout()));
|
||||||
|
|
|
@ -46,7 +46,6 @@ import org.apache.jorphan.collections.ListedHashTree;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.LinkedList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
|
@ -157,19 +156,7 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
}
|
}
|
||||||
|
|
||||||
//增加误报、全局断言
|
//增加误报、全局断言
|
||||||
if (envConfig != null) {
|
HashTreeUtil.addPositive(envConfig, samplerHashTree, config, this.getProjectId());
|
||||||
if (envConfig.isUseErrorCode()) {
|
|
||||||
List<MsAssertions> errorReportAssertion = HashTreeUtil.getErrorReportByProjectId(this.getProjectId());
|
|
||||||
for (MsAssertions assertion : errorReportAssertion) {
|
|
||||||
assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (CollectionUtils.isNotEmpty(envConfig.getAssertions())) {
|
|
||||||
for (MsAssertions assertion : envConfig.getAssertions()) {
|
|
||||||
assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//处理全局前后置脚本(步骤内)
|
//处理全局前后置脚本(步骤内)
|
||||||
String environmentId = this.getEnvironmentId();
|
String environmentId = this.getEnvironmentId();
|
||||||
|
@ -266,13 +253,7 @@ public class MsTCPSampler extends MsTestElement {
|
||||||
tcpSampler.setName(testName);
|
tcpSampler.setName(testName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tcpSampler.setProperty("MS-ID", this.getId());
|
ElementUtil.setBaseParams(tcpSampler, this.getParent(), config, this.getId(), this.getIndex());
|
||||||
String indexPath = this.getIndex();
|
|
||||||
tcpSampler.setProperty("MS-RESOURCE-ID", ElementUtil.getResourceId(this.getId(), config, this.getParent(), indexPath));
|
|
||||||
List<String> id_names = new LinkedList<>();
|
|
||||||
ElementUtil.getScenarioSet(this, id_names);
|
|
||||||
tcpSampler.setProperty("MS-SCENARIO", JSON.toJSONString(id_names));
|
|
||||||
|
|
||||||
tcpSampler.setProperty(TestElement.TEST_CLASS, TCPSampler.class.getName());
|
tcpSampler.setProperty(TestElement.TEST_CLASS, TCPSampler.class.getName());
|
||||||
tcpSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TCPSamplerGui"));
|
tcpSampler.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass("TCPSamplerGui"));
|
||||||
tcpSampler.setClassname(this.getClassname());
|
tcpSampler.setClassname(this.getClassname());
|
||||||
|
|
|
@ -4,11 +4,8 @@ import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
||||||
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.MsJSR223PreProcessor;
|
import io.metersphere.api.dto.definition.request.processors.pre.MsJSR223PreProcessor;
|
||||||
import io.metersphere.api.dto.scenario.environment.GlobalScriptConfig;
|
import io.metersphere.api.dto.scenario.environment.GlobalScriptConfig;
|
||||||
import io.metersphere.base.domain.ApiModule;
|
|
||||||
import io.metersphere.base.domain.ApiModuleExample;
|
|
||||||
import io.metersphere.base.mapper.ApiModuleMapper;
|
import io.metersphere.base.mapper.ApiModuleMapper;
|
||||||
import io.metersphere.commons.utils.BeanUtils;
|
import io.metersphere.commons.utils.BeanUtils;
|
||||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
import org.apache.commons.collections.CollectionUtils;
|
import org.apache.commons.collections.CollectionUtils;
|
||||||
import org.apache.commons.lang3.StringUtils;
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
@ -53,39 +50,6 @@ public class HttpConfig {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getAllChild(String moduleId, List<String> allChild) {
|
|
||||||
// 找出所有子模块
|
|
||||||
if (apiModuleMapper == null) {
|
|
||||||
apiModuleMapper = CommonBeanFactory.getBean(ApiModuleMapper.class);
|
|
||||||
}
|
|
||||||
allChild.add(moduleId);
|
|
||||||
ApiModuleExample example = new ApiModuleExample();
|
|
||||||
example.createCriteria().andParentIdEqualTo(moduleId);
|
|
||||||
List<ApiModule> modules = apiModuleMapper.selectByExample(example);
|
|
||||||
for (ApiModule module : modules) {
|
|
||||||
getAllChild(module.getId(), allChild);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) {
|
|
||||||
// List<String> moduleIds = new ArrayList<>();
|
|
||||||
// if (CollectionUtils.isNotEmpty(configCondition.getDetails())) {
|
|
||||||
// if (CollectionUtils.isEmpty(configCondition.getModuleIds())) {
|
|
||||||
// for (KeyValue keyValue : configCondition.getDetails()) {
|
|
||||||
// getAllChild(keyValue.getValue(), moduleIds);
|
|
||||||
// }
|
|
||||||
// configCondition.setModuleIds(moduleIds);
|
|
||||||
// } else {
|
|
||||||
// moduleIds = configCondition.getModuleIds();
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// if (moduleIds.contains(moduleId)) {
|
|
||||||
// return initHttpConfig(configCondition);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
|
|
||||||
public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) {
|
public HttpConfig getModuleCondition(String moduleId, HttpConfigCondition configCondition) {
|
||||||
if (CollectionUtils.isNotEmpty(configCondition.getDetails())) {
|
if (CollectionUtils.isNotEmpty(configCondition.getDetails())) {
|
||||||
List<KeyValue> details = configCondition.getDetails().stream().filter(detail -> StringUtils.contains(detail.getValue(), moduleId)).collect(Collectors.toList());
|
List<KeyValue> details = configCondition.getDetails().stream().filter(detail -> StringUtils.contains(detail.getValue(), moduleId)).collect(Collectors.toList());
|
||||||
|
|
|
@ -3,8 +3,10 @@ package io.metersphere.commons.utils;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import io.metersphere.api.dto.RunningParamKeys;
|
import io.metersphere.api.dto.RunningParamKeys;
|
||||||
|
import io.metersphere.api.dto.definition.request.ParameterConfig;
|
||||||
import io.metersphere.api.dto.definition.request.assertions.MsAssertionRegex;
|
import io.metersphere.api.dto.definition.request.assertions.MsAssertionRegex;
|
||||||
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
import io.metersphere.api.dto.definition.request.assertions.MsAssertions;
|
||||||
|
import io.metersphere.api.dto.scenario.environment.EnvironmentConfig;
|
||||||
import io.metersphere.api.service.ApiTestEnvironmentService;
|
import io.metersphere.api.service.ApiTestEnvironmentService;
|
||||||
import io.metersphere.api.service.ExtErrorReportLibraryService;
|
import io.metersphere.api.service.ExtErrorReportLibraryService;
|
||||||
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
import io.metersphere.base.domain.ApiTestEnvironmentWithBLOBs;
|
||||||
|
@ -237,4 +239,21 @@ public class HashTreeUtil {
|
||||||
ExtErrorReportLibraryService service = CommonBeanFactory.getBean(ExtErrorReportLibraryService.class);
|
ExtErrorReportLibraryService service = CommonBeanFactory.getBean(ExtErrorReportLibraryService.class);
|
||||||
return service.getAssertionByProjectIdAndStatusIsOpen(projectId);
|
return service.getAssertionByProjectIdAndStatusIsOpen(projectId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void addPositive(EnvironmentConfig envConfig, HashTree samplerHashTree, ParameterConfig config, String projectId) {
|
||||||
|
if (envConfig != null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (envConfig.isUseErrorCode()) {
|
||||||
|
List<MsAssertions> errorReportAssertion = HashTreeUtil.getErrorReportByProjectId(projectId);
|
||||||
|
for (MsAssertions assertion : errorReportAssertion) {
|
||||||
|
assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (CollectionUtils.isNotEmpty(envConfig.getAssertions())) {
|
||||||
|
for (MsAssertions assertion : envConfig.getAssertions()) {
|
||||||
|
assertion.toHashTree(samplerHashTree, assertion.getHashTree(), config);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue