refactor(接口测试): 接口定义导入部分字段进行trim处理

This commit is contained in:
Jianguo-Genius 2024-09-09 14:37:39 +08:00 committed by Craftsman
parent d5c739a4da
commit 8d65802488
3 changed files with 13 additions and 9 deletions

View File

@ -77,12 +77,12 @@ public abstract class HttpApiDefinitionImportAbstractParser<T> implements ApiDef
protected ApiDefinitionDetail buildApiDefinition(String name, String path, String method, String modulePath, ImportRequest importRequest) {
ApiDefinitionDetail apiDefinition = new ApiDefinitionDetail();
apiDefinition.setId(IDGenerator.nextStr());
apiDefinition.setName(name);
apiDefinition.setPath(formatPath(path));
apiDefinition.setProtocol(importRequest.getProtocol());
apiDefinition.setMethod(method);
apiDefinition.setProjectId(importRequest.getProjectId());
apiDefinition.setModulePath(modulePath);
apiDefinition.setName(StringUtils.trim(name));
apiDefinition.setPath(formatPath(StringUtils.trim(path)));
apiDefinition.setProtocol(StringUtils.trim(importRequest.getProtocol()));
apiDefinition.setMethod(StringUtils.trim(method));
apiDefinition.setProjectId(StringUtils.trim(importRequest.getProjectId()));
apiDefinition.setModulePath(StringUtils.trim(modulePath));
apiDefinition.setResponse(new ArrayList<>());
return apiDefinition;
}

View File

@ -100,10 +100,10 @@ public class JmeterParserApiDefinition implements ApiDefinitionImportParser<ApiI
for (AbstractMsProtocolTestElement protocolTestElement : msElement) {
ApiDefinitionDetail definition = new ApiDefinitionDetail();
definition.setName(protocolTestElement.getName());
definition.setName(StringUtils.trim(protocolTestElement.getName()));
if (protocolTestElement instanceof MsHTTPElement msHTTPElement) {
definition.setMethod(msHTTPElement.getMethod());
definition.setPath(msHTTPElement.getPath());
definition.setMethod(StringUtils.trim(msHTTPElement.getMethod()));
definition.setPath(StringUtils.trim(msHTTPElement.getPath()));
definition.setProtocol(ApiConstants.HTTP_PROTOCOL);
} else {
definition.setProtocol(polymorphicNameMap.get(protocolTestElement.getClass().getSimpleName()));

View File

@ -532,6 +532,10 @@ public class ApiDefinitionImportService {
ApiDefinitionDetail importApi = existenceApiDefinitionDetail.getImportApiDefinition();
ApiDefinitionDetail existenceApi = existenceApiDefinitionDetail.getExistenceApiDefinition();
if (StringUtils.isNotBlank(importApi.getModulePath()) && !StringUtils.startsWith(importApi.getModulePath(), "/")) {
importApi.setModulePath("/" + importApi.getModulePath());
}
boolean isSameRequest = false;
ApiDefinitionBlob apiDefinitionBlob = existenceApiDefinitionBlobMap.get(existenceApi.getId());
MsHTTPElement existenceMsHTTPElement = null;