refactor(接口测试): 场景导入接口兼容历史数据
--bug=1027894 --user=王孝刚 【接口测试】场景详情-UI列表导入-切换项目-选择模块-选择所有数据-复制报500 https://www.tapd.cn/55049933/s/1394138
This commit is contained in:
parent
ae83bc1675
commit
b4bf0c6e63
|
@ -180,6 +180,12 @@ public class ApiDefinitionService {
|
|||
public static final String ARGUMENTS = "arguments";
|
||||
public static final String BODY = "body";
|
||||
private static final String SCHEDULE = "schedule";
|
||||
public static final String TYPE = "type";
|
||||
public static final String HTTP = "HTTPSamplerProxy";
|
||||
public static final String CLAZZ = "className";
|
||||
public static final String FORMAT = "format";
|
||||
public static final String RAW = "raw";
|
||||
public static final String JSONSCHEMA = "jsonSchema";
|
||||
|
||||
|
||||
public List<ApiDefinitionResult> list(ApiDefinitionRequest request) {
|
||||
|
@ -330,19 +336,21 @@ public class ApiDefinitionService {
|
|||
}
|
||||
List<ApiDefinitionResult> resList = extApiDefinitionMapper.listByIds(request.getIds());
|
||||
resList.forEach(item -> {
|
||||
MsTestElement msTestElement = JSONUtil.parseObject(item.getRequest(), MsTestElement.class);
|
||||
if (msTestElement instanceof MsHTTPSamplerProxy) {
|
||||
MsHTTPSamplerProxy requestBody = (MsHTTPSamplerProxy) msTestElement;
|
||||
Body body = requestBody.getBody();
|
||||
if (StringUtils.isNotBlank(body.getType()) && StringUtils.equals(body.getType(), Body.JSON_STR)) {
|
||||
if (StringUtils.isNotEmpty(body.getFormat()) && body.getJsonSchema() != null && Body.JSON_SCHEMA.equals(body.getFormat())) {
|
||||
body.setRaw(JSONSchemaParser.preview(JSONUtil.toJSONString(body.getJsonSchema())));
|
||||
JSONObject jsonObject = JSONUtil.parseObject(item.getRequest());
|
||||
if (jsonObject != null && jsonObject.has(TYPE) && jsonObject.optString(TYPE).equals(HTTP)) {
|
||||
jsonObject.put(CLAZZ, MsHTTPSamplerProxy.class.getCanonicalName());
|
||||
JSONObject body = jsonObject.optJSONObject(BODY);
|
||||
if (StringUtils.isNotBlank(body.optString(TYPE))
|
||||
&& StringUtils.equals(body.optString(TYPE), Body.JSON_STR)
|
||||
&& StringUtils.isNotEmpty(body.optString(FORMAT))
|
||||
&& body.optJSONObject(JSONSCHEMA) != null
|
||||
&& Body.JSON_SCHEMA.equals(body.optString(FORMAT))) {
|
||||
body.put(RAW, JSONSchemaParser.preview(body.optString(JSONSCHEMA)));
|
||||
jsonObject.put(BODY, body);
|
||||
}
|
||||
item.setRequest(jsonObject.toString());
|
||||
}
|
||||
item.setRequest(JSONUtil.toJSONString(requestBody));
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
// 排序
|
||||
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
||||
fixedOrderComparator.setUnknownObjectBehavior(FixedOrderComparator.UnknownObjectBehavior.BEFORE);
|
||||
|
@ -1563,9 +1571,12 @@ public class ApiDefinitionService {
|
|||
*/
|
||||
List<ApiDefinitionWithBLOBs> specifyData = new ArrayList<>();
|
||||
if (StringUtils.isNotBlank(mockApiResourceId)) {
|
||||
ApiDefinitionWithBLOBs apiDefinition = apiDefinitionMapper.selectByPrimaryKey(mockApiResourceId);
|
||||
if (apiDefinition != null) {
|
||||
specifyData.add(apiDefinition);
|
||||
ApiDefinitionExample apiDefinitionExample = new ApiDefinitionExample();
|
||||
apiDefinitionExample.createCriteria().andIdEqualTo(mockApiResourceId).andStatusNotEqualTo("Trash");
|
||||
List<ApiDefinitionWithBLOBs> apiDefinitions = apiDefinitionMapper.selectByExampleWithBLOBs(apiDefinitionExample);
|
||||
ApiDefinitionWithBLOBs apiDefinition;
|
||||
if (CollectionUtils.isNotEmpty(apiDefinitions)) {
|
||||
specifyData.add(apiDefinitions.get(0));
|
||||
} else {
|
||||
ApiTestCase testCase = apiTestCaseMapper.selectByPrimaryKey(mockApiResourceId);
|
||||
if (testCase != null) {
|
||||
|
|
|
@ -851,19 +851,21 @@ public class ApiTestCaseService {
|
|||
} else {
|
||||
list = extApiTestCaseMapper.getCaseInfo(request);
|
||||
list.forEach(item -> {
|
||||
MsTestElement msTestElement = JSONUtil.parseObject(item.getRequest(), MsTestElement.class);
|
||||
if (msTestElement instanceof MsHTTPSamplerProxy) {
|
||||
MsHTTPSamplerProxy requestBody = (MsHTTPSamplerProxy) JSONUtil.parseObject(item.getRequest(), MsTestElement.class);
|
||||
Body body = requestBody.getBody();
|
||||
if (StringUtils.isNotBlank(body.getType()) && StringUtils.equals(body.getType(), Body.JSON_STR)) {
|
||||
if (StringUtils.isNotEmpty(body.getFormat()) && body.getJsonSchema() != null && Body.JSON_SCHEMA.equals(body.getFormat())) {
|
||||
body.setRaw(JSONSchemaParser.preview(JSONUtil.toJSONString(body.getJsonSchema())));
|
||||
JSONObject jsonObject = JSONUtil.parseObject(item.getRequest());
|
||||
if (jsonObject != null && jsonObject.has(ApiDefinitionService.TYPE) && jsonObject.optString(ApiDefinitionService.TYPE).equals(ApiDefinitionService.HTTP)) {
|
||||
jsonObject.put(ApiDefinitionService.CLAZZ, MsHTTPSamplerProxy.class.getCanonicalName());
|
||||
JSONObject body = jsonObject.optJSONObject(ApiDefinitionService.BODY);
|
||||
if (StringUtils.isNotBlank(body.optString(ApiDefinitionService.TYPE))
|
||||
&& StringUtils.equals(body.optString(ApiDefinitionService.TYPE), Body.JSON_STR)
|
||||
&& StringUtils.isNotEmpty(body.optString(ApiDefinitionService.FORMAT))
|
||||
&& body.optJSONObject(ApiDefinitionService.JSONSCHEMA) != null
|
||||
&& Body.JSON_SCHEMA.equals(body.optString(ApiDefinitionService.FORMAT))) {
|
||||
body.put(ApiDefinitionService.RAW, JSONSchemaParser.preview(body.optString(ApiDefinitionService.JSONSCHEMA)));
|
||||
jsonObject.put(ApiDefinitionService.BODY, body);
|
||||
}
|
||||
item.setRequest(jsonObject.toString());
|
||||
}
|
||||
item.setRequest(JSONUtil.toJSONString(requestBody));
|
||||
}
|
||||
}
|
||||
);
|
||||
});
|
||||
}
|
||||
// 排序
|
||||
FixedOrderComparator<String> fixedOrderComparator = new FixedOrderComparator<String>(request.getIds());
|
||||
|
|
Loading…
Reference in New Issue