mirror of
https://gitee.com/fit2cloud-feizhiyun/MeterSphere.git
synced 2024-12-02 20:19:16 +08:00
fix(接口测试): 兼容导入JMX历史数据
【【接口测试】导入jmx场景后直接点执行/调试,提示要先选环境】https://www.tapd.cn/55049933/bugtrace/bugs/view?bug_id=1155049933001026424 Signed-off-by: fit2-zhao <yong.zhao@fit2cloud.com>
This commit is contained in:
parent
07f9a08275
commit
93853efce8
@ -335,9 +335,11 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
samplerProxy.setUrl(this.getUrl(source));
|
||||
samplerProxy.setPath(null);
|
||||
samplerProxy.setCustomizeReq(true);
|
||||
samplerProxy.setIsRefEnvironment(false);
|
||||
}
|
||||
samplerProxy.setId(UUID.randomUUID().toString());
|
||||
samplerProxy.setType(ElementConstants.HTTP_SAMPLER);
|
||||
samplerProxy.setClazzName(MsHTTPSamplerProxy.class.getCanonicalName());
|
||||
body.getKvs().add(new KeyValue());
|
||||
body.getBinary().add(new KeyValue());
|
||||
|
||||
@ -375,6 +377,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
msTCPSampler.setUsername(tcpSampler.getProperty(ConfigTestElement.USERNAME).getStringValue());
|
||||
msTCPSampler.setPassword(tcpSampler.getProperty(ConfigTestElement.PASSWORD).getStringValue());
|
||||
msTCPSampler.setClassname(tcpSampler.getClassname());
|
||||
msTCPSampler.setClazzName(MsTCPSampler.class.getCanonicalName());
|
||||
}
|
||||
|
||||
private void convertDubboSample(MsDubboSampler elementNode, DubboSample sampler) {
|
||||
@ -431,6 +434,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
});
|
||||
}
|
||||
elementNode.setAttachmentArgs(attachmentArgs);
|
||||
elementNode.setClazzName(MsDubboSampler.class.getCanonicalName());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -558,6 +562,10 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
msJDBCSampler.setDataSourceId(dataPools.getDataSources().get(jdbcSampler.getPropertyAsString("dataSource")).getId());
|
||||
}
|
||||
msJDBCSampler.setVariables(new LinkedList<>());
|
||||
msJDBCSampler.setCustomizeReq(true);
|
||||
msJDBCSampler.setIsRefEnvironment(false);
|
||||
msJDBCSampler.setReferenced(ElementConstants.STEP_CREATED);
|
||||
msJDBCSampler.setClazzName(MsJDBCSampler.class.getCanonicalName());
|
||||
}
|
||||
|
||||
private void convertMsExtract(MsExtract extract, Object key) {
|
||||
@ -757,6 +765,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
BeanUtils.copyBean(elementNode, jsr223Sampler);
|
||||
((MsJSR223Processor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT));
|
||||
((MsJSR223Processor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage"));
|
||||
elementNode.setClazzName(MsJSR223Processor.class.getCanonicalName());
|
||||
}
|
||||
// BeanShell自定义脚本
|
||||
else if (key instanceof BeanShellSampler) {
|
||||
@ -766,6 +775,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
((MsJSR223Processor) elementNode).setJsrEnable(false);
|
||||
((MsJSR223Processor) elementNode).setScript(jsr223Sampler.getPropertyAsString("BeanShellSampler.query"));
|
||||
((MsJSR223Processor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage"));
|
||||
elementNode.setClazzName(MsJSR223Processor.class.getCanonicalName());
|
||||
}
|
||||
// 后置脚本
|
||||
else if (key instanceof JSR223PostProcessor) {
|
||||
@ -774,6 +784,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
BeanUtils.copyBean(elementNode, jsr223Sampler);
|
||||
((MsJSR223PostProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT));
|
||||
((MsJSR223PostProcessor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage"));
|
||||
elementNode.setClazzName(MsJSR223PostProcessor.class.getCanonicalName());
|
||||
} else if (key instanceof BeanShellPostProcessor) {
|
||||
elementNode = getMsTestElement((BeanShellPostProcessor) key);
|
||||
} else if (key instanceof BeanShellPreProcessor) {
|
||||
@ -786,22 +797,26 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
BeanUtils.copyBean(elementNode, jsr223Sampler);
|
||||
((MsJSR223PreProcessor) elementNode).setScript(jsr223Sampler.getPropertyAsString(ElementConstants.SCRIPT));
|
||||
((MsJSR223PreProcessor) elementNode).setScriptLanguage(jsr223Sampler.getPropertyAsString("scriptLanguage"));
|
||||
elementNode.setClazzName(MsJSR223PreProcessor.class.getCanonicalName());
|
||||
}
|
||||
// 断言规则
|
||||
else if (key instanceof ResponseAssertion || key instanceof JSONPathAssertion || key instanceof XPath2Assertion || key instanceof JSR223Assertion || key instanceof DurationAssertion) {
|
||||
elementNode = new MsAssertions();
|
||||
convertMsAssertions((MsAssertions) elementNode, key);
|
||||
elementNode.setClazzName(MsAssertions.class.getCanonicalName());
|
||||
}
|
||||
// 提取参数
|
||||
else if (key instanceof RegexExtractor || key instanceof XPath2Extractor || key instanceof JSONPostProcessor) {
|
||||
elementNode = new MsExtract();
|
||||
convertMsExtract((MsExtract) elementNode, key);
|
||||
elementNode.setClazzName(MsExtract.class.getCanonicalName());
|
||||
}
|
||||
// 定时器
|
||||
else if (key instanceof ConstantTimer) {
|
||||
elementNode = new MsConstantTimer();
|
||||
BeanUtils.copyBean(elementNode, key);
|
||||
elementNode.setType(ElementConstants.CONSTANT_TIMER);
|
||||
elementNode.setClazzName(MsConstantTimer.class.getCanonicalName());
|
||||
}
|
||||
// 次数循环控制器
|
||||
else if (key instanceof LoopController) {
|
||||
@ -814,6 +829,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
countController.setLoops(String.valueOf(loopController.getLoops()));
|
||||
countController.setProceed(true);
|
||||
((MsLoopController) elementNode).setCountController(countController);
|
||||
elementNode.setClazzName(MsLoopController.class.getCanonicalName());
|
||||
}
|
||||
// While循环控制器
|
||||
else if (key instanceof WhileController) {
|
||||
@ -825,6 +841,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
MsWhileController countController = new MsWhileController();
|
||||
countController.setValue(whileController.getCondition());
|
||||
((MsLoopController) elementNode).setWhileController(countController);
|
||||
elementNode.setClazzName(MsWhileController.class.getCanonicalName());
|
||||
}
|
||||
// Foreach 循环控制器
|
||||
else if (key instanceof ForeachController) {
|
||||
@ -837,12 +854,14 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
countController.setInputVal(foreachController.getInputValString());
|
||||
countController.setReturnVal(foreachController.getReturnValString());
|
||||
((MsLoopController) elementNode).setForEachController(countController);
|
||||
elementNode.setClazzName(ForeachController.class.getCanonicalName());
|
||||
} else if (key instanceof TransactionController) {
|
||||
TransactionController transactionController = (TransactionController) key;
|
||||
elementNode = new MsTransactionController();
|
||||
elementNode.setName(transactionController.getName());
|
||||
((MsTransactionController) elementNode).setGenerateParentSample(transactionController.isGenerateParentSample());
|
||||
((MsTransactionController) elementNode).setIncludeTimers(transactionController.isIncludeTimers());
|
||||
elementNode.setClazzName(MsTransactionController.class.getCanonicalName());
|
||||
} else if (StringUtils.equals(key.getClass().getName(), "net.xmeter.samplers.ConnectSampler")) {
|
||||
elementNode = getMqttElement(key, "io.metersphere.plugin.mqtt.sampler.MqttConnectSampler");
|
||||
} else if (StringUtils.equals(key.getClass().getName(), "net.xmeter.samplers.DisConnectSampler")) {
|
||||
@ -864,6 +883,7 @@ public class JMeterParser extends ApiImportAbstractParser<ScenarioImport> {
|
||||
elementNode.setName(testElement.getName());
|
||||
((MsJmeterElement) elementNode).setJmeterElement(objToXml(key));
|
||||
((MsJmeterElement) elementNode).setElementType(key.getClass().getSimpleName());
|
||||
elementNode.setClazzName(MsJmeterElement.class.getCanonicalName());
|
||||
}
|
||||
elementNode.setEnable(((TestElement) key).isEnabled());
|
||||
elementNode.setResourceId(UUID.randomUUID().toString());
|
||||
|
@ -65,6 +65,7 @@ import org.apache.commons.lang3.StringUtils;
|
||||
import org.apache.ibatis.session.ExecutorType;
|
||||
import org.apache.ibatis.session.SqlSession;
|
||||
import org.apache.ibatis.session.SqlSessionFactory;
|
||||
import org.apache.jmeter.protocol.http.sampler.HTTPSamplerProxy;
|
||||
import org.apache.jorphan.collections.HashTree;
|
||||
import org.apache.jorphan.collections.ListedHashTree;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@ -868,6 +869,7 @@ public class ApiScenarioService {
|
||||
public int getScenarioStep(List<String> ids) {
|
||||
return extApiScenarioReferenceIdMapper.selectByScenarioIds(ids);
|
||||
}
|
||||
|
||||
public List<ApiScenarioDTO> getScenarioDetail(List<String> ids) {
|
||||
if (CollectionUtils.isEmpty(ids)) {
|
||||
return new ArrayList<>();
|
||||
@ -2199,7 +2201,8 @@ public class ApiScenarioService {
|
||||
} else {
|
||||
//将复制的或者类型不是引用case的步骤赋予当前项目id,目的是为了运行的时候可以配置运行环境
|
||||
object.put("projectId", projectId);
|
||||
if (StringUtils.isEmpty(object.optString("url"))) {
|
||||
if (StringUtils.isEmpty(object.optString("url"))
|
||||
&& StringUtils.equals(object.optString("type"), HTTPSamplerProxy.class.getCanonicalName())) {
|
||||
object.put("isRefEnvironment", true);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user