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;
|
harEntryList = har.log.entries;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<String> savedUrl = new ArrayList<>();
|
|
||||||
|
|
||||||
for (HarEntry entry : harEntryList) {
|
for (HarEntry entry : harEntryList) {
|
||||||
HarRequest harRequest = entry.request;
|
HarRequest harRequest = entry.request;
|
||||||
|
@ -91,12 +90,6 @@ public class HarParser extends HarAbstractParser {
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (savedUrl.contains(harRequest.url)) {
|
|
||||||
continue;
|
|
||||||
} else {
|
|
||||||
savedUrl.add(harRequest.url);
|
|
||||||
}
|
|
||||||
|
|
||||||
//默认取路径的最后一块
|
//默认取路径的最后一块
|
||||||
String reqName = "";
|
String reqName = "";
|
||||||
if (harRequest.url != null) {
|
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.definition.response.HttpResponse;
|
||||||
import io.metersphere.api.dto.parse.postman.PostmanCollection;
|
import io.metersphere.api.dto.parse.postman.PostmanCollection;
|
||||||
import io.metersphere.api.dto.parse.postman.PostmanItem;
|
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.api.parse.PostmanAbstractParserParser;
|
||||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
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.exception.MSException;
|
||||||
import io.metersphere.commons.utils.BeanUtils;
|
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 org.apache.commons.lang3.StringUtils;
|
||||||
|
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefinitionImport> {
|
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);
|
PostmanCollection postmanCollection = JSON.parseObject(testStr, PostmanCollection.class, Feature.DisableSpecialKeyDetect);
|
||||||
List<PostmanKeyValue> variables = postmanCollection.getVariable();
|
|
||||||
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
ApiDefinitionImport apiImport = new ApiDefinitionImport();
|
||||||
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
List<ApiDefinitionWithBLOBs> results = new ArrayList<>();
|
||||||
|
|
||||||
|
@ -51,23 +44,15 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
||||||
modulePath = "/" + postmanCollection.getInfo().getName();
|
modulePath = "/" + postmanCollection.getInfo().getName();
|
||||||
}
|
}
|
||||||
List<ApiTestCaseWithBLOBs> cases = new ArrayList<>();
|
List<ApiTestCaseWithBLOBs> cases = new ArrayList<>();
|
||||||
Map<String, String> repeatMap = new HashMap();
|
parseItem(postmanCollection.getItem(), modulePath, results,
|
||||||
ProjectMapper projectMapper = CommonBeanFactory.getBean(ProjectMapper.class);
|
cases);
|
||||||
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);
|
|
||||||
apiImport.setData(results);
|
apiImport.setData(results);
|
||||||
apiImport.setCases(cases);
|
apiImport.setCases(cases);
|
||||||
return apiImport;
|
return apiImport;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void parseItem(List<PostmanItem> items, String modulePath, List<PostmanKeyValue> variables, List<ApiDefinitionWithBLOBs> results,
|
protected void parseItem(List<PostmanItem> items, String modulePath, List<ApiDefinitionWithBLOBs> results,
|
||||||
List<ApiTestCaseWithBLOBs> cases, Map<String, String> repeatMap, Boolean repeatable) {
|
List<ApiTestCaseWithBLOBs> cases) {
|
||||||
for (PostmanItem item : items) {
|
for (PostmanItem item : items) {
|
||||||
List<PostmanItem> childItems = item.getItem();
|
List<PostmanItem> childItems = item.getItem();
|
||||||
if (childItems != null) {
|
if (childItems != null) {
|
||||||
|
@ -75,7 +60,7 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
||||||
if (StringUtils.isNotBlank(modulePath) && StringUtils.isNotBlank(item.getName())) {
|
if (StringUtils.isNotBlank(modulePath) && StringUtils.isNotBlank(item.getName())) {
|
||||||
modulePath = modulePath + "/" + item.getName();
|
modulePath = modulePath + "/" + item.getName();
|
||||||
}
|
}
|
||||||
parseItem(childItems, modulePath, variables, results, cases, repeatMap, repeatable);
|
parseItem(childItems, modulePath, results, cases);
|
||||||
} else {
|
} else {
|
||||||
MsHTTPSamplerProxy msHTTPSamplerProxy = parsePostman(item);
|
MsHTTPSamplerProxy msHTTPSamplerProxy = parsePostman(item);
|
||||||
HttpResponse response = parsePostmanResponse(item);
|
HttpResponse response = parsePostmanResponse(item);
|
||||||
|
@ -89,17 +74,12 @@ public class PostmanDefinitionParser extends PostmanAbstractParserParser<ApiDefi
|
||||||
request.setModulePath(modulePath);
|
request.setModulePath(modulePath);
|
||||||
}
|
}
|
||||||
if (request != null) {
|
if (request != null) {
|
||||||
if (repeatMap.keySet().contains(request.getMethod() + request.getPath())
|
results.add(request);
|
||||||
&& (repeatable == null || repeatable == false)) {
|
|
||||||
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
|
ApiTestCaseWithBLOBs apiTestCase = new ApiTestCaseWithBLOBs();
|
||||||
BeanUtils.copyBean(apiTestCase, request);
|
BeanUtils.copyBean(apiTestCase, request);
|
||||||
apiTestCase.setApiDefinitionId(repeatMap.get(request.getMethod() + request.getPath()));
|
apiTestCase.setApiDefinitionId(request.getId());
|
||||||
apiTestCase.setPriority("P0");
|
apiTestCase.setPriority("P0");
|
||||||
cases.add(apiTestCase);
|
cases.add(apiTestCase);
|
||||||
} else {
|
|
||||||
repeatMap.put(request.getMethod() + request.getPath(), request.getId());
|
|
||||||
results.add(request);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -769,6 +769,7 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
moduleMap.remove(modulePath);
|
moduleMap.remove(modulePath);
|
||||||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||||
}
|
}
|
||||||
|
moduleDatas.remove(apiDefinitionWithBLOBs);
|
||||||
}
|
}
|
||||||
optionData.remove(apiDefinitionWithBLOBs);
|
optionData.remove(apiDefinitionWithBLOBs);
|
||||||
}
|
}
|
||||||
|
@ -984,7 +985,9 @@ public class ApiModuleService extends NodeTreeService<ApiModuleDTO> {
|
||||||
moduleMap.remove(modulePath);
|
moduleMap.remove(modulePath);
|
||||||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||||
}
|
}
|
||||||
|
moduleDatas.remove(apiDefinitionWithBLOBs);
|
||||||
}
|
}
|
||||||
|
|
||||||
optionData.remove(apiDefinitionWithBLOBs);
|
optionData.remove(apiDefinitionWithBLOBs);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -600,7 +600,6 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
Map<String, List<ApiScenarioWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiScenario::getModulePath));
|
Map<String, List<ApiScenarioWithBLOBs>> moduleOptionData = optionData.stream().collect(Collectors.groupingBy(ApiScenario::getModulePath));
|
||||||
repeatDataMap.forEach((k, v) -> {
|
repeatDataMap.forEach((k, v) -> {
|
||||||
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
|
ApiScenarioWithBLOBs apiScenarioWithBLOBs = nameModuleMap.get(k);
|
||||||
if (apiScenarioWithBLOBs != null) {
|
|
||||||
if (apiScenarioWithBLOBs != null) {
|
if (apiScenarioWithBLOBs != null) {
|
||||||
String modulePath = apiScenarioWithBLOBs.getModulePath();
|
String modulePath = apiScenarioWithBLOBs.getModulePath();
|
||||||
List<ApiScenarioWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
|
List<ApiScenarioWithBLOBs> moduleDatas = moduleOptionData.get(modulePath);
|
||||||
|
@ -609,7 +608,8 @@ public class ApiScenarioModuleService extends NodeTreeService<ApiScenarioModuleD
|
||||||
moduleMap.remove(modulePath);
|
moduleMap.remove(modulePath);
|
||||||
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
removeModulePath(moduleMap, moduleOptionData, modulePath);
|
||||||
}
|
}
|
||||||
}
|
moduleDatas.remove(apiScenarioWithBLOBs);
|
||||||
|
|
||||||
}
|
}
|
||||||
optionData.remove(apiScenarioWithBLOBs);
|
optionData.remove(apiScenarioWithBLOBs);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue