fix(接口测试): 修复导入JMeter脚本文件

--bug=1015184 --user=赵勇 【接口测试】github#16100,.jmx里含content-type为multipart/form-data的请求时,导到平台请求体不是form-data https://www.tapd.cn/55049933/s/1207309
This commit is contained in:
fit2-zhao 2022-07-22 15:03:22 +08:00 committed by f2c-ci-robot[bot]
parent e12241bb45
commit 77a24d38bc
1 changed files with 10 additions and 24 deletions

View File

@ -48,6 +48,7 @@ import io.metersphere.commons.utils.CommonBeanFactory;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.plugin.core.MsTestElement;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.jmeter.assertions.*;
import org.apache.jmeter.config.ConfigTestElement;
@ -114,29 +115,12 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
private List<ApiScenarioWithBLOBs> parseObj(MsScenario msScenario, ApiTestImportRequest request) {
List<ApiScenarioWithBLOBs> scenarioWithBLOBsList = new ArrayList<>();
ApiScenarioWithBLOBs scenarioWithBLOBs = new ApiScenarioWithBLOBs();
/* ApiScenarioModule selectModule = null;
String selectModulePath = null;
if (StringUtils.isNotBlank(request.getModuleId())) {
selectModule = ApiScenarioImportUtil.getSelectModule(request.getModuleId());
if (selectModule != null) {
selectModulePath = ApiScenarioImportUtil.getSelectModulePath(selectModule.getName(), selectModule.getParentId());
}
}
ApiScenarioModule module = ApiScenarioImportUtil.buildModule(selectModule, msScenario.getName(), this.projectId);*/
scenarioWithBLOBs.setName(request.getFileName());
scenarioWithBLOBs.setProjectId(request.getProjectId());
if (msScenario != null && CollectionUtils.isNotEmpty(msScenario.getHashTree())) {
scenarioWithBLOBs.setStepTotal(msScenario.getHashTree().size());
scenarioWithBLOBs.setModulePath("/" + msScenario.getName());
}
/*if (module != null) {
scenarioWithBLOBs.setApiScenarioModuleId(module.getId());
if (StringUtils.isNotBlank(selectModulePath)) {
scenarioWithBLOBs.setModulePath(selectModulePath + "/" + module.getName());
} else {
scenarioWithBLOBs.setModulePath("/" + module.getName());
}
}*/
scenarioWithBLOBs.setId(UUID.randomUUID().toString());
scenarioWithBLOBs.setScenarioDefinition(JSON.toJSONString(msScenario));
scenarioWithBLOBsList.add(scenarioWithBLOBs);
@ -305,7 +289,15 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
samplerProxy.getBody().setRaw(v);
});
samplerProxy.getBody().initKvs();
} else if (StringUtils.isNotEmpty(bodyType) || (source.getMethod().equalsIgnoreCase("POST") && source.getArguments().getArgumentsAsMap().size() > 0)) {
} else if (source.getDoMultipart()) {
samplerProxy.getBody().setType(Body.FORM_DATA);
source.getArguments().getArgumentsAsMap().forEach((k, v) -> {
KeyValue keyValue = new KeyValue(k, v);
samplerProxy.getBody().getKvs().add(keyValue);
});
} else if (StringUtils.isNotEmpty(bodyType) ||
(source.getMethod().equalsIgnoreCase("POST") &&
MapUtils.isNotEmpty(source.getArguments().getArgumentsAsMap()))) {
samplerProxy.getBody().setType(Body.WWW_FROM);
source.getArguments().getArgumentsAsMap().forEach((k, v) -> {
KeyValue keyValue = new KeyValue(k, v);
@ -779,12 +771,6 @@ public class MsJmeterParser extends ApiImportAbstractParser<ScenarioImport> {
BeanUtils.copyBean(elementNode, key);
elementNode.setType("ConstantTimer");
}
// IF条件控制器这里平台方式和jmeter 不同暂时不处理
// else if (key instanceof IfController) {
// elementNode = new MsIfController();
// BeanUtils.copyBean(elementNode, key);
// elementNode.setType("IfController");
// }
// 次数循环控制器
else if (key instanceof LoopController) {
elementNode = new MsLoopController();