From e8527950271a6254f6070e02f409f560b0b1a80d Mon Sep 17 00:00:00 2001 From: wxg0103 <727495428@qq.com> Date: Tue, 6 Feb 2024 10:01:15 +0800 Subject: [PATCH] =?UTF-8?q?refactor(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E5=A2=9E=E5=8A=A0=E6=96=87=E6=A1=A3=E6=96=AD=E8=A8=80?= =?UTF-8?q?=E8=A7=A3=E6=9E=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../api/parser/api/Swagger3Parser.java | 2 +- .../body/DocumentAssertionConverter.java | 155 +++++++++++++++++- .../ApiDefinitionImportUtilService.java | 16 +- .../controller/ApiDebugControllerTests.java | 18 +- .../api/controller/MsHTTPElementTest.java | 125 +++++++++++++- .../project/api/assertion/body/Condition.java | 18 ++ .../api/assertion/body/ElementCondition.java | 22 +++ .../assertion/body/MsDocumentAssertion.java | 7 +- .../body/MsDocumentAssertionElement.java | 8 +- .../project}/constants/PropertyConstant.java | 6 +- pom.xml | 2 +- 11 files changed, 347 insertions(+), 32 deletions(-) create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java create mode 100644 backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java rename backend/services/{api-test/src/main/java/io/metersphere/api => project-management/src/main/java/io/metersphere/project}/constants/PropertyConstant.java (63%) diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java index 08b58974bd..1c4a744faa 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/api/Swagger3Parser.java @@ -9,7 +9,7 @@ import io.metersphere.api.dto.request.http.*; import io.metersphere.api.dto.request.http.auth.NoAuth; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.schema.JsonSchemaItem; -import io.metersphere.api.constants.PropertyConstant; +import io.metersphere.project.constants.PropertyConstant; import io.metersphere.api.parser.ImportParser; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.sdk.exception.MSException; diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java index aabd1070fc..153d555847 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/parser/jmeter/processor/assertion/body/DocumentAssertionConverter.java @@ -1,27 +1,166 @@ package io.metersphere.api.parser.jmeter.processor.assertion.body; -import io.metersphere.project.api.assertion.body.MsDocumentAssertion; +import io.metersphere.assertions.JSONPathAssertion; +import io.metersphere.assertions.XMLAssertion; import io.metersphere.plugin.api.dto.ParameterConfig; +import io.metersphere.project.api.assertion.body.Condition; +import io.metersphere.project.api.assertion.body.ElementCondition; +import io.metersphere.project.api.assertion.body.MsDocumentAssertion; +import io.metersphere.project.api.assertion.body.MsDocumentAssertionElement; +import io.metersphere.project.constants.PropertyConstant; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.BooleanUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.jmeter.testelement.TestElement; import org.apache.jorphan.collections.HashTree; +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; + /** * @Author: jianxing * @CreateTime: 2024-01-03 10:05 */ public class DocumentAssertionConverter extends ResponseBodyTypeAssertionConverter { + + @Override public void parse(HashTree hashTree, MsDocumentAssertion msAssertion, ParameterConfig config, boolean isIgnoreStatus, boolean globalEnable) { if (msAssertion == null) { return; } // todo 定义好 jsonschema 再补充 -// String documentType = msAssertion.getDocumentType(); -// MsDocumentAssertionElement documentAssertionElement; -// if (StringUtils.equals(documentType, MsDocumentAssertion.DocumentType.XML.name())) { -// documentAssertionElement = msAssertion.getXmlAssertion(); -// } else { -// documentAssertionElement = msAssertion.getJsonAssertion(); -// } + if (needParse(msAssertion, config)) { + String documentType = msAssertion.getDocumentType(); + if (StringUtils.equals(documentType, MsDocumentAssertion.DocumentType.XML.name())) { + hashTree.add(parseAssertion(msAssertion.getXmlAssertion(), globalEnable, new XMLAssertion())); + } else { + hashTree.add(parseAssertion(msAssertion.getJsonAssertion(), globalEnable, new JSONPathAssertion())); + } + } + + } + + private List parseAssertion(MsDocumentAssertionElement assertion, boolean globalEnable, T t) { + + List list = new LinkedList<>(); + Map conditionMap = new java.util.HashMap<>(); + List dataList = new ArrayList<>(); + dataList.add(assertion); + conditions(dataList, conditionMap); + formatting(dataList, list, null, conditionMap, globalEnable, t); + return list; + } + + private void conditions(List dataList, Map conditionMap) { + dataList.forEach(item -> { + ElementCondition elementCondition = new ElementCondition(item.getInclude(), item.getTypeVerification(), item.getArrayVerification(), new LinkedList() {{ + this.add(new Condition(item.getCondition(), item.getExpectedResult())); + }}); + elementCondition.setType(item.getType()); + conditionMap.put(item.getId(), elementCondition); + + if (CollectionUtils.isNotEmpty(item.getChildren())) { + conditions(item.getChildren(), conditionMap); + } + }); + } + + public void formatting(List dataList, + List list, + MsDocumentAssertionElement parentNode, + Map conditionMap, + boolean globalEnable, + T t) { + for (int i = 0; i < dataList.size(); i++) { + MsDocumentAssertionElement item = dataList.get(i); + if (!item.getId().equals(PropertyConstant.ROOT)) { + if (parentNode != null) { + if (parentNode.getType().equals(PropertyConstant.ARRAY)) { + try { + int index = StringUtils.isNotEmpty(item.getParamName()) ? Integer.parseInt(item.getParamName()) : i; + item.setJsonPath(parentNode.getJsonPath() + "[" + index + "]"); + } catch (Exception e) { + item.setJsonPath(parentNode.getJsonPath() + "." + item.getParamName()); + } + } else { + item.setJsonPath(parentNode.getJsonPath() + "." + item.getParamName()); + } + } else { + item.setJsonPath("$." + item.getParamName()); + } + if (!StringUtils.equalsAny(item.getCondition(), PropertyConstant.NONE, null) || item.getInclude() || item.getArrayVerification() || item.getTypeVerification()) { + list.add(newAssertion(item, conditionMap.get(item.getId()), globalEnable, t)); + } + if (CollectionUtils.isNotEmpty(item.getChildren())) { + if (item.getType().equals(PropertyConstant.ARRAY) && !item.getArrayVerification()) { + continue; + } + formatting(item.getChildren(), list, item, conditionMap, globalEnable, t); + } + } else { + if (CollectionUtils.isNotEmpty(item.getChildren())) { + formatting(item.getChildren(), list, null, conditionMap, globalEnable, t); + } + } + } + } + + private String getConditionStr(MsDocumentAssertionElement item, ElementCondition elementCondition) { + StringBuilder conditionStr = new StringBuilder(); + if (elementCondition != null && CollectionUtils.isNotEmpty(elementCondition.getConditions())) { + if (elementCondition.isTypeVerification()) { + conditionStr.append("类型:[ ").append(item.getType()).append(" ]"); + conditionStr.append(" and "); + } + elementCondition.getConditions().forEach(condition -> { + if (!StringUtils.equals(PropertyConstant.NONE, condition.getKey())) { + conditionStr.append(getLabel(condition.getKey()).replace("'%'", (condition.getValue() != null ? condition.getValue().toString() : ""))); + conditionStr.append(" and "); + } + }); + } + String label = ""; + if (StringUtils.isNotEmpty(conditionStr.toString())) { + label = conditionStr.substring(0, conditionStr.toString().length() - 4); + } + return label; + } + + private T newAssertion(MsDocumentAssertionElement item, ElementCondition elementCondition, boolean globalEnable, T assertion) { + assertion.setEnabled(true); + if (BooleanUtils.isFalse(globalEnable)) { + // 如果整体禁用,则禁用 + assertion.setEnabled(false); + } + if (assertion instanceof XMLAssertion xmlAssertion) { + xmlAssertion.setJsonValidationBool(true); + } + + assertion.setName(String.format("Response date expect %s %s %s", item.getJsonPath(), getConditionStr(item, elementCondition).toLowerCase().replace("_", ""), item.getExpectedResult())); + assertion.setProperty(TestElement.TEST_CLASS, assertion.getClass().getName()); + assertion.setProperty(TestElement.GUI_CLASS, "io.metersphere.assertions.gui." + assertion.getClass().getSimpleName() + "Gui"); + assertion.setProperty("JSON_PATH", item.getJsonPath()); + assertion.setProperty("EXPECTED_VALUE", item.getExpectedResult() != null ? item.getExpectedResult().toString() : ""); + assertion.setProperty("CONDITION", item.getCondition()); + assertion.setProperty("JSONVALIDATION", true); + return assertion; + } + + public String getLabel(String value) { + return switch (value) { + case "EQUALS" -> "值-等于[value='%']"; + case "NOT_EQUALS" -> "值-不等于[value!='%']"; + case "CONTAINS" -> "值-包含[include='%']"; + case "LENGTH_EQUALS" -> "长度-等于[length='%']"; + case "LENGTH_NOT_EQUALS" -> "长度-不等于[length!='%']"; + case "LENGTH_GT" -> "长度-大于[length>'%']"; + case "LENGTH_LT" -> "长度-小于[length<'%']"; + case "REGEX" -> "正则匹配"; + default -> "不校验[]"; + }; } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java index 495d1d7e0a..59b00facfa 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/service/definition/ApiDefinitionImportUtilService.java @@ -6,13 +6,13 @@ import io.metersphere.api.domain.ApiDefinition; import io.metersphere.api.domain.ApiDefinitionBlob; import io.metersphere.api.domain.ApiDefinitionBlobExample; import io.metersphere.api.domain.ApiDefinitionModule; +import io.metersphere.api.dto.converter.ApiDefinitionImport; +import io.metersphere.api.dto.converter.ApiDefinitionImportDetail; +import io.metersphere.api.dto.converter.ApiDetailWithData; +import io.metersphere.api.dto.converter.ApiDetailWithDataUpdate; import io.metersphere.api.dto.definition.ApiDefinitionDTO; import io.metersphere.api.dto.definition.ApiDefinitionPageRequest; import io.metersphere.api.dto.definition.ApiModuleRequest; -import io.metersphere.api.dto.converter.ApiDetailWithData; -import io.metersphere.api.dto.converter.ApiDetailWithDataUpdate; -import io.metersphere.api.dto.converter.ApiDefinitionImport; -import io.metersphere.api.dto.converter.ApiDefinitionImportDetail; import io.metersphere.api.dto.request.ImportRequest; import io.metersphere.api.dto.request.http.Header; import io.metersphere.api.dto.request.http.MsHTTPElement; @@ -20,9 +20,9 @@ import io.metersphere.api.dto.request.http.QueryParam; import io.metersphere.api.dto.request.http.RestParam; import io.metersphere.api.dto.request.http.body.*; import io.metersphere.api.dto.schema.JsonSchemaItem; -import io.metersphere.api.constants.PropertyConstant; import io.metersphere.api.mapper.*; import io.metersphere.api.utils.ApiDataUtils; +import io.metersphere.project.constants.PropertyConstant; import io.metersphere.project.domain.Project; import io.metersphere.project.mapper.ExtBaseProjectVersionMapper; import io.metersphere.project.mapper.ProjectApplicationMapper; @@ -161,12 +161,12 @@ public class ApiDefinitionImportUtilService { apiLists.forEach(t -> { t.setModulePath(idModuleMap.get(t.getModuleId()) != null ? idModuleMap.get(t.getModuleId()).getPath() : StringUtils.EMPTY); }); - ApiDetailWithData apiDeatlWithData = new ApiDetailWithData(); + ApiDetailWithData apiDealWithData = new ApiDetailWithData(); //判断数据是否是唯一的 - checkApiDataOnly(request, importData, apiLists, apiDeatlWithData); + checkApiDataOnly(request, importData, apiLists, apiDealWithData); ApiDetailWithDataUpdate apiDetailWithDataUpdate = new ApiDetailWithDataUpdate(); - getNeedUpdateData(request, apiDeatlWithData, apiDetailWithDataUpdate); + getNeedUpdateData(request, apiDealWithData, apiDetailWithDataUpdate); //数据入库 insertData(modulePathMap, idModuleMap, apiDetailWithDataUpdate, request, user); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java index e8389583fd..d98147a81c 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/ApiDebugControllerTests.java @@ -5,9 +5,9 @@ import io.metersphere.api.controller.result.ApiResultCode; import io.metersphere.api.domain.ApiDebug; import io.metersphere.api.domain.ApiDebugBlob; import io.metersphere.api.domain.ApiFileResource; +import io.metersphere.api.dto.assertion.MsAssertionConfig; import io.metersphere.api.dto.debug.*; import io.metersphere.api.dto.request.MsCommonElement; -import io.metersphere.api.dto.assertion.MsAssertionConfig; import io.metersphere.api.dto.request.http.MsHTTPElement; import io.metersphere.api.dto.request.http.body.Body; import io.metersphere.api.mapper.ApiDebugBlobMapper; @@ -275,6 +275,7 @@ public class ApiDebugControllerTests extends BaseTest { /** * 校验上传的文件 + * * @param id * @param fileIds 全部的文件ID */ @@ -304,6 +305,7 @@ public class ApiDebugControllerTests extends BaseTest { /** * 校验上传的文件 + * * @param id * @param fileIds 全部的文件ID */ @@ -394,6 +396,20 @@ public class ApiDebugControllerTests extends BaseTest { request.setRequest(getMsElementParam(msHTTPElement)); this.requestPostWithOk(DEBUG, request); + msAssertionConfig = new MsAssertionConfig(); + msAssertionConfig.setEnableGlobal(false); + msAssertionConfig.setAssertions(MsHTTPElementTest.getGeneralXmlAssertions()); + msCommonElement = new MsCommonElement(); + msCommonElement.setAssertionConfig(msAssertionConfig); + linkedList = new LinkedList(); + linkedList.add(msCommonElement); + msHTTPElement = MsHTTPElementTest.getMsHttpElement(); + msHTTPElement.setChildren(linkedList); + msHTTPElement.setEnable(true); + request.setRequest(getMsElementParam(msHTTPElement)); + this.requestPostWithOk(DEBUG, request); + + // 测试请求体 MockMultipartFile file = getMockMultipartFile(); String fileId = doUploadTempFile(file); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java index 2e2320203a..4f41eb05e0 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/MsHTTPElementTest.java @@ -11,25 +11,25 @@ import io.metersphere.api.dto.request.http.auth.DigestAuth; import io.metersphere.api.dto.request.http.auth.HTTPAuth; import io.metersphere.api.dto.request.http.auth.NoAuth; import io.metersphere.api.dto.request.http.body.*; -import io.metersphere.api.dto.request.processors.*; -import io.metersphere.project.api.assertion.*; -import io.metersphere.project.api.assertion.body.*; -import io.metersphere.project.api.processor.extract.JSONPathExtract; -import io.metersphere.project.api.processor.extract.RegexExtract; -import io.metersphere.project.api.processor.extract.ResultMatchingExtract; -import io.metersphere.project.api.processor.extract.XPathExtract; -import io.metersphere.project.api.processor.ExtractPostProcessor; +import io.metersphere.api.dto.request.processors.MsProcessorConfig; import io.metersphere.api.dto.schema.JsonSchemaItem; import io.metersphere.api.parser.TestElementParser; import io.metersphere.api.parser.TestElementParserFactory; import io.metersphere.api.utils.ApiDataUtils; import io.metersphere.plugin.api.dto.ParameterConfig; import io.metersphere.plugin.api.spi.AbstractMsTestElement; -import io.metersphere.project.constants.ScriptLanguageType; import io.metersphere.project.api.KeyValueEnableParam; +import io.metersphere.project.api.assertion.*; +import io.metersphere.project.api.assertion.body.*; +import io.metersphere.project.api.processor.ExtractPostProcessor; import io.metersphere.project.api.processor.SQLProcessor; import io.metersphere.project.api.processor.ScriptProcessor; import io.metersphere.project.api.processor.TimeWaitingProcessor; +import io.metersphere.project.api.processor.extract.JSONPathExtract; +import io.metersphere.project.api.processor.extract.RegexExtract; +import io.metersphere.project.api.processor.extract.ResultMatchingExtract; +import io.metersphere.project.api.processor.extract.XPathExtract; +import io.metersphere.project.constants.ScriptLanguageType; import io.metersphere.sdk.constants.MsAssertionCondition; import io.metersphere.sdk.util.BeanUtils; import org.junit.jupiter.api.Assertions; @@ -268,6 +268,35 @@ public class MsHTTPElementTest { defaultParser.parse(msTestElement, parameterConfig); } + @Test + public void msAssertionTestXml() { + + MsHTTPElement msHTTPElement = getMsHttpElement(); + List assertions = getGeneralXmlAssertions(); + + MsAssertionConfig msAssertionConfig = new MsAssertionConfig(); + msAssertionConfig.setEnableGlobal(false); + msAssertionConfig.setAssertions(assertions); + + MsCommonElement msCommonElement = new MsCommonElement(); + msCommonElement.setAssertionConfig(msAssertionConfig); + + LinkedList linkedList = new LinkedList(); + linkedList.add(msCommonElement); + msHTTPElement.setChildren(linkedList); + + String json = ApiDataUtils.toJSONString(msHTTPElement); + Assertions.assertNotNull(json); + Assertions.assertEquals(ApiDataUtils.parseObject(json, AbstractMsTestElement.class), msHTTPElement); + + // 测试脚本解析 + ParameterConfig parameterConfig = new ApiParamConfig(); + parameterConfig.setReportId("reportId"); + TestElementParser defaultParser = TestElementParserFactory.getDefaultParser(); + AbstractMsTestElement msTestElement = ApiDataUtils.parseObject(json, AbstractMsTestElement.class); + defaultParser.parse(msTestElement, parameterConfig); + } + public static List getGeneralAssertions() { List assertions = new ArrayList<>(); MsResponseCodeAssertion responseCodeAssertion = new MsResponseCodeAssertion(); @@ -297,6 +326,39 @@ public class MsHTTPElementTest { MsResponseBodyAssertion documentResponseBodyAssertion = new MsResponseBodyAssertion(); documentResponseBodyAssertion.setAssertionBodyType(MsResponseBodyAssertion.MsBodyAssertionType.DOCUMENT.name()); MsDocumentAssertion msDocumentAssertion = new MsDocumentAssertion(); + MsDocumentAssertionElement item = new MsDocumentAssertionElement(); + item.setId("1"); + item.setParamName("pet"); + item.setInclude(false); + item.setType("object"); + item.setCondition("none"); + item.setTypeVerification(false); + item.setExpectedResult(""); + MsDocumentAssertionElement item1 = new MsDocumentAssertionElement(); + item1.setId("2"); + item1.setParamName("id"); + item1.setInclude(false); + item1.setType("integer"); + item1.setCondition("EQUALS"); + item1.setExpectedResult("1"); + MsDocumentAssertionElement item2 = new MsDocumentAssertionElement(); + item2.setId("3"); + item2.setParamName("attributes"); + item2.setInclude(false); + item2.setType("string"); + item2.setCondition("EQUALS"); + item2.setExpectedResult("s,2"); + MsDocumentAssertionElement item3 = new MsDocumentAssertionElement(); + item3.setId("4"); + item3.setParamName("array"); + item3.setInclude(false); + item3.setArrayVerification(true); + item3.setType("array"); + item3.setCondition("EQUALS"); + item3.setExpectedResult("s,2"); + item.setChildren(List.of(item1, item2, item3)); + msDocumentAssertion.setJsonAssertion(item); + msDocumentAssertion.setDocumentType("JSON"); documentResponseBodyAssertion.setDocumentAssertion(msDocumentAssertion); assertions.add(documentResponseBodyAssertion); @@ -344,6 +406,51 @@ public class MsHTTPElementTest { return assertions; } + public static List getGeneralXmlAssertions() { + List assertions = new ArrayList<>(); + + MsResponseBodyAssertion documentResponseBodyAssertion = new MsResponseBodyAssertion(); + documentResponseBodyAssertion.setAssertionBodyType(MsResponseBodyAssertion.MsBodyAssertionType.DOCUMENT.name()); + MsDocumentAssertion msDocumentAssertion = new MsDocumentAssertion(); + MsDocumentAssertionElement item = new MsDocumentAssertionElement(); + item.setId("1"); + item.setParamName("pet"); + item.setInclude(false); + item.setType("object"); + item.setCondition("none"); + item.setTypeVerification(false); + item.setExpectedResult(""); + MsDocumentAssertionElement item1 = new MsDocumentAssertionElement(); + item1.setId("2"); + item1.setParamName("id"); + item1.setInclude(false); + item1.setType("integer"); + item1.setCondition("EQUALS"); + item1.setExpectedResult("1"); + MsDocumentAssertionElement item2 = new MsDocumentAssertionElement(); + item2.setId("3"); + item2.setParamName("attributes"); + item2.setInclude(false); + item2.setType("string"); + item2.setCondition("EQUALS"); + item2.setExpectedResult("s,2"); + MsDocumentAssertionElement item3 = new MsDocumentAssertionElement(); + item3.setId("4"); + item3.setParamName("array"); + item3.setInclude(false); + item3.setArrayVerification(true); + item3.setType("array"); + item3.setCondition("EQUALS"); + item3.setExpectedResult("s,2"); + item.setChildren(List.of(item1, item2, item3)); + msDocumentAssertion.setXmlAssertion(item); + msDocumentAssertion.setDocumentType("XML"); + documentResponseBodyAssertion.setDocumentAssertion(msDocumentAssertion); + assertions.add(documentResponseBodyAssertion); + + return assertions; + } + public static MsHTTPElement getMsHttpElement() { MsHTTPElement msHTTPElement = new MsHTTPElement(); msHTTPElement.setUrl("http://www.test.com"); diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java new file mode 100644 index 0000000000..ccbe364fec --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/Condition.java @@ -0,0 +1,18 @@ +package io.metersphere.project.api.assertion.body; + +import lombok.Data; + +@Data +public class Condition { + private String key; + private Object value; + + public Condition() { + + } + + public Condition(String key, Object value) { + this.key = key; + this.value = value; + } +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java new file mode 100644 index 0000000000..0ee97e7b89 --- /dev/null +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/ElementCondition.java @@ -0,0 +1,22 @@ +package io.metersphere.project.api.assertion.body; + +import lombok.Data; + +import java.util.List; + +@Data +public class ElementCondition { + private boolean include; + private boolean typeVerification; + private boolean arrayVerification; + private String type; + + List conditions; + + public ElementCondition(boolean include, boolean typeVerification, boolean arrayVerification, List conditions) { + this.include = include; + this.typeVerification = typeVerification; + this.arrayVerification = arrayVerification; + this.conditions = conditions; + } +} diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertion.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertion.java index 58e4ecd78e..b38cb9d7fd 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertion.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertion.java @@ -7,6 +7,7 @@ import lombok.Data; /** * 文档断言 + * * @Author: jianxing * @CreateTime: 2023-11-23 14:19 */ @@ -15,6 +16,7 @@ public class MsDocumentAssertion extends MsBodyAssertionItem { /** * 跟随定义的apiId * 传空为不跟随接口定义 + * 如果选择了 */ @Size(max = 50) private String followApiId; @@ -25,9 +27,10 @@ public class MsDocumentAssertion extends MsBodyAssertionItem { * 这里跟前端数据结构有差异 * 后端从设计层面支持多种文档格式,前端只支持一种 * 同时切换可以同时持久化两种格式 - * + *

* 取值参考 {@link DocumentType} -= */ + * = + */ @EnumValue(enumClass = DocumentType.class) private String documentType; /** diff --git a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertionElement.java b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertionElement.java index 3f7bdef6d1..dd37265867 100644 --- a/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertionElement.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/api/assertion/body/MsDocumentAssertionElement.java @@ -12,6 +12,7 @@ import java.util.List; /** * 文档断言项 + * * @Author: jianxing * @CreateTime: 2023-11-23 11:43 */ @@ -52,12 +53,16 @@ public class MsDocumentAssertionElement { /** * 组内校验 */ - private Boolean arrayVerification; + private Boolean arrayVerification = false; /** * 子对象 */ @Valid private List children; + /** + * 在执行时组装数据用 + */ + private String jsonPath; /** * 文档断言类型 @@ -80,4 +85,5 @@ public class MsDocumentAssertionElement { return value; } } + } diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/constants/PropertyConstant.java b/backend/services/project-management/src/main/java/io/metersphere/project/constants/PropertyConstant.java similarity index 63% rename from backend/services/api-test/src/main/java/io/metersphere/api/constants/PropertyConstant.java rename to backend/services/project-management/src/main/java/io/metersphere/project/constants/PropertyConstant.java index 99ba65d0cc..5cc0cbc701 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/constants/PropertyConstant.java +++ b/backend/services/project-management/src/main/java/io/metersphere/project/constants/PropertyConstant.java @@ -1,4 +1,4 @@ -package io.metersphere.api.constants; +package io.metersphere.project.constants; public class PropertyConstant { public final static String REQUIRED = "required"; @@ -10,5 +10,9 @@ public class PropertyConstant { public final static String INTEGER = "integer"; public final static String NULL = "null"; public final static String NONE = "none"; + public final static String ROOT = "root"; + public final static String EXPECTED_VALUE = "EXPECTED_VALUE"; + public final static String ELEMENT_CONDITION = "ElementCondition"; + public final static String XML_PATH = "XML_PATH"; } diff --git a/pom.xml b/pom.xml index 58ba1811e0..0724bc90c4 100644 --- a/pom.xml +++ b/pom.xml @@ -28,7 +28,7 @@ 33.0.0-jre 6.1.0 3.0 - 1.0.1 + 1.0.2 1.0.7 3.26.0 3.0.3