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