refactor(接口定义): 提取相同代码
This commit is contained in:
parent
b286d9ce99
commit
20abce6d9b
|
@ -29,7 +29,6 @@ import io.metersphere.base.mapper.ApiScenarioMapper;
|
||||||
import io.metersphere.commons.constants.ElementConstants;
|
import io.metersphere.commons.constants.ElementConstants;
|
||||||
import io.metersphere.commons.constants.PropertyConstant;
|
import io.metersphere.commons.constants.PropertyConstant;
|
||||||
import io.metersphere.commons.constants.StorageConstants;
|
import io.metersphere.commons.constants.StorageConstants;
|
||||||
import io.metersphere.commons.enums.StorageEnums;
|
|
||||||
import io.metersphere.commons.exception.MSException;
|
import io.metersphere.commons.exception.MSException;
|
||||||
import io.metersphere.commons.utils.*;
|
import io.metersphere.commons.utils.*;
|
||||||
import io.metersphere.commons.vo.JDBCProcessorVO;
|
import io.metersphere.commons.vo.JDBCProcessorVO;
|
||||||
|
@ -105,6 +104,12 @@ public class ElementUtil {
|
||||||
list = config.getTransferVariables().stream().filter(ScenarioVariable::isCSVValid).filter(ScenarioVariable::isEnable).collect(Collectors.toList());
|
list = config.getTransferVariables().stream().filter(ScenarioVariable::isCSVValid).filter(ScenarioVariable::isEnable).collect(Collectors.toList());
|
||||||
}
|
}
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
|
addCsv(tree, config, shareMode, list);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addCsv(HashTree tree, ParameterConfig config, String shareMode, List<ScenarioVariable> list) {
|
||||||
FileMetadataService fileMetadataService = CommonBeanFactory.getBean(FileMetadataService.class);
|
FileMetadataService fileMetadataService = CommonBeanFactory.getBean(FileMetadataService.class);
|
||||||
list.forEach(item -> {
|
list.forEach(item -> {
|
||||||
CSVDataSet csvDataSet = new CSVDataSet();
|
CSVDataSet csvDataSet = new CSVDataSet();
|
||||||
|
@ -116,25 +121,27 @@ public class ElementUtil {
|
||||||
if (CollectionUtils.isEmpty(item.getFiles())) {
|
if (CollectionUtils.isEmpty(item.getFiles())) {
|
||||||
MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + ":[ " + Translator.get("csv_no_exist") + " ]");
|
MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + ":[ " + Translator.get("csv_no_exist") + " ]");
|
||||||
} else {
|
} else {
|
||||||
boolean isRef = false;
|
|
||||||
String fileId = null;
|
String fileId = null;
|
||||||
boolean isRepository = false;
|
boolean isRepository = false;
|
||||||
BodyFile file = item.getFiles().get(0);
|
BodyFile file = item.getFiles().get(0);
|
||||||
String path = BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName();
|
boolean isRef = StringUtils.equalsIgnoreCase(file.getStorage(), StorageConstants.FILE_REF.name());
|
||||||
|
String path = StringUtils.join(BODY_FILE_DIR, File.pathSeparator, item.getFiles().get(0).getId(), "_", item.getFiles().get(0).getName());
|
||||||
if (StringUtils.equalsIgnoreCase(file.getStorage(), StorageConstants.FILE_REF.name())) {
|
if (StringUtils.equalsIgnoreCase(file.getStorage(), StorageConstants.FILE_REF.name())) {
|
||||||
isRef = true;
|
|
||||||
fileId = file.getFileId();
|
fileId = file.getFileId();
|
||||||
if (fileMetadataService != null) {
|
|
||||||
FileMetadata fileMetadata = fileMetadataService.getFileMetadataById(fileId);
|
FileMetadata fileMetadata = fileMetadataService.getFileMetadataById(fileId);
|
||||||
if (fileMetadata != null && !StringUtils.equals(fileMetadata.getStorage(), StorageConstants.LOCAL.name())) {
|
if (fileMetadata != null
|
||||||
|
&& !StringUtils.equals(fileMetadata.getStorage(), StorageConstants.LOCAL.name())) {
|
||||||
isRepository = true;
|
isRepository = true;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
path = FileUtils.getFilePath(file);
|
path = FileUtils.getFilePath(file);
|
||||||
}
|
}
|
||||||
if (!config.isOperating() && !isRepository && !new File(path).exists()) {
|
if (!config.isOperating() && !isRepository && !new File(path).exists()) {
|
||||||
|
// 从MinIO下载
|
||||||
|
ApiFileUtil.downloadFile(file.getId(), path);
|
||||||
|
if (!new File(path).exists()) {
|
||||||
MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + ":[ " + Translator.get("csv_no_exist") + " ]");
|
MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + ":[ " + Translator.get("csv_no_exist") + " ]");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
csvDataSet.setProperty(ElementConstants.FILENAME, path);
|
csvDataSet.setProperty(ElementConstants.FILENAME, path);
|
||||||
csvDataSet.setProperty(ElementConstants.IS_REF, isRef);
|
csvDataSet.setProperty(ElementConstants.IS_REF, isRef);
|
||||||
csvDataSet.setProperty(ElementConstants.FILE_ID, fileId);
|
csvDataSet.setProperty(ElementConstants.FILE_ID, fileId);
|
||||||
|
@ -149,53 +156,12 @@ public class ElementUtil {
|
||||||
tree.add(csvDataSet);
|
tree.add(csvDataSet);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void addApiCsvDataSet(HashTree tree, List<ScenarioVariable> variables, ParameterConfig config, String shareMode) {
|
public static void addApiCsvDataSet(HashTree tree, List<ScenarioVariable> variables, ParameterConfig config, String shareMode) {
|
||||||
if (CollectionUtils.isNotEmpty(variables)) {
|
if (CollectionUtils.isNotEmpty(variables)) {
|
||||||
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).filter(ScenarioVariable::isEnable).collect(Collectors.toList());
|
List<ScenarioVariable> list = variables.stream().filter(ScenarioVariable::isCSVValid).filter(ScenarioVariable::isEnable).collect(Collectors.toList());
|
||||||
if (CollectionUtils.isNotEmpty(list)) {
|
if (CollectionUtils.isNotEmpty(list)) {
|
||||||
list.forEach(item -> {
|
addCsv(tree, config, shareMode, list);
|
||||||
CSVDataSet csvDataSet = new CSVDataSet();
|
|
||||||
csvDataSet.setEnabled(true);
|
|
||||||
csvDataSet.setProperty(TestElement.TEST_CLASS, CSVDataSet.class.getName());
|
|
||||||
csvDataSet.setProperty(TestElement.GUI_CLASS, SaveService.aliasToClass(TEST_BEAN_GUI));
|
|
||||||
csvDataSet.setName(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName());
|
|
||||||
csvDataSet.setProperty("fileEncoding", StringUtils.isEmpty(item.getEncoding()) ? StandardCharsets.UTF_8.name() : item.getEncoding());
|
|
||||||
if (CollectionUtils.isEmpty(item.getFiles())) {
|
|
||||||
MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + ":[ " + Translator.get("csv_no_exist") + " ]");
|
|
||||||
} else {
|
|
||||||
BodyFile file = item.getFiles().get(0);
|
|
||||||
String fileId = item.getId();
|
|
||||||
boolean isRef = false;
|
|
||||||
String path;
|
|
||||||
if (StringUtils.equalsIgnoreCase(file.getStorage(), StorageConstants.FILE_REF.name())) {
|
|
||||||
isRef = true;
|
|
||||||
fileId = file.getFileId();
|
|
||||||
path = FileUtils.getFilePath(file);
|
|
||||||
} else {
|
|
||||||
path = BODY_FILE_DIR + "/" + item.getFiles().get(0).getId() + "_" + item.getFiles().get(0).getName();
|
|
||||||
if (StringUtils.equalsIgnoreCase(file.getStorage(), StorageEnums.FILE_REF.name())) {
|
|
||||||
path = ApiFileUtil.getFilePath(file);
|
|
||||||
}
|
|
||||||
if (!config.isOperating() && !new File(path).exists()) {
|
|
||||||
MSException.throwException(StringUtils.isEmpty(item.getName()) ? "CSVDataSet" : item.getName() + ":[ " + Translator.get("csv_no_exist") + " ]");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
csvDataSet.setProperty(ElementConstants.FILENAME, path);
|
|
||||||
csvDataSet.setProperty(ElementConstants.IS_REF, isRef);
|
|
||||||
csvDataSet.setProperty(ElementConstants.FILE_ID, fileId);
|
|
||||||
csvDataSet.setProperty(ElementConstants.RESOURCE_ID, file.getId());
|
|
||||||
}
|
|
||||||
csvDataSet.setIgnoreFirstLine(false);
|
|
||||||
csvDataSet.setProperty("shareMode", shareMode);
|
|
||||||
csvDataSet.setProperty("recycle", true);
|
|
||||||
csvDataSet.setProperty("delimiter", item.getDelimiter());
|
|
||||||
csvDataSet.setProperty("quotedData", item.isQuotedData());
|
|
||||||
csvDataSet.setComment(StringUtils.isEmpty(item.getDescription()) ? "" : item.getDescription());
|
|
||||||
tree.add(csvDataSet);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -554,7 +554,7 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
try {
|
try {
|
||||||
String value = keyValue.getValue() != null && keyValue.getValue().startsWith("@") ?
|
String value = keyValue.getValue() != null && keyValue.getValue().startsWith("@") ?
|
||||||
ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
||||||
value = keyValue.isUrlEncode() ? StringUtils.join(StringUtils.join("${__urlencode(", value), ")}") : value;
|
value = keyValue.isUrlEncode() ? StringUtils.join("${__urlencode(", value, ")}") : value;
|
||||||
keyValueMap.put(keyValue.getName(), value);
|
keyValueMap.put(keyValue.getName(), value);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
LogUtil.error(e);
|
LogUtil.error(e);
|
||||||
|
@ -585,11 +585,11 @@ public class MsHTTPSamplerProxy extends MsTestElement {
|
||||||
stringBuffer.append("?");
|
stringBuffer.append("?");
|
||||||
}
|
}
|
||||||
this.getArguments().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue -> {
|
this.getArguments().stream().filter(KeyValue::isEnable).filter(KeyValue::isValid).forEach(keyValue -> {
|
||||||
stringBuffer.append(keyValue.isUrlEncode() ? StringUtils.join(StringUtils.join("${__urlencode(", keyValue.getName()), ")}") : keyValue.getName());
|
stringBuffer.append(keyValue.isUrlEncode() ? StringUtils.join("${__urlencode(", keyValue.getName(), ")}") : keyValue.getName());
|
||||||
if (keyValue.getValue() != null) {
|
if (keyValue.getValue() != null) {
|
||||||
try {
|
try {
|
||||||
String value = keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
String value = keyValue.getValue().startsWith("@") ? ScriptEngineUtils.buildFunctionCallString(keyValue.getValue()) : keyValue.getValue();
|
||||||
value = keyValue.isUrlEncode() ? StringUtils.join(StringUtils.join("${__urlencode(", value), ")}") : value;
|
value = keyValue.isUrlEncode() ? StringUtils.join("${__urlencode(", value, ")}") : value;
|
||||||
if (StringUtils.isNotEmpty(value) && value.contains(StringUtils.CR)) {
|
if (StringUtils.isNotEmpty(value) && value.contains(StringUtils.CR)) {
|
||||||
value = value.replaceAll(StringUtils.CR, StringUtils.EMPTY);
|
value = value.replaceAll(StringUtils.CR, StringUtils.EMPTY);
|
||||||
}
|
}
|
||||||
|
|
|
@ -99,8 +99,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
httpOld.getHeaders().remove(httpOld.getHeaders().size() - 1);
|
httpOld.getHeaders().remove(httpOld.getHeaders().size() - 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
String headerNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getHeaders())), JSON_END);
|
String headerNew = StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getHeaders()), JSON_END);
|
||||||
String headerOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getHeaders())), JSON_END);
|
String headerOld = StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getHeaders()), JSON_END);
|
||||||
if (!StringUtils.equals(headerNew, headerOld)) {
|
if (!StringUtils.equals(headerNew, headerOld)) {
|
||||||
String patch = jsonDiff.diff(headerOld, headerNew);
|
String patch = jsonDiff.diff(headerOld, headerNew);
|
||||||
String diffPatch = jsonDiff.apply(headerOld, patch);
|
String diffPatch = jsonDiff.apply(headerOld, patch);
|
||||||
|
@ -113,8 +113,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
httpNew.getArguments().remove(httpNew.getArguments().size() - 1);
|
httpNew.getArguments().remove(httpNew.getArguments().size() - 1);
|
||||||
httpOld.getArguments().remove(httpOld.getArguments().size() - 1);
|
httpOld.getArguments().remove(httpOld.getArguments().size() - 1);
|
||||||
}
|
}
|
||||||
String queryNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getArguments())), JSON_END);
|
String queryNew = StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getArguments()), JSON_END);
|
||||||
String queryOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getArguments())), JSON_END);
|
String queryOld = StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getArguments()), JSON_END);
|
||||||
if (!StringUtils.equals(queryNew, queryOld)) {
|
if (!StringUtils.equals(queryNew, queryOld)) {
|
||||||
String patch = jsonDiff.diff(queryOld, queryNew);
|
String patch = jsonDiff.diff(queryOld, queryNew);
|
||||||
String diff = jsonDiff.apply(queryOld, patch);
|
String diff = jsonDiff.apply(queryOld, patch);
|
||||||
|
@ -127,8 +127,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
httpNew.getRest().remove(httpNew.getRest().size() - 1);
|
httpNew.getRest().remove(httpNew.getRest().size() - 1);
|
||||||
httpOld.getRest().remove(httpOld.getRest().size() - 1);
|
httpOld.getRest().remove(httpOld.getRest().size() - 1);
|
||||||
}
|
}
|
||||||
String restNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getRest())), JSON_END);
|
String restNew = StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getRest()), JSON_END);
|
||||||
String restOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getRest())), JSON_END);
|
String restOld = StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getRest()), JSON_END);
|
||||||
if (!StringUtils.equals(restNew, restOld)) {
|
if (!StringUtils.equals(restNew, restOld)) {
|
||||||
String patch = jsonDiff.diff(restOld, restNew);
|
String patch = jsonDiff.diff(restOld, restNew);
|
||||||
String diff = jsonDiff.apply(restOld, patch);
|
String diff = jsonDiff.apply(restOld, patch);
|
||||||
|
@ -152,8 +152,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
httpNew.getBody().getKvs().remove(httpNew.getBody().getKvs().size() - 1);
|
httpNew.getBody().getKvs().remove(httpNew.getBody().getKvs().size() - 1);
|
||||||
httpOld.getBody().getKvs().remove(httpOld.getBody().getKvs().size() - 1);
|
httpOld.getBody().getKvs().remove(httpOld.getBody().getKvs().size() - 1);
|
||||||
}
|
}
|
||||||
String bodyFormNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getBody().getKvs())), JSON_END);
|
String bodyFormNew = StringUtils.join(JSON_START, JSON.toJSONString(httpNew.getBody().getKvs()), JSON_END);
|
||||||
String bodyFormOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getBody().getKvs())), JSON_END);
|
String bodyFormOld = StringUtils.join(JSON_START, JSON.toJSONString(httpOld.getBody().getKvs()), JSON_END);
|
||||||
if (!StringUtils.equals(bodyFormNew, bodyFormOld)) {
|
if (!StringUtils.equals(bodyFormNew, bodyFormOld)) {
|
||||||
String patch = jsonDiff.diff(bodyFormOld, bodyFormNew);
|
String patch = jsonDiff.diff(bodyFormOld, bodyFormNew);
|
||||||
String diff = jsonDiff.apply(bodyFormNew, patch);
|
String diff = jsonDiff.apply(bodyFormNew, patch);
|
||||||
|
@ -197,8 +197,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
private static void diffHttpResponse(JSONObject httpNew, JSONObject httpOld, JsonDiff jsonDiff, Map<String, String> diffMap) {
|
private static void diffHttpResponse(JSONObject httpNew, JSONObject httpOld, JsonDiff jsonDiff, Map<String, String> diffMap) {
|
||||||
// 请求头对比 old/new
|
// 请求头对比 old/new
|
||||||
if (httpNew.get(HEADS) != null && httpOld.get(HEADS) != null) {
|
if (httpNew.get(HEADS) != null && httpOld.get(HEADS) != null) {
|
||||||
String headerNew = StringUtils.join(StringUtils.join(JSON_START, httpNew.get(HEADS).toString()), JSON_END);
|
String headerNew = StringUtils.join(JSON_START, httpNew.get(HEADS).toString(), JSON_END);
|
||||||
String headerOld = StringUtils.join(StringUtils.join(JSON_START, httpOld.get(HEADS).toString()), JSON_END);
|
String headerOld = StringUtils.join(JSON_START, httpOld.get(HEADS).toString(), JSON_END);
|
||||||
if (!StringUtils.equals(headerNew, headerOld)) {
|
if (!StringUtils.equals(headerNew, headerOld)) {
|
||||||
String patch = jsonDiff.diff(headerOld, headerNew);
|
String patch = jsonDiff.diff(headerOld, headerNew);
|
||||||
String diffPatch = jsonDiff.apply(headerNew, patch);
|
String diffPatch = jsonDiff.apply(headerNew, patch);
|
||||||
|
@ -209,8 +209,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
}
|
}
|
||||||
// 对比statusCode参数
|
// 对比statusCode参数
|
||||||
if (httpNew.get(STATUS_CODE) != null && httpOld.get(STATUS_CODE) != null) {
|
if (httpNew.get(STATUS_CODE) != null && httpOld.get(STATUS_CODE) != null) {
|
||||||
String statusCodeNew = StringUtils.join(StringUtils.join(JSON_START, httpNew.get(STATUS_CODE).toString()), JSON_END);
|
String statusCodeNew = StringUtils.join(JSON_START, httpNew.get(STATUS_CODE).toString(), JSON_END);
|
||||||
String statusCodeOld = StringUtils.join(StringUtils.join(JSON_START, httpOld.get(STATUS_CODE).toString()), JSON_END);
|
String statusCodeOld = StringUtils.join(JSON_START, httpOld.get(STATUS_CODE).toString(), JSON_END);
|
||||||
if (!StringUtils.equals(statusCodeNew, statusCodeOld)) {
|
if (!StringUtils.equals(statusCodeNew, statusCodeOld)) {
|
||||||
String patch = jsonDiff.diff(statusCodeOld, statusCodeNew);
|
String patch = jsonDiff.diff(statusCodeOld, statusCodeNew);
|
||||||
String diff = jsonDiff.apply(statusCodeNew, patch);
|
String diff = jsonDiff.apply(statusCodeNew, patch);
|
||||||
|
@ -238,8 +238,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
bodyNew.getKvs().remove(bodyNew.getKvs().size() - 1);
|
bodyNew.getKvs().remove(bodyNew.getKvs().size() - 1);
|
||||||
bodyOld.getKvs().remove(bodyOld.getKvs().size() - 1);
|
bodyOld.getKvs().remove(bodyOld.getKvs().size() - 1);
|
||||||
}
|
}
|
||||||
String bodyFormNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(bodyNew.getKvs())), JSON_END);
|
String bodyFormNew = StringUtils.join(JSON_START, JSON.toJSONString(bodyNew.getKvs()), JSON_END);
|
||||||
String bodyFormOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(bodyOld.getKvs())), JSON_END);
|
String bodyFormOld = StringUtils.join(JSON_START, JSON.toJSONString(bodyOld.getKvs()), JSON_END);
|
||||||
if (!StringUtils.equals(bodyFormNew, bodyFormOld)) {
|
if (!StringUtils.equals(bodyFormNew, bodyFormOld)) {
|
||||||
String patch = jsonDiff.diff(bodyFormOld, bodyFormNew);
|
String patch = jsonDiff.diff(bodyFormOld, bodyFormNew);
|
||||||
String diff = jsonDiff.apply(bodyFormNew, patch);
|
String diff = jsonDiff.apply(bodyFormNew, patch);
|
||||||
|
@ -261,8 +261,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
tcpNew.getParameters().remove(tcpNew.getParameters().size() - 1);
|
tcpNew.getParameters().remove(tcpNew.getParameters().size() - 1);
|
||||||
tcpOld.getParameters().remove(tcpOld.getParameters().size() - 1);
|
tcpOld.getParameters().remove(tcpOld.getParameters().size() - 1);
|
||||||
}
|
}
|
||||||
String queryNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getParameters())), JSON_END);
|
String queryNew = StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getParameters()), JSON_END);
|
||||||
String queryOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getParameters())), JSON_END);
|
String queryOld = StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getParameters()), JSON_END);
|
||||||
if (!StringUtils.equals(queryNew, queryOld)) {
|
if (!StringUtils.equals(queryNew, queryOld)) {
|
||||||
String patch = jsonDiff.diff(queryOld, queryNew);
|
String patch = jsonDiff.diff(queryOld, queryNew);
|
||||||
String diff = jsonDiff.apply(queryNew, patch);
|
String diff = jsonDiff.apply(queryNew, patch);
|
||||||
|
@ -279,8 +279,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// 对比BODY-XML参数
|
// 对比BODY-XML参数
|
||||||
String xmlNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getXmlDataStruct())), JSON_END);
|
String xmlNew = StringUtils.join(JSON_START, JSON.toJSONString(tcpNew.getXmlDataStruct()), JSON_END);
|
||||||
String xmlOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getXmlDataStruct())), JSON_END);
|
String xmlOld = StringUtils.join(JSON_START, JSON.toJSONString(tcpOld.getXmlDataStruct()), JSON_END);
|
||||||
if (!StringUtils.equals(xmlNew, xmlOld)) {
|
if (!StringUtils.equals(xmlNew, xmlOld)) {
|
||||||
diffMap.put(StringUtils.join(BODY_XML, "_1"), JSON.toJSONString(tcpNew.getXmlDataStruct()));
|
diffMap.put(StringUtils.join(BODY_XML, "_1"), JSON.toJSONString(tcpNew.getXmlDataStruct()));
|
||||||
diffMap.put(StringUtils.join(BODY_XML, "_2"), JSON.toJSONString(tcpOld.getXmlDataStruct()));
|
diffMap.put(StringUtils.join(BODY_XML, "_2"), JSON.toJSONString(tcpOld.getXmlDataStruct()));
|
||||||
|
@ -326,8 +326,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
jdbcNew.getVariables().remove(jdbcNew.getVariables().size() - 1);
|
jdbcNew.getVariables().remove(jdbcNew.getVariables().size() - 1);
|
||||||
jdbcOld.getVariables().remove(jdbcOld.getVariables().size() - 1);
|
jdbcOld.getVariables().remove(jdbcOld.getVariables().size() - 1);
|
||||||
}
|
}
|
||||||
String variablesNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(jdbcNew.getVariables())), JSON_END);
|
String variablesNew = StringUtils.join(JSON_START, JSON.toJSONString(jdbcNew.getVariables()), JSON_END);
|
||||||
String variablesOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(jdbcOld.getVariables())), JSON_END);
|
String variablesOld = StringUtils.join(JSON_START, JSON.toJSONString(jdbcOld.getVariables()), JSON_END);
|
||||||
if (!StringUtils.equals(variablesNew, variablesOld)) {
|
if (!StringUtils.equals(variablesNew, variablesOld)) {
|
||||||
String patch = jsonDiff.diff(variablesOld, variablesNew);
|
String patch = jsonDiff.diff(variablesOld, variablesNew);
|
||||||
String diffPatch = jsonDiff.apply(variablesNew, patch);
|
String diffPatch = jsonDiff.apply(variablesNew, patch);
|
||||||
|
@ -367,8 +367,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
dubboNew.getArgs().remove(dubboNew.getArgs().size() - 1);
|
dubboNew.getArgs().remove(dubboNew.getArgs().size() - 1);
|
||||||
dubboOld.getArgs().remove(dubboOld.getArgs().size() - 1);
|
dubboOld.getArgs().remove(dubboOld.getArgs().size() - 1);
|
||||||
}
|
}
|
||||||
String argsNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(dubboNew.getArgs())), JSON_END);
|
String argsNew = StringUtils.join(JSON_START, JSON.toJSONString(dubboNew.getArgs()), JSON_END);
|
||||||
String argsOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(dubboOld.getArgs())), JSON_END);
|
String argsOld = StringUtils.join(JSON_START, JSON.toJSONString(dubboOld.getArgs()), JSON_END);
|
||||||
if (!StringUtils.equals(argsNew, argsOld)) {
|
if (!StringUtils.equals(argsNew, argsOld)) {
|
||||||
String patch = jsonDiff.diff(argsOld, argsNew);
|
String patch = jsonDiff.diff(argsOld, argsNew);
|
||||||
String diffPatch = jsonDiff.apply(argsNew, patch);
|
String diffPatch = jsonDiff.apply(argsNew, patch);
|
||||||
|
@ -381,8 +381,8 @@ public class ApiTestDefinitionDiffUtilImpl implements ApiDefinitionDiffUtil {
|
||||||
dubboNew.getAttachmentArgs().remove(dubboNew.getAttachmentArgs().size() - 1);
|
dubboNew.getAttachmentArgs().remove(dubboNew.getAttachmentArgs().size() - 1);
|
||||||
dubboOld.getAttachmentArgs().remove(dubboOld.getAttachmentArgs().size() - 1);
|
dubboOld.getAttachmentArgs().remove(dubboOld.getAttachmentArgs().size() - 1);
|
||||||
}
|
}
|
||||||
String attachmentNew = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(dubboNew.getAttachmentArgs())), JSON_END);
|
String attachmentNew = StringUtils.join(JSON_START, JSON.toJSONString(dubboNew.getAttachmentArgs()), JSON_END);
|
||||||
String attachmentOld = StringUtils.join(StringUtils.join(JSON_START, JSON.toJSONString(dubboOld.getAttachmentArgs())), JSON_END);
|
String attachmentOld = StringUtils.join(JSON_START, JSON.toJSONString(dubboOld.getAttachmentArgs()), JSON_END);
|
||||||
if (!StringUtils.equals(attachmentNew, attachmentOld)) {
|
if (!StringUtils.equals(attachmentNew, attachmentOld)) {
|
||||||
String patch = jsonDiff.diff(attachmentOld, attachmentNew);
|
String patch = jsonDiff.diff(attachmentOld, attachmentNew);
|
||||||
String diffPatch = jsonDiff.apply(attachmentNew, patch);
|
String diffPatch = jsonDiff.apply(attachmentNew, patch);
|
||||||
|
|
|
@ -174,14 +174,14 @@ public class ReflexObjectUtil {
|
||||||
List<String> originalValueArray = JSON.parseArray(originalValue.toString(), String.class);
|
List<String> originalValueArray = JSON.parseArray(originalValue.toString(), String.class);
|
||||||
Collections.sort(originalValueArray);
|
Collections.sort(originalValueArray);
|
||||||
Object originalObject = JSON.toJSONString(originalValueArray);
|
Object originalObject = JSON.toJSONString(originalValueArray);
|
||||||
oldTags = StringUtils.join(StringUtils.join(JSON_START, ((originalColumns.get(i) != null && originalObject != null) ? originalObject.toString() : "\"\"")), JSON_END);
|
oldTags = StringUtils.join(JSON_START, ((originalColumns.get(i) != null && originalObject != null) ? originalObject.toString() : "\"\""), JSON_END);
|
||||||
}
|
}
|
||||||
List<String> newValueArray = JSON.parseArray(newValue.toString(), String.class);
|
List<String> newValueArray = JSON.parseArray(newValue.toString(), String.class);
|
||||||
if (CollectionUtils.isNotEmpty(newValueArray)) {
|
if (CollectionUtils.isNotEmpty(newValueArray)) {
|
||||||
Collections.sort(newValueArray);
|
Collections.sort(newValueArray);
|
||||||
}
|
}
|
||||||
Object newObject = JSON.toJSONString(newValueArray);
|
Object newObject = JSON.toJSONString(newValueArray);
|
||||||
String newTags = StringUtils.join(StringUtils.join(JSON_START, ((newColumns.get(i) != null && newObject != null) ? newObject.toString() : "\"\"")), JSON_END);
|
String newTags = StringUtils.join(JSON_START, ((newColumns.get(i) != null && newObject != null) ? newObject.toString() : "\"\""), JSON_END);
|
||||||
String diffValue;
|
String diffValue;
|
||||||
if (oldTags != null) {
|
if (oldTags != null) {
|
||||||
String diffStr = diff.diff(oldTags, newTags);
|
String diffStr = diff.diff(oldTags, newTags);
|
||||||
|
|
Loading…
Reference in New Issue