fix(接口测试): 修复接口场景转性能或导出JMX时获取不到环境里变量配置的问题
--bug=1021644 --user=宋天阳 【接口测试】github#21150,使用接口自动化转化来的场景,获取不到运行环境的环境变量 https://www.tapd.cn/55049933/s/1324158
This commit is contained in:
parent
49d3eb400a
commit
e148a7a84e
|
@ -1463,74 +1463,91 @@ public class ApiDefinitionService {
|
|||
}
|
||||
|
||||
public List<ApiDefinitionWithBLOBs> preparedUrl(String projectId, String method, String baseUrlSuffix, String mockApiResourceId) {
|
||||
|
||||
/*
|
||||
* 获取符合条件的api时,先检查请求头中自带的mockApiResourceId
|
||||
* mockApiResourceId在MsHttpSample拼装的过程中进行添加。初衷是在接口定义调试和接口用例执行时定位到设置了Mock期望的接口。 所以如果请求来源于第三方工具(如Postman等)则不保证该ID的必填性和正确性
|
||||
* 当这个ID能查出数据,则以该api为主。如果查不出来,按照之前匹配URL的方式继续处理。
|
||||
*/
|
||||
List<ApiDefinitionWithBLOBs> specifyData = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(mockApiResourceId)) {
|
||||
//如果请求头中指定了API 则返回当前API
|
||||
List<ApiDefinitionWithBLOBs> returnList = new ArrayList<>();
|
||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionMapper.selectByPrimaryKey(mockApiResourceId);
|
||||
if (apiDefinition != null) {
|
||||
returnList.add(apiDefinition);
|
||||
specifyData.add(apiDefinition);
|
||||
} else {
|
||||
ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(mockApiResourceId);
|
||||
if (testCase != null) {
|
||||
apiDefinition = apiDefinitionMapper.selectByPrimaryKey(testCase.getApiDefinitionId());
|
||||
if (apiDefinition != null) {
|
||||
specifyData.add(apiDefinition);
|
||||
}
|
||||
}
|
||||
}
|
||||
return returnList;
|
||||
} else if (StringUtils.isEmpty(baseUrlSuffix)) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(specifyData)) {
|
||||
return specifyData;
|
||||
} else {
|
||||
String apiId = this.getApiIdFromMockApiResourceId(mockApiResourceId, projectId);
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
ApiDefinitionExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andMethodEqualTo(method).andProjectIdEqualTo(projectId).andStatusNotEqualTo("Trash").andProtocolEqualTo("HTTP").andLatestEqualTo(true);
|
||||
if (StringUtils.isNotBlank(apiId)) {
|
||||
criteria.andIdEqualTo(apiId);
|
||||
}
|
||||
List<ApiDefinition> apiList = apiDefinitionMapper.selectByExample(example);
|
||||
List<String> apiIdList = new ArrayList<>();
|
||||
boolean urlSuffixEndEmpty = false;
|
||||
String urlSuffix = baseUrlSuffix;
|
||||
if (urlSuffix.endsWith("/")) {
|
||||
urlSuffixEndEmpty = true;
|
||||
urlSuffix = urlSuffix + "testMock";
|
||||
}
|
||||
String[] urlParams = urlSuffix.split("/");
|
||||
if (urlSuffixEndEmpty) {
|
||||
urlParams[urlParams.length - 1] = StringUtils.EMPTY;
|
||||
}
|
||||
for (ApiDefinition api : apiList) {
|
||||
if (StringUtils.equalsAny(api.getPath(), baseUrlSuffix, "/" + baseUrlSuffix)) {
|
||||
apiIdList.add(api.getId());
|
||||
} else {
|
||||
String path = api.getPath();
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
continue;
|
||||
}
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(path)) {
|
||||
String[] pathArr = path.split("/");
|
||||
if (pathArr.length == urlParams.length) {
|
||||
boolean isFetch = true;
|
||||
for (int i = 0; i < urlParams.length; i++) {
|
||||
String pathItem = pathArr[i];
|
||||
if (!(pathItem.startsWith("{") && pathItem.endsWith("}"))) {
|
||||
if (!StringUtils.equals(pathArr[i], urlParams[i])) {
|
||||
isFetch = false;
|
||||
break;
|
||||
if (StringUtils.isEmpty(baseUrlSuffix)) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
String apiId = this.getApiIdFromMockApiResourceId(mockApiResourceId, projectId);
|
||||
ApiDefinitionExample example = new ApiDefinitionExample();
|
||||
ApiDefinitionExample.Criteria criteria = example.createCriteria();
|
||||
criteria.andMethodEqualTo(method).andProjectIdEqualTo(projectId).andStatusNotEqualTo("Trash").andProtocolEqualTo("HTTP").andLatestEqualTo(true);
|
||||
if (StringUtils.isNotBlank(apiId)) {
|
||||
criteria.andIdEqualTo(apiId);
|
||||
}
|
||||
List<ApiDefinition> apiList = apiDefinitionMapper.selectByExample(example);
|
||||
List<String> apiIdList = new ArrayList<>();
|
||||
boolean urlSuffixEndEmpty = false;
|
||||
String urlSuffix = baseUrlSuffix;
|
||||
if (urlSuffix.endsWith("/")) {
|
||||
urlSuffixEndEmpty = true;
|
||||
urlSuffix = urlSuffix + "testMock";
|
||||
}
|
||||
String[] urlParams = urlSuffix.split("/");
|
||||
if (urlSuffixEndEmpty) {
|
||||
urlParams[urlParams.length - 1] = StringUtils.EMPTY;
|
||||
}
|
||||
for (ApiDefinition api : apiList) {
|
||||
if (StringUtils.equalsAny(api.getPath(), baseUrlSuffix, "/" + baseUrlSuffix)) {
|
||||
apiIdList.add(api.getId());
|
||||
} else {
|
||||
String path = api.getPath();
|
||||
if (StringUtils.isEmpty(path)) {
|
||||
continue;
|
||||
}
|
||||
if (path.startsWith("/")) {
|
||||
path = path.substring(1);
|
||||
}
|
||||
if (StringUtils.isNotEmpty(path)) {
|
||||
String[] pathArr = path.split("/");
|
||||
if (pathArr.length == urlParams.length) {
|
||||
boolean isFetch = true;
|
||||
for (int i = 0; i < urlParams.length; i++) {
|
||||
String pathItem = pathArr[i];
|
||||
if (!(pathItem.startsWith("{") && pathItem.endsWith("}"))) {
|
||||
if (!StringUtils.equals(pathArr[i], urlParams[i])) {
|
||||
isFetch = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
if (isFetch) {
|
||||
apiIdList.add(api.getId());
|
||||
}
|
||||
if (isFetch) {
|
||||
apiIdList.add(api.getId());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (apiIdList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
example.clear();
|
||||
example.createCriteria().andIdIn(apiIdList);
|
||||
return apiDefinitionMapper.selectByExampleWithBLOBs(example);
|
||||
if (apiIdList.isEmpty()) {
|
||||
return new ArrayList<>();
|
||||
} else {
|
||||
example.clear();
|
||||
example.createCriteria().andIdIn(apiIdList);
|
||||
return apiDefinitionMapper.selectByExampleWithBLOBs(example);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -861,6 +861,7 @@ public class ApiScenarioService {
|
|||
ParameterConfig config = new ParameterConfig();
|
||||
config.setOperating(true);
|
||||
config.getExcludeScenarioIds().add(apiScenario.getId());
|
||||
config.setScenarioId(apiScenario.getId());
|
||||
try {
|
||||
MsScenario scenario = JSON.parseObject(apiScenario.getScenarioDefinition(), MsScenario.class);
|
||||
if (scenario == null) {
|
||||
|
|
|
@ -354,9 +354,6 @@ export default {
|
|||
},
|
||||
enableTrash() {
|
||||
this.condition.trashEnable = true;
|
||||
this.$nextTick(() => {
|
||||
this.$emit('enableTrash', this.condition.trashEnable);
|
||||
});
|
||||
},
|
||||
removeModuleId(nodeIds) {
|
||||
if (localStorage.getItem('scenarioModule') && localStorage.getItem('scenarioModule') === nodeIds[0]) {
|
||||
|
|
Loading…
Reference in New Issue