refactor(接口测试): 优化接口导入选择覆盖数据,全部数据被更新的缺陷

This commit is contained in:
wxg0103 2024-05-11 19:32:32 +08:00 committed by 刘瑞斌
parent eae3398f94
commit af684b2b8e
2 changed files with 49 additions and 38 deletions

View File

@ -5,7 +5,6 @@ import io.metersphere.project.constants.PropertyConstant;
import io.metersphere.sdk.constants.ValueEnum; import io.metersphere.sdk.constants.ValueEnum;
import io.metersphere.system.valid.EnumValue; import io.metersphere.system.valid.EnumValue;
import jakarta.validation.Valid; import jakarta.validation.Valid;
import jakarta.validation.constraints.NotBlank;
import lombok.AllArgsConstructor; import lombok.AllArgsConstructor;
import lombok.Data; import lombok.Data;
import lombok.NoArgsConstructor; import lombok.NoArgsConstructor;
@ -29,7 +28,6 @@ public class JsonSchemaItem {
/** /**
* 参数ID * 参数ID
*/ */
@NotBlank
private String id; private String id;
/** /**
* 参数名称 * 参数名称

View File

@ -608,56 +608,69 @@ public class ApiDefinitionImportUtilService {
Body dbbody = dbRequest.getBody(); Body dbbody = dbRequest.getBody();
Body importBody = importRequest.getBody(); Body importBody = importRequest.getBody();
if (dbbody != null && importBody != null) { if (dbbody != null && importBody != null) {
if (!StringUtils.equals(dbbody.getBodyType(), importBody.getBodyType())) {
return false;
}
//判断null类型 //判断null类型
StringUtils.equals(String.valueOf(dbbody.getNoneBody()), String.valueOf(importBody.getNoneBody())); StringUtils.equals(String.valueOf(dbbody.getNoneBody()), String.valueOf(importBody.getNoneBody()));
//判断form类型 //判断form类型
FormDataBody formDataBody = dbbody.getFormDataBody(); if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.FORM_DATA.name())) {
FormDataBody importFormDataBody = importBody.getFormDataBody(); FormDataBody formDataBody = dbbody.getFormDataBody();
if (ObjectUtils.isNotEmpty(formDataBody) || ObjectUtils.isNotEmpty(importFormDataBody)) { FormDataBody importFormDataBody = importBody.getFormDataBody();
List<FormDataKV> formValues = formDataBody.getFormValues(); if (ObjectUtils.isNotEmpty(formDataBody) || ObjectUtils.isNotEmpty(importFormDataBody)) {
List<FormDataKV> importFormValues = importFormDataBody.getFormValues(); List<FormDataKV> formValues = formDataBody.getFormValues();
if (CollectionUtils.isNotEmpty(formValues) || CollectionUtils.isNotEmpty(importFormValues)) { List<FormDataKV> importFormValues = importFormDataBody.getFormValues();
List<String> dbFormKeys = formValues.stream().map(FormDataKV::getKey).toList(); if (CollectionUtils.isNotEmpty(formValues) || CollectionUtils.isNotEmpty(importFormValues)) {
List<String> importFormKeys = importFormValues.stream().map(FormDataKV::getKey).toList(); List<String> dbFormKeys = formValues.stream().map(FormDataKV::getKey).toList();
if (paramsIsSame(dbFormKeys, importFormKeys)) { List<String> importFormKeys = importFormValues.stream().map(FormDataKV::getKey).toList();
return false; if (paramsIsSame(dbFormKeys, importFormKeys)) {
return false;
}
} }
} }
} }
//判读www类型 if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.WWW_FORM.name())) {
WWWFormBody wwwBody = dbbody.getWwwFormBody(); //判读www类型
WWWFormBody importWwwBody = importBody.getWwwFormBody(); WWWFormBody wwwBody = dbbody.getWwwFormBody();
if (ObjectUtils.isNotEmpty(wwwBody) || ObjectUtils.isNotEmpty(importWwwBody)) { WWWFormBody importWwwBody = importBody.getWwwFormBody();
List<WWWFormKV> wwwValues = wwwBody.getFormValues(); if (ObjectUtils.isNotEmpty(wwwBody) || ObjectUtils.isNotEmpty(importWwwBody)) {
List<WWWFormKV> importWwwValues = importWwwBody.getFormValues(); List<WWWFormKV> wwwValues = wwwBody.getFormValues();
if (CollectionUtils.isNotEmpty(wwwValues) || CollectionUtils.isNotEmpty(importWwwValues)) { List<WWWFormKV> importWwwValues = importWwwBody.getFormValues();
List<String> dbWwwKeys = wwwValues.stream().map(WWWFormKV::getKey).toList(); if (CollectionUtils.isNotEmpty(wwwValues) || CollectionUtils.isNotEmpty(importWwwValues)) {
List<String> importWwwKeys = importWwwValues.stream().map(WWWFormKV::getKey).toList(); List<String> dbWwwKeys = wwwValues.stream().map(WWWFormKV::getKey).toList();
if (paramsIsSame(dbWwwKeys, importWwwKeys)) { List<String> importWwwKeys = importWwwValues.stream().map(WWWFormKV::getKey).toList();
return false; if (paramsIsSame(dbWwwKeys, importWwwKeys)) {
return false;
}
} }
} }
} }
//TODO 判断binary类型 //TODO 判断binary类型
//判断raw类型 //判断raw类型
RawBody rawBody = dbbody.getRawBody(); if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.RAW.name())) {
RawBody importRawBody = importBody.getRawBody(); RawBody rawBody = dbbody.getRawBody();
if (ObjectUtils.isNotEmpty(rawBody) || ObjectUtils.isNotEmpty(importRawBody)) { RawBody importRawBody = importBody.getRawBody();
return false; if (ObjectUtils.isNotEmpty(rawBody) || ObjectUtils.isNotEmpty(importRawBody)) {
}
//判断json类型
JsonBody jsonBody = dbbody.getJsonBody();
JsonBody importJsonBody = importBody.getJsonBody();
if (ObjectUtils.isNotEmpty(jsonBody) || ObjectUtils.isNotEmpty(importJsonBody)) {
if (StringUtils.isNotBlank(jsonBody.getJsonValue()) || StringUtils.isNotBlank(importJsonBody.getJsonValue())) {
return false; return false;
} }
//判断jsonschema }
JsonSchemaItem jsonSchema = jsonBody.getJsonSchema(); //判断json类型
JsonSchemaItem importJsonSchema = importJsonBody.getJsonSchema(); if (StringUtils.equals(dbbody.getBodyType(), Body.BodyType.JSON.name())) {
if (jsonSchema != null && importJsonSchema != null) { //判断json类型
return jsonSchemaIsSame(jsonSchema, importJsonSchema); JsonBody jsonBody = dbbody.getJsonBody();
JsonBody importJsonBody = importBody.getJsonBody();
if (ObjectUtils.isNotEmpty(jsonBody) || ObjectUtils.isNotEmpty(importJsonBody)) {
if (!StringUtils.equals(jsonBody.getJsonValue(), importJsonBody.getJsonValue())) {
return false;
}
//判断jsonschema
JsonSchemaItem jsonSchema = jsonBody.getJsonSchema();
JsonSchemaItem importJsonSchema = importJsonBody.getJsonSchema();
if (jsonSchema != null && importJsonSchema != null) {
return jsonSchemaIsSame(jsonSchema, importJsonSchema);
}
} }
} }
} }