fix(接口测试): 接口导入问题
--user=郭雨琦 --bug=1011903 接口导入数据调整,接口自动化导入数据调整 https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001011903
This commit is contained in:
parent
afc2e87c3c
commit
7ecc2b313b
|
@ -1,10 +1,13 @@
|
|||
package io.metersphere.api.dto.automation.parse;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONArray;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import io.metersphere.api.dto.automation.ApiScenarioModuleDTO;
|
||||
import io.metersphere.api.dto.definition.ApiDefinitionResult;
|
||||
import io.metersphere.api.dto.definition.parse.ms.NodeTree;
|
||||
import io.metersphere.api.dto.definition.response.HttpResponse;
|
||||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.api.service.ApiDefinitionService;
|
||||
import io.metersphere.api.service.ApiScenarioModuleService;
|
||||
import io.metersphere.api.service.ApiTestCaseService;
|
||||
|
@ -180,7 +183,15 @@ public class ApiScenarioImportUtil {
|
|||
test.setId(id);
|
||||
test.setNum(apiDefinitionService.getNextNum(projectId)+i);
|
||||
test.setName(object.getString("name"));
|
||||
test.setPath(object.getString("path"));
|
||||
if(StringUtils.isBlank(object.getString("path"))){
|
||||
if(StringUtils.isNotBlank(object.getString("url"))){
|
||||
ApiImportAbstractParser apiImportAbstractParser = CommonBeanFactory.getBean(ApiImportAbstractParser.class);
|
||||
String path = apiImportAbstractParser.formatPath(object.getString("url"));
|
||||
test.setPath(path);
|
||||
}
|
||||
}else{
|
||||
test.setPath(object.getString("path"));
|
||||
}
|
||||
test.setCreateUser(SessionUtils.getUserId());
|
||||
test.setProjectId(projectId);
|
||||
test.setCreateTime(System.currentTimeMillis());
|
||||
|
@ -193,20 +204,12 @@ public class ApiScenarioImportUtil {
|
|||
object.put("resourceId", test.getId());
|
||||
object.put("projectId", projectId);
|
||||
object.put("useEnvironment","");
|
||||
object.put("url","");
|
||||
JSONObject objectNew = JSONObject.parseObject(object.toJSONString());
|
||||
objectNew.remove("refType");
|
||||
objectNew.remove("referenced");
|
||||
test.setRequest(objectNew.toJSONString());
|
||||
JSONObject obj = new JSONObject();
|
||||
obj.put("type", object.get("protocol"));
|
||||
obj.put("body", object.get("body"));
|
||||
obj.put("headers", object.get("headers"));
|
||||
Map<String, Boolean>map = new HashMap<>();
|
||||
map.put("enable", true);
|
||||
List<Map<String, Boolean>> list = new ArrayList<>();
|
||||
list.add(map);
|
||||
obj.put("statusCode",list);
|
||||
test.setResponse(obj.toJSONString());
|
||||
test.setResponse(JSON.toJSONString(new HttpResponse()));
|
||||
test.setUserId(SessionUtils.getUserId());
|
||||
test.setLatest(true);
|
||||
test.setOrder(apiDefinitionService.getImportNextOrder(projectId));
|
||||
|
|
|
@ -7,11 +7,13 @@ import io.metersphere.api.dto.ApiTestImportRequest;
|
|||
import io.metersphere.api.dto.definition.parse.ms.NodeTree;
|
||||
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
|
||||
import io.metersphere.api.dto.scenario.request.RequestType;
|
||||
import io.metersphere.api.parse.ApiImportAbstractParser;
|
||||
import io.metersphere.api.parse.MsAbstractParser;
|
||||
import io.metersphere.base.domain.ApiDefinitionWithBLOBs;
|
||||
import io.metersphere.base.domain.ApiModule;
|
||||
import io.metersphere.base.domain.ApiTestCaseWithBLOBs;
|
||||
import io.metersphere.commons.constants.ApiImportPlatform;
|
||||
import io.metersphere.commons.utils.CommonBeanFactory;
|
||||
import io.metersphere.commons.utils.SessionUtils;
|
||||
import org.apache.commons.collections.CollectionUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
@ -123,6 +125,14 @@ public class MsDefinitionParser extends MsAbstractParser<ApiDefinitionImport> {
|
|||
if(requestObj.get("projectId")!=null){
|
||||
requestObj.put("projectId", apiDefinition.getProjectId());
|
||||
}
|
||||
if(StringUtils.isBlank(requestObj.getString("path"))){
|
||||
if(StringUtils.isNotBlank(requestObj.getString("url"))){
|
||||
ApiImportAbstractParser apiImportAbstractParser = CommonBeanFactory.getBean(ApiImportAbstractParser.class);
|
||||
String path = apiImportAbstractParser.formatPath(requestObj.getString("url"));
|
||||
requestObj.put("path",path);
|
||||
}
|
||||
}
|
||||
requestObj.put("url","");
|
||||
apiDefinition.setRequest(JSONObject.toJSONString(requestObj));
|
||||
apiDefinition.setCreateUser(SessionUtils.getUserId());
|
||||
apiDefinition.setUserId(SessionUtils.getUserId());
|
||||
|
|
|
@ -135,7 +135,7 @@ public abstract class ApiImportAbstractParser<T> implements ApiImportParser<T> {
|
|||
return apiDefinition;
|
||||
}
|
||||
|
||||
private String formatPath(String url) {
|
||||
public String formatPath(String url) {
|
||||
try {
|
||||
URL urlObject = new URL(url);
|
||||
String path = StringUtils.isBlank(urlObject.getPath()) ? "/" : urlObject.getPath();
|
||||
|
|
Loading…
Reference in New Issue