fix(接口测试): postman 导入和har导入解析时不去重
--user=郭雨琦 --bug=1014714 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001014715
This commit is contained in:
parent
3dc5413680
commit
6bfc7eb425
|
@ -74,7 +74,6 @@ public class HarParser extends HarAbstractParser {
|
|||
harEntryList = har.log.entries;
|
||||
}
|
||||
|
||||
List<String> savedUrl = new ArrayList<>();
|
||||
|
||||
for (HarEntry entry : harEntryList) {
|
||||
HarRequest harRequest = entry.request;
|
||||
|
@ -91,12 +90,6 @@ public class HarParser extends HarAbstractParser {
|
|||
} catch (Exception e) {
|
||||
}
|
||||
|
||||
if (savedUrl.contains(harRequest.url)) {
|
||||
continue;
|
||||
} else {
|
||||
savedUrl.add(harRequest.url);
|
||||
}
|
||||
|
||||
//默认取路径的最后一块
|
||||
String reqName = "";
|
||||
if (harRequest.url != null) {
|
||||
|
|
|
@ -8,22 +8,16 @@ import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
|||
import io.metersphere.api.dto.definition.response.HttpResponse;
|
||||
import io.metersphere.api.dto.parse.postman.PostmanCollection;
|
||||
import io.metersphere.api.dto.parse.postman.PostmanItem;
|
||||
import io.metersphere.api.dto.parse.postman.PostmanKeyValue;
|
||||
import io.metersphere.api.parse.PostmanAbstractParserParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.base.domain.Project;
|
||||
import io.metersphere.base.mapper.ProjectMapper;
|
||||
import io.metersphere.commons.constants.ProjectApplicationType;
|
||||
import io.metersphere.commons.exception.MSException;
|
||||
import io.metersphere.commons.utils.BeanUtils;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.dto.ProjectConfig;
|
||||
import io.metersphere.service.ProjectApplicationService;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
import java.io.InputStream;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefinitionImport> {
|
||||
|
||||
|
@ -42,7 +36,6 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
}
|
||||
}
|
||||
PostmanCollection postmanCollection = JSON.parseObject(testStr, PostmanCollection.class, Feature.DisableSpecialKeyDetect);
|
||||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||
|
||||
|
@ -51,23 +44,15 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
modulePath = "/" + postmanCollection.getInfo().getName();
|
||||
}
|
||||
List<ApiTestCaseWithBLOBs> cases = new ArrayList<>();
|
||||
Map<String, String> repeatMap = new HashMap();
|
||||
ProjectMapper projectMapper = CommonBeanFactory.getBean(ProjectMapper.class);
|
||||
Project project = projectMapper.selectByPrimaryKey(request.getProjectId());
|
||||
ProjectApplicationService projectApplicationService = CommonBeanFactory.getBean(ProjectApplicationService.class);
|
||||
ProjectConfig config = projectApplicationService.getSpecificTypeValue(project.getId(), ProjectApplicationType.URL_REPEATABLE.name());
|
||||
boolean urlRepeat = config.getUrlRepeatable();
|
||||
parseItem(postmanCollection.getItem(), modulePath, variables, results,
|
||||
cases, repeatMap, urlRepeat);
|
||||
Collections.reverse(results); // 调整顺序
|
||||
Collections.reverse(cases);
|
||||
parseItem(postmanCollection.getItem(), modulePath, results,
|
||||
cases);
|
||||
apiImport.setData(results);
|
||||
apiImport.setCases(cases);
|
||||
return apiImport;
|
||||
}
|
||||
|
||||
protected void parseItem(List<PostmanItem> items, String modulePath, List<PostmanKeyValue> variables, List<ApiDefinitionWithBLOBs> results,
|
||||
List<ApiTestCaseWithBLOBs> cases, Map<String, String> repeatMap, Boolean repeatable) {
|
||||
protected void parseItem(List<PostmanItem> items, String modulePath, List<ApiDefinitionWithBLOBs> results,
|
||||
List<ApiTestCaseWithBLOBs> cases) {
|
||||
for (PostmanItem item : items) {
|
||||
List<PostmanItem> childItems = item.getItem();
|
||||
if (childItems != null) {
|
||||
|
@ -75,7 +60,7 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
if (StringUtils.isNotBlank(modulePath) && StringUtils.isNotBlank(item.getName())) {
|
||||
modulePath = modulePath + "/" + item.getName();
|
||||
}
|
||||
parseItem(childItems, modulePath, variables, results, cases, repeatMap, repeatable);
|
||||
parseItem(childItems, modulePath, results, cases);
|
||||
} else {
|
||||
MsHTTPSamplerProxy msHTTPSamplerProxy = parsePostman(item);
|
||||
HttpResponse response = parsePostmanResponse(item);
|
||||
|
@ -89,17 +74,12 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
|||
request.setModulePath(modulePath);
|
||||
}
|
||||
if (request != null) {
|
||||
if (repeatMap.keySet().contains(request.getMethod() + request.getPath())
|
||||
&& (repeatable == null || repeatable == false)) {
|
||||
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
|
||||
BeanUtils.copyBean(apiTestCase, request);
|
||||
apiTestCase.setApiDefinitionId(repeatMap.get(request.getMethod() + request.getPath()));
|
||||
apiTestCase.setPriority("P0");
|
||||
cases.add(apiTestCase);
|
||||
} else {
|
||||
repeatMap.put(request.getMethod() + request.getPath(), request.getId());
|
||||
results.add(request);
|
||||
}
|
||||
results.add(request);
|
||||
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
|
||||
BeanUtils.copyBean(apiTestCase, request);
|
||||
apiTestCase.setApiDefinitionId(request.getId());
|
||||
apiTestCase.setPriority("P0");
|
||||
cases.add(apiTestCase);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -769,6 +769,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
moduleMap.remove(modulePath);
|
||||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||
}
|
||||
moduleDatas.remove(apiDefinitionWithBLOBs);
|
||||
}
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
}
|
||||
|
@ -984,7 +985,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
|||
moduleMap.remove(modulePath);
|
||||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||
}
|
||||
moduleDatas.remove(apiDefinitionWithBLOBs);
|
||||
}
|
||||
|
||||
optionData.remove(apiDefinitionWithBLOBs);
|
||||
}
|
||||
};
|
||||
|
|
|
@ -601,15 +601,15 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
|||
repeatDataMap.forEach((k, v) -> {
|
||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
if (apiScenarioWithBLOBs != null) {
|
||||
String modulePath = apiScenarioWithBLOBs.getModulePath();
|
||||
List<ApiScenarioWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
|
||||
if (moduleDatas != null) {
|
||||
if (moduleDatas.size() <= 1) {
|
||||
moduleMap.remove(modulePath);
|
||||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||
}
|
||||
String modulePath = apiScenarioWithBLOBs.getModulePath();
|
||||
List<ApiScenarioWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
|
||||
if (moduleDatas != null) {
|
||||
if (moduleDatas.size() <= 1) {
|
||||
moduleMap.remove(modulePath);
|
||||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||
}
|
||||
moduleDatas.remove(apiScenarioWithBLOBs);
|
||||
|
||||
}
|
||||
optionData.remove(apiScenarioWithBLOBs);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue