feat(接口自动化): 导入jmx对已经有的请求处理
This commit is contained in:
parent
726044ee61
commit
e7df89b1e2
|
@ -1,7 +1,6 @@
|
|||
package io.metersphere.api.dto.automation.parse;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
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;
|
||||
|
@ -38,6 +37,7 @@ import io.metersphere.base.domain.ApiScenarioWithBLOBs;
|
|||
import io.metersphere.commons.constants.LoopConstants;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.jmeter.assertions.*;
|
||||
import org.apache.jmeter.config.ConfigTestElement;
|
||||
import org.apache.jmeter.control.ForeachController;
|
||||
|
@ -55,6 +55,7 @@ import org.apache.jmeter.protocol.java.sampler.JSR223Sampler;
|
|||
import org.apache.jmeter.protocol.jdbc.sampler.JDBCSampler;
|
||||
import org.apache.jmeter.protocol.tcp.sampler.TCPSampler;
|
||||
import org.apache.jmeter.save.SaveService;
|
||||
import org.apache.jmeter.testelement.TestElement;
|
||||
import org.apache.jmeter.testelement.TestPlan;
|
||||
import org.apache.jmeter.timers.ConstantTimer;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
|
@ -74,9 +75,7 @@ public class MsJmeterParser extends ScenarioImportAbstractParser {
|
|||
HashTree testPlan = this.getHashTree(scriptWrapper);
|
||||
MsScenario scenario = new MsScenario();
|
||||
scenario.setReferenced("REF");
|
||||
LinkedList<MsTestElement> hashTrees = new LinkedList<>();
|
||||
scenario.setHashTree(hashTrees);
|
||||
getTree(testPlan, scenario);
|
||||
jmterHashTree(testPlan, scenario);
|
||||
this.projectId = request.getProjectId();
|
||||
|
||||
ScenarioImport scenarioImport = new ScenarioImport();
|
||||
|
@ -167,202 +166,251 @@ public class MsJmeterParser extends ScenarioImportAbstractParser {
|
|||
msTCPSampler.setPassword(tcpSampler.getProperty(ConfigTestElement.PASSWORD).getStringValue());
|
||||
}
|
||||
|
||||
private void getTree(HashTree tree, MsTestElement scenario) {
|
||||
private void convertDubboSample(MsDubboSampler elementNode, DubboSample sampler) {
|
||||
elementNode.setType("DubboSampler");
|
||||
elementNode.setProtocol("dubbo://");
|
||||
elementNode.set_interface(sampler.getPropertyAsString("FIELD_DUBBO_INTERFACE"));
|
||||
elementNode.setMethod(sampler.getPropertyAsString("FIELD_DUBBO_METHOD"));
|
||||
|
||||
MsConfigCenter configCenter = new MsConfigCenter();
|
||||
configCenter.setProtocol(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_PROTOCOL"));
|
||||
configCenter.setGroup(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_GROUP"));
|
||||
configCenter.setNamespace(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_NAMESPACE"));
|
||||
configCenter.setUsername(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_USER_NAME"));
|
||||
configCenter.setPassword(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_PASSWORD"));
|
||||
configCenter.setAddress(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_ADDRESS"));
|
||||
configCenter.setTimeout(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_TIMEOUT"));
|
||||
elementNode.setConfigCenter(configCenter);
|
||||
|
||||
MsRegistryCenter registryCenter = new MsRegistryCenter();
|
||||
registryCenter.setProtocol(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_PROTOCOL"));
|
||||
registryCenter.setAddress(sampler.getPropertyAsString("FIELD_DUBBO_ADDRESS"));
|
||||
registryCenter.setGroup(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_GROUP"));
|
||||
registryCenter.setUsername(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_USER_NAME"));
|
||||
registryCenter.setPassword(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_PASSWORD"));
|
||||
registryCenter.setTimeout(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_TIMEOUT"));
|
||||
elementNode.setRegistryCenter(registryCenter);
|
||||
|
||||
MsConsumerAndService consumerAndService = new MsConsumerAndService();
|
||||
consumerAndService.setAsync(sampler.getPropertyAsString("FIELD_DUBBO_ASYNC"));
|
||||
consumerAndService.setCluster(sampler.getPropertyAsString("FIELD_DUBBO_CLUSTER"));
|
||||
consumerAndService.setConnections(sampler.getPropertyAsString("FIELD_DUBBO_CONNECTIONS"));
|
||||
consumerAndService.setGroup(sampler.getPropertyAsString("FIELD_DUBBO_GROUP"));
|
||||
consumerAndService.setLoadBalance(sampler.getPropertyAsString("FIELD_DUBBO_LOADBALANCE"));
|
||||
consumerAndService.setVersion(sampler.getPropertyAsString("FIELD_DUBBO_VERSION"));
|
||||
consumerAndService.setTimeout(sampler.getPropertyAsString("FIELD_DUBBO_TIMEOUT"));
|
||||
elementNode.setConsumerAndService(consumerAndService);
|
||||
|
||||
List<MethodArgument> methodArguments = Constants.getMethodArgs(sampler);
|
||||
if (CollectionUtils.isNotEmpty(methodArguments)) {
|
||||
List<KeyValue> methodArgs = new LinkedList<>();
|
||||
methodArguments.forEach(item -> {
|
||||
KeyValue keyValue = new KeyValue(item.getParamType(), item.getParamValue());
|
||||
methodArgs.add(keyValue);
|
||||
});
|
||||
elementNode.setArgs(methodArgs);
|
||||
}
|
||||
|
||||
List<MethodArgument> arguments = Constants.getAttachmentArgs(sampler);
|
||||
if (CollectionUtils.isNotEmpty(arguments)) {
|
||||
List<KeyValue> methodArgs = new LinkedList<>();
|
||||
arguments.forEach(item -> {
|
||||
KeyValue keyValue = new KeyValue(item.getParamType(), item.getParamValue());
|
||||
methodArgs.add(keyValue);
|
||||
});
|
||||
elementNode.setAttachmentArgs(methodArgs);
|
||||
}
|
||||
}
|
||||
|
||||
private void convertJDBCSampler(MsJDBCSampler msJDBCSampler, JDBCSampler jdbcSampler) {
|
||||
msJDBCSampler.setType("JDBCSampler");
|
||||
msJDBCSampler.setName(jdbcSampler.getName());
|
||||
msJDBCSampler.setProtocol("SQL");
|
||||
msJDBCSampler.setQuery(jdbcSampler.getQuery());
|
||||
msJDBCSampler.setQueryTimeout(StringUtils.isNotEmpty(jdbcSampler.getQueryTimeout()) ? Long.parseLong(jdbcSampler.getQueryTimeout()) : 0L);
|
||||
msJDBCSampler.setResultVariable(jdbcSampler.getResultVariable());
|
||||
msJDBCSampler.setVariableNames(jdbcSampler.getVariableNames());
|
||||
}
|
||||
|
||||
private void convertMsExtract(MsExtract extract, Object key) {
|
||||
// 提取数据单独处理
|
||||
MsExtract extract = new MsExtract();
|
||||
extract.setType("Extract");
|
||||
extract.setJson(new LinkedList<>());
|
||||
extract.setRegex(new LinkedList<>());
|
||||
extract.setXpath(new LinkedList<>());
|
||||
// 断言规则
|
||||
MsAssertions assertions = new MsAssertions();
|
||||
if (key instanceof RegexExtractor) {
|
||||
MsExtractRegex regex = new MsExtractRegex();
|
||||
RegexExtractor regexExtractor = (RegexExtractor) key;
|
||||
if (regexExtractor.useRequestHeaders()) {
|
||||
regex.setUseHeaders("request_headers");
|
||||
} else if (regexExtractor.useBody()) {
|
||||
regex.setUseHeaders("false");
|
||||
} else if (regexExtractor.useUnescapedBody()) {
|
||||
regex.setUseHeaders("unescaped");
|
||||
} else if (regexExtractor.useBodyAsDocument()) {
|
||||
regex.setUseHeaders("as_document");
|
||||
} else if (regexExtractor.useUrl()) {
|
||||
regex.setUseHeaders("URL");
|
||||
}
|
||||
regex.setExpression(regexExtractor.getRegex());
|
||||
regex.setVariable(regexExtractor.getRefName());
|
||||
extract.setName(regexExtractor.getName());
|
||||
extract.getRegex().add(regex);
|
||||
} else if (key instanceof XPath2Extractor) {
|
||||
XPath2Extractor xPath2Extractor = (XPath2Extractor) key;
|
||||
MsExtractXPath xPath = new MsExtractXPath();
|
||||
xPath.setVariable(xPath2Extractor.getRefName());
|
||||
xPath.setExpression(xPath2Extractor.getXPathQuery());
|
||||
|
||||
extract.setName(xPath2Extractor.getName());
|
||||
extract.getXpath().add(xPath);
|
||||
} else if (key instanceof JSONPostProcessor) {
|
||||
JSONPostProcessor jsonPostProcessor = (JSONPostProcessor) key;
|
||||
MsExtractJSONPath jsonPath = new MsExtractJSONPath();
|
||||
jsonPath.setVariable(jsonPostProcessor.getRefNames());
|
||||
jsonPath.setExpression(jsonPostProcessor.getJsonPathExpressions());
|
||||
extract.setName(jsonPostProcessor.getName());
|
||||
extract.getJson().add(jsonPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void convertMsAssertions(MsAssertions assertions, Object key) {
|
||||
assertions.setJsonPath(new LinkedList<>());
|
||||
assertions.setJsr223(new LinkedList<>());
|
||||
assertions.setXpath2(new LinkedList<>());
|
||||
assertions.setRegex(new LinkedList<>());
|
||||
assertions.setDuration(new MsAssertionDuration());
|
||||
assertions.setType("Assertions");
|
||||
if (key instanceof ResponseAssertion) {
|
||||
MsAssertionRegex assertionRegex = new MsAssertionRegex();
|
||||
ResponseAssertion assertion = (ResponseAssertion) key;
|
||||
assertionRegex.setDescription(assertion.getName());
|
||||
assertionRegex.setAssumeSuccess(assertion.getAssumeSuccess());
|
||||
assertionRegex.setExpression(assertion.getTestStrings().getStringValue());
|
||||
if (assertion.isTestFieldRequestData()) {
|
||||
assertionRegex.setSubject("Response Data");
|
||||
}
|
||||
if (assertion.isTestFieldResponseCode()) {
|
||||
assertionRegex.setSubject("Response Code");
|
||||
}
|
||||
if (assertion.isTestFieldRequestHeaders()) {
|
||||
assertionRegex.setSubject("Response Headers");
|
||||
}
|
||||
assertions.setName(assertion.getName());
|
||||
assertions.getRegex().add(assertionRegex);
|
||||
} else if (key instanceof JSONPathAssertion) {
|
||||
MsAssertionJsonPath assertionJsonPath = new MsAssertionJsonPath();
|
||||
JSONPathAssertion jsonPathAssertion = (JSONPathAssertion) key;
|
||||
assertionJsonPath.setDescription(jsonPathAssertion.getName());
|
||||
assertionJsonPath.setExpression(jsonPathAssertion.getJsonPath());
|
||||
assertionJsonPath.setExpect(jsonPathAssertion.getExpectedValue());
|
||||
assertions.setName(jsonPathAssertion.getName());
|
||||
assertions.getJsonPath().add(assertionJsonPath);
|
||||
} else if (key instanceof XPath2Assertion) {
|
||||
MsAssertionXPath2 assertionXPath2 = new MsAssertionXPath2();
|
||||
XPath2Assertion xPath2Assertion = (XPath2Assertion) key;
|
||||
assertionXPath2.setExpression(xPath2Assertion.getXPathString());
|
||||
assertions.setName(xPath2Assertion.getName());
|
||||
assertions.getXpath2().add(assertionXPath2);
|
||||
} else if (key instanceof JSR223Assertion) {
|
||||
MsAssertionJSR223 msAssertionJSR223 = new MsAssertionJSR223();
|
||||
JSR223Assertion jsr223Assertion = (JSR223Assertion) key;
|
||||
msAssertionJSR223.setName(jsr223Assertion.getName());
|
||||
msAssertionJSR223.setScript(jsr223Assertion.getScript());
|
||||
msAssertionJSR223.setScriptLanguage(jsr223Assertion.getScriptLanguage());
|
||||
assertions.setName(jsr223Assertion.getName());
|
||||
|
||||
assertions.getJsr223().add(msAssertionJSR223);
|
||||
} else if (key instanceof DurationAssertion) {
|
||||
MsAssertionDuration assertionDuration = new MsAssertionDuration();
|
||||
DurationAssertion durationAssertion = (DurationAssertion) key;
|
||||
assertionDuration.setValue(durationAssertion.getProperty("DurationAssertion.duration").getIntValue());
|
||||
assertions.setName(durationAssertion.getName());
|
||||
assertions.setDuration(assertionDuration);
|
||||
}
|
||||
}
|
||||
|
||||
private void jmterHashTree(HashTree tree, MsTestElement scenario) {
|
||||
for (Object key : tree.keySet()) {
|
||||
MsTestElement elementNode = null;
|
||||
if (CollectionUtils.isEmpty(scenario.getHashTree())) {
|
||||
scenario.setHashTree(new LinkedList<>());
|
||||
}
|
||||
// 测试计划
|
||||
if (key instanceof TestPlan) {
|
||||
scenario.setName(((TestPlan) key).getName());
|
||||
elementNode = new MsJmeterElement();
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(key));
|
||||
elementNode.setName(jsonObject.get("name") == null ? "" : jsonObject.get("name").toString());
|
||||
elementNode.setName(((TestPlan) key).getName());
|
||||
((MsJmeterElement) elementNode).setJmeterElement(key);
|
||||
} else if (key instanceof ThreadGroup) {
|
||||
}
|
||||
// 线程组
|
||||
else if (key instanceof ThreadGroup) {
|
||||
elementNode = new MsScenario(((ThreadGroup) key).getName());
|
||||
} else if (key instanceof HTTPSamplerProxy) {
|
||||
}
|
||||
// HTTP请求
|
||||
else if (key instanceof HTTPSamplerProxy) {
|
||||
elementNode = new MsHTTPSamplerProxy();
|
||||
((MsHTTPSamplerProxy) elementNode).setBody(new Body());
|
||||
convertHttpSampler((MsHTTPSamplerProxy) elementNode, (HTTPSamplerProxy) key);
|
||||
} else if (key instanceof TCPSampler) {
|
||||
}
|
||||
// TCP请求
|
||||
else if (key instanceof TCPSampler) {
|
||||
elementNode = new MsTCPSampler();
|
||||
TCPSampler tcpSampler = (TCPSampler) key;
|
||||
convertTCPSampler((MsTCPSampler) elementNode, tcpSampler);
|
||||
} else if (key instanceof DubboSample) {
|
||||
}
|
||||
// DUBBO请求
|
||||
else if (key instanceof DubboSample) {
|
||||
DubboSample sampler = (DubboSample) key;
|
||||
elementNode = new MsDubboSampler();
|
||||
elementNode.setType("DubboSampler");
|
||||
((MsDubboSampler) elementNode).setProtocol("dubbo://");
|
||||
((MsDubboSampler) elementNode).set_interface(sampler.getPropertyAsString("FIELD_DUBBO_INTERFACE"));
|
||||
((MsDubboSampler) elementNode).setMethod(sampler.getPropertyAsString("FIELD_DUBBO_METHOD"));
|
||||
|
||||
MsConfigCenter configCenter = new MsConfigCenter();
|
||||
configCenter.setProtocol(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_PROTOCOL"));
|
||||
configCenter.setGroup(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_GROUP"));
|
||||
configCenter.setNamespace(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_NAMESPACE"));
|
||||
configCenter.setUsername(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_USER_NAME"));
|
||||
configCenter.setPassword(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_PASSWORD"));
|
||||
configCenter.setAddress(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_ADDRESS"));
|
||||
configCenter.setTimeout(sampler.getPropertyAsString("FIELD_DUBBO_CONFIG_CENTER_TIMEOUT"));
|
||||
((MsDubboSampler) elementNode).setConfigCenter(configCenter);
|
||||
|
||||
MsRegistryCenter registryCenter = new MsRegistryCenter();
|
||||
registryCenter.setProtocol(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_PROTOCOL"));
|
||||
registryCenter.setAddress(sampler.getPropertyAsString("FIELD_DUBBO_ADDRESS"));
|
||||
registryCenter.setGroup(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_GROUP"));
|
||||
registryCenter.setUsername(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_USER_NAME"));
|
||||
registryCenter.setPassword(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_PASSWORD"));
|
||||
registryCenter.setTimeout(sampler.getPropertyAsString("FIELD_DUBBO_REGISTRY_TIMEOUT"));
|
||||
((MsDubboSampler) elementNode).setRegistryCenter(registryCenter);
|
||||
|
||||
MsConsumerAndService consumerAndService = new MsConsumerAndService();
|
||||
consumerAndService.setAsync(sampler.getPropertyAsString("FIELD_DUBBO_ASYNC"));
|
||||
consumerAndService.setCluster(sampler.getPropertyAsString("FIELD_DUBBO_CLUSTER"));
|
||||
consumerAndService.setConnections(sampler.getPropertyAsString("FIELD_DUBBO_CONNECTIONS"));
|
||||
consumerAndService.setGroup(sampler.getPropertyAsString("FIELD_DUBBO_GROUP"));
|
||||
consumerAndService.setLoadBalance(sampler.getPropertyAsString("FIELD_DUBBO_LOADBALANCE"));
|
||||
consumerAndService.setVersion(sampler.getPropertyAsString("FIELD_DUBBO_VERSION"));
|
||||
consumerAndService.setTimeout(sampler.getPropertyAsString("FIELD_DUBBO_TIMEOUT"));
|
||||
((MsDubboSampler) elementNode).setConsumerAndService(consumerAndService);
|
||||
|
||||
List<MethodArgument> methodArguments = Constants.getMethodArgs(sampler);
|
||||
if (CollectionUtils.isNotEmpty(methodArguments)) {
|
||||
List<KeyValue> methodArgs = new LinkedList<>();
|
||||
methodArguments.forEach(item -> {
|
||||
KeyValue keyValue = new KeyValue(item.getParamType(), item.getParamValue());
|
||||
methodArgs.add(keyValue);
|
||||
});
|
||||
((MsDubboSampler) elementNode).setArgs(methodArgs);
|
||||
}
|
||||
|
||||
List<MethodArgument> arguments = Constants.getAttachmentArgs(sampler);
|
||||
if (CollectionUtils.isNotEmpty(arguments)) {
|
||||
List<KeyValue> methodArgs = new LinkedList<>();
|
||||
arguments.forEach(item -> {
|
||||
KeyValue keyValue = new KeyValue(item.getParamType(), item.getParamValue());
|
||||
methodArgs.add(keyValue);
|
||||
});
|
||||
((MsDubboSampler) elementNode).setAttachmentArgs(methodArgs);
|
||||
}
|
||||
|
||||
} else if (key instanceof JDBCSampler) {
|
||||
MsJDBCSampler msJDBCSampler = new MsJDBCSampler();
|
||||
convertDubboSample((MsDubboSampler) elementNode, sampler);
|
||||
}
|
||||
// JDBC请求
|
||||
else if (key instanceof JDBCSampler) {
|
||||
elementNode = new MsJDBCSampler();
|
||||
JDBCSampler jdbcSampler = (JDBCSampler) key;
|
||||
msJDBCSampler.setType("JDBCSampler");
|
||||
msJDBCSampler.setName(jdbcSampler.getName());
|
||||
msJDBCSampler.setProtocol("SQL");
|
||||
msJDBCSampler.setQuery(jdbcSampler.getQuery());
|
||||
msJDBCSampler.setQueryTimeout(Long.parseLong(jdbcSampler.getQueryTimeout()));
|
||||
msJDBCSampler.setResultVariable(jdbcSampler.getResultVariable());
|
||||
msJDBCSampler.setVariableNames(jdbcSampler.getVariableNames());
|
||||
elementNode = msJDBCSampler;
|
||||
convertJDBCSampler((MsJDBCSampler) elementNode, jdbcSampler);
|
||||
} else if (key instanceof JSR223Sampler) {
|
||||
JSR223Sampler jsr223Sampler = (JSR223Sampler) key;
|
||||
elementNode = new MsJSR223Processor();
|
||||
BeanUtils.copyBean(elementNode, jsr223Sampler);
|
||||
} else if (key instanceof JSR223PostProcessor) {
|
||||
}
|
||||
// 后置脚本
|
||||
else if (key instanceof JSR223PostProcessor) {
|
||||
JSR223PostProcessor jsr223Sampler = (JSR223PostProcessor) key;
|
||||
elementNode = new MsJSR223PostProcessor();
|
||||
BeanUtils.copyBean(elementNode, jsr223Sampler);
|
||||
} else if (key instanceof JSR223PreProcessor) {
|
||||
}
|
||||
// 前置脚本
|
||||
else if (key instanceof JSR223PreProcessor) {
|
||||
JSR223PreProcessor jsr223Sampler = (JSR223PreProcessor) key;
|
||||
elementNode = new MsJSR223PreProcessor();
|
||||
BeanUtils.copyBean(elementNode, jsr223Sampler);
|
||||
} else if (key instanceof ResponseAssertion) {
|
||||
MsAssertionRegex assertionRegex = new MsAssertionRegex();
|
||||
ResponseAssertion assertion = (ResponseAssertion) key;
|
||||
assertionRegex.setDescription(assertion.getName());
|
||||
assertionRegex.setAssumeSuccess(assertion.getAssumeSuccess());
|
||||
assertionRegex.setExpression(assertion.getTestStrings().getStringValue());
|
||||
if (assertion.isTestFieldRequestData()) {
|
||||
assertionRegex.setSubject("Response Data");
|
||||
}
|
||||
if (assertion.isTestFieldResponseCode()) {
|
||||
assertionRegex.setSubject("Response Code");
|
||||
}
|
||||
if (assertion.isTestFieldRequestHeaders()) {
|
||||
assertionRegex.setSubject("Response Headers");
|
||||
}
|
||||
assertions.getRegex().add(assertionRegex);
|
||||
} else if (key instanceof JSONPathAssertion) {
|
||||
MsAssertionJsonPath assertionJsonPath = new MsAssertionJsonPath();
|
||||
JSONPathAssertion jsonPathAssertion = (JSONPathAssertion) key;
|
||||
assertionJsonPath.setDescription(jsonPathAssertion.getName());
|
||||
assertionJsonPath.setExpression(jsonPathAssertion.getJsonPath());
|
||||
assertionJsonPath.setExpect(jsonPathAssertion.getExpectedValue());
|
||||
assertions.getJsonPath().add(assertionJsonPath);
|
||||
} else if (key instanceof XPath2Assertion) {
|
||||
MsAssertionXPath2 assertionXPath2 = new MsAssertionXPath2();
|
||||
XPath2Assertion xPath2Assertion = (XPath2Assertion) key;
|
||||
assertionXPath2.setExpression(xPath2Assertion.getXPathString());
|
||||
assertions.getXpath2().add(assertionXPath2);
|
||||
} else if (key instanceof JSR223Assertion) {
|
||||
MsAssertionJSR223 msAssertionJSR223 = new MsAssertionJSR223();
|
||||
JSR223Assertion jsr223Assertion = (JSR223Assertion) key;
|
||||
msAssertionJSR223.setName(jsr223Assertion.getName());
|
||||
msAssertionJSR223.setScript(jsr223Assertion.getScript());
|
||||
msAssertionJSR223.setScriptLanguage(jsr223Assertion.getScriptLanguage());
|
||||
assertions.getJsr223().add(msAssertionJSR223);
|
||||
} else if (key instanceof DurationAssertion) {
|
||||
MsAssertionDuration assertionDuration = new MsAssertionDuration();
|
||||
DurationAssertion durationAssertion = (DurationAssertion) key;
|
||||
assertionDuration.setValue(durationAssertion.getProperty("DurationAssertion.duration").getIntValue());
|
||||
assertions.setDuration(assertionDuration);
|
||||
} else if (key instanceof RegexExtractor) {
|
||||
MsExtractRegex regex = new MsExtractRegex();
|
||||
RegexExtractor regexExtractor = (RegexExtractor) key;
|
||||
if (regexExtractor.useRequestHeaders()) {
|
||||
regex.setUseHeaders("request_headers");
|
||||
} else if (regexExtractor.useBody()) {
|
||||
regex.setUseHeaders("false");
|
||||
} else if (regexExtractor.useUnescapedBody()) {
|
||||
regex.setUseHeaders("unescaped");
|
||||
} else if (regexExtractor.useBodyAsDocument()) {
|
||||
regex.setUseHeaders("as_document");
|
||||
} else if (regexExtractor.useUrl()) {
|
||||
regex.setUseHeaders("URL");
|
||||
}
|
||||
regex.setType("Extract");
|
||||
regex.setExpression(regexExtractor.getRegex());
|
||||
regex.setVariable(regexExtractor.getRefName());
|
||||
extract.setName(regexExtractor.getName());
|
||||
extract.getRegex().add(regex);
|
||||
} else if (key instanceof XPath2Extractor) {
|
||||
XPath2Extractor xPath2Extractor = (XPath2Extractor) key;
|
||||
MsExtractXPath xPath = new MsExtractXPath();
|
||||
xPath.setVariable(xPath2Extractor.getRefName());
|
||||
xPath.setExpression(xPath2Extractor.getXPathQuery());
|
||||
xPath.setType("Extract");
|
||||
extract.getXpath().add(xPath);
|
||||
} else if (key instanceof JSONPostProcessor) {
|
||||
JSONPostProcessor jsonPostProcessor = (JSONPostProcessor) key;
|
||||
MsExtractJSONPath jsonPath = new MsExtractJSONPath();
|
||||
jsonPath.setVariable(jsonPostProcessor.getRefNames());
|
||||
jsonPath.setExpression(jsonPostProcessor.getJsonPathExpressions());
|
||||
jsonPath.setType("Extract");
|
||||
extract.getJson().add(jsonPath);
|
||||
} else if (key instanceof ConstantTimer) {
|
||||
}
|
||||
// 提取参数
|
||||
else if (key instanceof ResponseAssertion || key instanceof JSONPathAssertion || key instanceof XPath2Assertion || key instanceof JSR223Assertion || key instanceof DurationAssertion) {
|
||||
elementNode = new MsAssertions();
|
||||
convertMsAssertions((MsAssertions) elementNode, key);
|
||||
}
|
||||
// 断言规则
|
||||
else if (key instanceof RegexExtractor || key instanceof XPath2Extractor || key instanceof JSONPostProcessor) {
|
||||
elementNode = new MsExtract();
|
||||
convertMsExtract((MsExtract) elementNode, key);
|
||||
}
|
||||
// 定时器
|
||||
else if (key instanceof ConstantTimer) {
|
||||
elementNode = new MsConstantTimer();
|
||||
BeanUtils.copyBean(elementNode, key);
|
||||
elementNode.setType("ConstantTimer");
|
||||
} else if (key instanceof IfController) {
|
||||
}
|
||||
// IF条件控制器
|
||||
else if (key instanceof IfController) {
|
||||
elementNode = new MsIfController();
|
||||
BeanUtils.copyBean(elementNode, key);
|
||||
elementNode.setType("IfController");
|
||||
} else if (key instanceof LoopController) {
|
||||
}
|
||||
// 次数循环控制器
|
||||
else if (key instanceof LoopController) {
|
||||
elementNode = new MsLoopController();
|
||||
BeanUtils.copyBean(elementNode, key);
|
||||
elementNode.setType("LoopController");
|
||||
|
@ -372,7 +420,9 @@ public class MsJmeterParser extends ScenarioImportAbstractParser {
|
|||
countController.setLoops(loopController.getLoops());
|
||||
countController.setProceed(true);
|
||||
((MsLoopController) elementNode).setCountController(countController);
|
||||
} else if (key instanceof WhileController) {
|
||||
}
|
||||
// While循环控制器
|
||||
else if (key instanceof WhileController) {
|
||||
elementNode = new MsLoopController();
|
||||
BeanUtils.copyBean(elementNode, key);
|
||||
elementNode.setType("LoopController");
|
||||
|
@ -381,7 +431,9 @@ public class MsJmeterParser extends ScenarioImportAbstractParser {
|
|||
MsWhileController countController = new MsWhileController();
|
||||
countController.setValue(whileController.getCondition());
|
||||
((MsLoopController) elementNode).setWhileController(countController);
|
||||
} else if (key instanceof ForeachController) {
|
||||
}
|
||||
// Foreach 循环控制器
|
||||
else if (key instanceof ForeachController) {
|
||||
elementNode = new MsLoopController();
|
||||
BeanUtils.copyBean(elementNode, key);
|
||||
elementNode.setType("LoopController");
|
||||
|
@ -391,29 +443,39 @@ public class MsJmeterParser extends ScenarioImportAbstractParser {
|
|||
countController.setInputVal(foreachController.getInputValString());
|
||||
countController.setReturnVal(foreachController.getReturnValString());
|
||||
((MsLoopController) elementNode).setForEachController(countController);
|
||||
} else {
|
||||
}
|
||||
// 平台不能识别的Jmeter步骤
|
||||
else {
|
||||
elementNode = new MsJmeterElement();
|
||||
elementNode.setType("JmeterElement");
|
||||
JSONObject jsonObject = JSON.parseObject(JSON.toJSONString(key));
|
||||
elementNode.setName(jsonObject.get("name") == null ? "" : jsonObject.get("name").toString());
|
||||
TestElement testElement = (TestElement) key;
|
||||
elementNode.setName(testElement.getName());
|
||||
((MsJmeterElement) elementNode).setJmeterElement(key);
|
||||
}
|
||||
//提取参数
|
||||
if (CollectionUtils.isNotEmpty(extract.getJson()) || CollectionUtils.isNotEmpty(extract.getRegex()) || CollectionUtils.isNotEmpty(extract.getXpath())) {
|
||||
elementNode = extract;
|
||||
}
|
||||
//断言规则
|
||||
if (CollectionUtils.isNotEmpty(assertions.getRegex()) || CollectionUtils.isNotEmpty(assertions.getJsonPath())
|
||||
|| CollectionUtils.isNotEmpty(assertions.getJsr223()) || CollectionUtils.isNotEmpty(assertions.getXpath2()) || assertions.getDuration() != null) {
|
||||
elementNode = assertions;
|
||||
}
|
||||
|
||||
elementNode.setResourceId(UUID.randomUUID().toString());
|
||||
elementNode.setId(UUID.randomUUID().toString());
|
||||
scenario.getHashTree().add(elementNode);
|
||||
elementNode.setIndex(scenario.getHashTree().size() + 1 + "");
|
||||
// 提取参数
|
||||
if (elementNode instanceof MsExtract) {
|
||||
if (CollectionUtils.isNotEmpty(((MsExtract) elementNode).getJson()) || CollectionUtils.isNotEmpty(((MsExtract) elementNode).getRegex()) || CollectionUtils.isNotEmpty(((MsExtract) elementNode).getXpath())) {
|
||||
scenario.getHashTree().add(elementNode);
|
||||
}
|
||||
}
|
||||
//断言规则
|
||||
else if (elementNode instanceof MsAssertions) {
|
||||
if (CollectionUtils.isNotEmpty(((MsAssertions) elementNode).getRegex()) || CollectionUtils.isNotEmpty(((MsAssertions) elementNode).getJsonPath())
|
||||
|| CollectionUtils.isNotEmpty(((MsAssertions) elementNode).getJsr223()) || CollectionUtils.isNotEmpty(((MsAssertions) elementNode).getXpath2()) || ((MsAssertions) elementNode).getDuration() != null) {
|
||||
scenario.getHashTree().add(elementNode);
|
||||
}
|
||||
}
|
||||
// 争取其他请求
|
||||
else {
|
||||
scenario.getHashTree().add(elementNode);
|
||||
}
|
||||
// 递归子项
|
||||
HashTree node = tree.get(key);
|
||||
if (node != null) {
|
||||
getTree(node, elementNode);
|
||||
jmterHashTree(node, elementNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -393,7 +393,7 @@
|
|||
},
|
||||
{
|
||||
title: this.$t('api_test.automation.scenario_import'),
|
||||
show: this.operatingElements.indexOf('scenario') === 0,
|
||||
show: this.operatingElements && this.operatingElements.indexOf('scenario') === 0,
|
||||
titleColor: "#606266",
|
||||
titleBgColor: "#F4F4F5",
|
||||
icon: "movie",
|
||||
|
@ -437,7 +437,7 @@
|
|||
},
|
||||
showButton(...names) {
|
||||
for (const name of names) {
|
||||
if (this.operatingElements.includes(name)) {
|
||||
if (name && this.operatingElements && this.operatingElements.includes(name)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@
|
|||
request: {
|
||||
type: Object,
|
||||
},
|
||||
defTitle: {type: String, default: "Jmeter组建"},
|
||||
defTitle: {type: String, default: "Jmeter组件"},
|
||||
defColor: {type: String, default: "#606260"},
|
||||
defBackgroundColor: {type: String, default: "#F4F4FF"},
|
||||
node: {},
|
||||
|
|
Loading…
Reference in New Issue