fix(接口测试): 修复postman文件jmeter文件导入时响应体默认值问题

https://www.tapd.cn/55049933/bugtrace/bugs/view/1155049933001018503
--user=郭雨琦
This commit is contained in:
guoyuqi 2022-10-20 17:33:37 +08:00 committed by xiaomeinvG
parent 9ae2923ddd
commit 70644744a4
3 changed files with 17 additions and 3 deletions

View File

@ -4,6 +4,7 @@ package io.metersphere.api.parse;
import io.metersphere.api.dto.ApiTestImportRequest;
import io.metersphere.api.dto.definition.request.MsScenario;
import io.metersphere.api.dto.definition.request.sampler.MsHTTPSamplerProxy;
import io.metersphere.api.dto.definition.response.HttpResponse;
import io.metersphere.api.dto.scenario.Body;
import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.commons.constants.RequestTypeConstants;
@ -220,4 +221,13 @@ public abstract class ApiImportAbstractParser<T> implements ApiImportParser<T> {
scenarioWithBLOBs.setScenarioDefinition(JSON.toJSONString(msScenario));
return scenarioWithBLOBs;
}
public static HttpResponse getDefaultHttpResponse() {
HttpResponse msResponse = new HttpResponse();
msResponse.setHeaders(new ArrayList<>());
msResponse.setType(RequestTypeConstants.HTTP);
msResponse.setBody(new Body());
msResponse.setStatusCode(new ArrayList<>());
return msResponse;
}
}

View File

@ -11,12 +11,12 @@ import io.metersphere.api.dto.scenario.KeyValue;
import io.metersphere.api.parse.postman.*;
import io.metersphere.commons.constants.MsRequestBodyType;
import io.metersphere.commons.constants.PostmanRequestBodyMode;
import io.metersphere.commons.constants.RequestTypeConstants;
import io.metersphere.commons.utils.BeanUtils;
import io.metersphere.commons.utils.JSON;
import io.metersphere.commons.utils.LogUtil;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.List;
@ -61,11 +61,11 @@ public abstract class PostmanAbstractParserParser<T> extends ApiImportAbstractPa
protected HttpResponse parsePostmanResponse(PostmanItem requestItem) {
List<PostmanResponse> requestList = requestItem.getResponse();
if (CollectionUtils.isEmpty(requestList)) {
return new HttpResponse();
return getDefaultHttpResponse();
}
PostmanResponse requestDesc = requestItem.getResponse().get(0);
if (requestDesc == null) {
return null;
return getDefaultHttpResponse();
}
PostmanUrl url = requestDesc.getOriginalRequest().getUrl();
MsHTTPSamplerProxy request = buildRequest(requestItem.getName(), null, null, requestDesc.getJsonSchema());

View File

@ -28,6 +28,7 @@ import io.metersphere.api.dto.definition.request.sampler.dubbo.MsConsumerAndServ
import io.metersphere.api.dto.definition.request.sampler.dubbo.MsRegistryCenter;
import io.metersphere.api.dto.definition.request.timer.MsConstantTimer;
import io.metersphere.api.dto.definition.request.unknown.MsJmeterElement;
import io.metersphere.api.dto.definition.response.HttpResponse;
import io.metersphere.api.dto.scenario.Body;
import io.metersphere.api.dto.scenario.DatabaseConfig;
import io.metersphere.api.dto.scenario.KeyValue;
@ -138,6 +139,8 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
element.getHashTree().clear();
}
apiDefinitionWithBLOBs.setRequest(JSON.toJSONString(element));
HttpResponse defaultHttpResponse = getDefaultHttpResponse();
apiDefinitionWithBLOBs.setResponse(JSON.toJSONString(defaultHttpResponse));
definitions.add(apiDefinitionWithBLOBs);
}
}
@ -344,6 +347,7 @@ public class JmeterDefinitionParser extends ApiImportAbstractParser<ApiDefinitio
return apiDefinition;
}
private HashTree getHashTree(Object scriptWrapper) throws Exception {
Field field = scriptWrapper.getClass().getDeclaredField("testPlan");
field.setAccessible(true);