refactor(接口测试): 修复ESB接口创建案例时请求参数为空的问题

--bug=1011754 --user=宋天阳 【接口测试】github#12046,tcp协议的接口定义在新建接口用例时,请求参数为空
https://www.tapd.cn/55049933/s/1127610
This commit is contained in:
song-tianyang 2022-03-30 14:58:52 +08:00 committed by CountryBuilder
parent 7aefade2c0
commit 0fcbb212d6
3 changed files with 37 additions and 36 deletions

View File

@ -1823,10 +1823,18 @@ public class ApiDefinitionService {
ApiDefinitionRequest request = new ApiDefinitionRequest();
request.setId(id);
List<ApiDefinitionResult> list = extApiDefinitionMapper.list(request);
ApiDefinitionResult result = null;
if (CollectionUtils.isNotEmpty(list)) {
return list.get(0);
result = list.get(0);
this.checkApiAttachInfo(result);
}
return result;
}
private void checkApiAttachInfo(ApiDefinitionResult result) {
if (StringUtils.equalsIgnoreCase("esb", result.getMethod())) {
esbApiParamService.handleApiEsbParams(result);
}
return null;
}

View File

@ -121,26 +121,6 @@ public class EsbApiParamService {
}
}
// try {
// if (StringUtils.isNotEmpty(res.getRequest())) {
// JSONObject jsonObj = JSONObject.parseObject(res.getRequest());
//
// JSONArray esbDataArray = JSONArray.parseArray(esbParamBlobs.getDataStruct());
// jsonObj.put("esbDataStruct", esbDataArray);
//
// JSONArray responseDataArray = JSONArray.parseArray(esbParamBlobs.getResponseDataStruct());
// jsonObj.put("backEsbDataStruct", responseDataArray);
//
// JSONObject backedScriptObj = JSONObject.parseObject(esbParamBlobs.getBackedScript());
// jsonObj.put("backScript", backedScriptObj);
//
// jsonObj.put("esbFrontedScript", esbParamBlobs.getFrontedScript());
//
// res.setRequest(jsonObj.toJSONString());
// }
// } catch (Exception e) {
// }
}
public void handleApiEsbParams(ApiTestCaseWithBLOBs res) {
@ -313,7 +293,7 @@ public class EsbApiParamService {
return keyValueList;
}
private List<KeyValue> genKeyValueListByDataStruct(MsTCPSampler tcpSampler, List<EsbDataStruct> dataStructRequestList) {
public List<KeyValue> genKeyValueListByDataStruct(MsTCPSampler tcpSampler, List<EsbDataStruct> dataStructRequestList) {
List<KeyValue> keyValueList = new ArrayList<>();
String sendRequest = tcpSampler.getRequest();
String paramRegexStr = "\\$\\{([^}]*)\\}";

View File

@ -4,13 +4,16 @@ import io.metersphere.api.dto.automation.TcpTreeTableDataStruct;
import io.metersphere.api.dto.automation.parse.TcpTreeTableDataParser;
import io.metersphere.api.dto.definition.SaveApiDefinitionRequest;
import io.metersphere.api.dto.definition.request.sampler.MsTCPSampler;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.commons.utils.LogUtil;
import io.metersphere.plugin.core.MsTestElement;
import io.metersphere.utils.LoggerUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import java.util.List;
/**
@ -21,6 +24,8 @@ import java.util.List;
@Service
@Transactional(rollbackFor = Exception.class)
public class TcpApiParamService {
@Resource
private EsbApiParamService esbApiParamService;
public SaveApiDefinitionRequest handleTcpRequest(SaveApiDefinitionRequest request) {
MsTCPSampler tcpSampler = this.handleTcpRequest(request.getRequest());
@ -51,19 +56,27 @@ public class TcpApiParamService {
try {
if (testElement instanceof MsTCPSampler) {
tcpSampler = (MsTCPSampler) testElement;
String reportType = tcpSampler.getReportType();
if (StringUtils.isNotEmpty(reportType)) {
switch (reportType) {
case "raw":
tcpSampler.setRequest(tcpSampler.getRawDataStruct());
break;
case "xml":
String xmlDataStruct = this.genValueFromEsbDataStructByParam(tcpSampler.getXmlDataStruct());
tcpSampler.setRequest(xmlDataStruct);
break;
case "json":
tcpSampler.setRequest(tcpSampler.getJsonDataStruct());
break;
String protocol = tcpSampler.getProtocol();
if(StringUtils.equalsIgnoreCase(protocol,"esb")){
if(CollectionUtils.isNotEmpty(tcpSampler.getEsbDataStruct())){
List<KeyValue> keyValueList = esbApiParamService.genKeyValueListByDataStruct(tcpSampler, tcpSampler.getEsbDataStruct());
tcpSampler.setParameters(keyValueList);
}
}else {
String reportType = tcpSampler.getReportType();
if (StringUtils.isNotEmpty(reportType)) {
switch (reportType) {
case "raw":
tcpSampler.setRequest(tcpSampler.getRawDataStruct());
break;
case "xml":
String xmlDataStruct = this.genValueFromEsbDataStructByParam(tcpSampler.getXmlDataStruct());
tcpSampler.setRequest(xmlDataStruct);
break;
case "json":
tcpSampler.setRequest(tcpSampler.getJsonDataStruct());
break;
}
}
}
}