diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/MsAssertionCondition.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/MsAssertionCondition.java new file mode 100644 index 0000000000..90e2a78c44 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/constants/MsAssertionCondition.java @@ -0,0 +1,88 @@ +package io.metersphere.sdk.constants; + +/** + * @Author: jianxing + * @CreateTime: 2023-11-23 10:21 + */ +public enum MsAssertionCondition { + /** + * 不校验 + */ + UNCHECK, + /** + * 包含 + */ + INCLUDE, + /** + * 不包含 + */ + NOT_INCLUDE, + /** + * 等于 + */ + EQUALS, + /** + * 不等于 + */ + NOT_EQUALS, + /** + * 大于 + */ + GT, + /** + * 大于或等于 + */ + GT_OR_EQUALS, + /** + * 小于 + */ + LT, + /** + * 小于或等于 + */ + LT_OR_EQUALS, + /** + * 以...开始 + */ + START_WITH, + /** + * 以...结束 + */ + END_WITH, + /** + * 为空 + */ + EMPTY, + /** + * 不为空 + */ + NOT_EMPTY, + /** + * 正则匹配 + */ + REGEX, + /** + * 长度等于 + */ + LENGTH_EQUALS, + /** + * 长度不等于 + */ + LENGTH_NOT_EQUALS, + /** + * 长度大于 + */ + LENGTH_GT, + /** + * 长度大于或等于 + */ + LENGTH_GT_OR_EQUALS, + /** + * 长度小于 + */ + LENGTH_LT, + /** + * 长度小于或等于 + */ + LENGTH_LT_OR_EQUALS, +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertion.java new file mode 100644 index 0000000000..763df73699 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertion.java @@ -0,0 +1,28 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.Data; + +/** + * 断言 + */ +@Data +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "assertionType") +@JsonSubTypes({ + @JsonSubTypes.Type(value = ResponseCodeAssertion.class), + @JsonSubTypes.Type(value = ResponseHeaderAssertion.class), + @JsonSubTypes.Type(value = ResponseBodyAssertion.class), + @JsonSubTypes.Type(value = ResponseTimeAssertion.class), + @JsonSubTypes.Type(value = ScriptAssertion.class), +}) +public abstract class MsAssertion { + /** + * 是否启用 + */ + private Boolean enable = true; + /** + * 断言名称 + */ + private String name; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionConfig.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionConfig.java new file mode 100644 index 0000000000..3856a1e55c --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionConfig.java @@ -0,0 +1,22 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import lombok.Data; + +import java.util.List; + +/** + * 断言设置 + * @Author: jianxing + * @CreateTime: 2023-11-23 17:26 + */ +@Data +public class MsAssertionConfig { + /** + * 是否启用全局断言 + */ + private Boolean enableGlobal; + /** + * 断言列表 + */ + private List assertions; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionDuration.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionDuration.java deleted file mode 100644 index 8f2b748d47..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionDuration.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.metersphere.sdk.dto.api.request.assertion; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsAssertionDuration extends MsAssertionType { - private long value; - - public MsAssertionDuration() { - setType(MsAssertionType.DURATION); - } - - public boolean isValid() { - return value > 0 && isEnable(); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionJSR223.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionJSR223.java deleted file mode 100644 index ec325b58b9..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionJSR223.java +++ /dev/null @@ -1,26 +0,0 @@ -package io.metersphere.sdk.dto.api.request.assertion; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.apache.commons.lang3.StringUtils; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsAssertionJSR223 extends MsAssertionType { - private String variable; - private String operator; - private String value; - private String desc; - private String name; - private String script; - private String scriptLanguage; - private Boolean jsrEnable; - - public MsAssertionJSR223() { - setType(MsAssertionType.JSR223); - } - - public boolean isValid() { - return StringUtils.isNotBlank(script) && StringUtils.isNotBlank(scriptLanguage) && isEnable(); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionJsonPath.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionJsonPath.java deleted file mode 100644 index ec8e93f5c4..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionJsonPath.java +++ /dev/null @@ -1,22 +0,0 @@ -package io.metersphere.sdk.dto.api.request.assertion; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.apache.commons.lang3.StringUtils; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsAssertionJsonPath extends MsAssertionType { - private String expect; - private String expression; - private String description; - private String option = "REGEX"; - - public MsAssertionJsonPath() { - setType(MsAssertionType.JSON_PATH); - } - - public boolean isValid() { - return StringUtils.isNotBlank(expression) && isEnable(); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionRegex.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionRegex.java deleted file mode 100644 index 5436b5af36..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionRegex.java +++ /dev/null @@ -1,23 +0,0 @@ -package io.metersphere.sdk.dto.api.request.assertion; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.apache.commons.lang3.StringUtils; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsAssertionRegex extends MsAssertionType { - private String subject; - private String expression; - private String description; - private boolean assumeSuccess; - private int testType = 2; - - public MsAssertionRegex() { - setType(MsAssertionType.REGEX); - } - - public boolean isValid() { - return StringUtils.isNotBlank(subject) && StringUtils.isNotBlank(expression) && isEnable(); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionType.java deleted file mode 100644 index 4942ee8011..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionType.java +++ /dev/null @@ -1,17 +0,0 @@ -package io.metersphere.sdk.dto.api.request.assertion; - -import lombok.Data; - -@Data -public class MsAssertionType { - public final static String REGEX = "Regex"; - public final static String DURATION = "Duration"; - public final static String JSON_PATH = "JSONPath"; - public final static String JSR223 = "JSR223"; - public final static String TEXT = "Text"; - public final static String XPATH2 = "XPath2"; - private boolean enable = true; - public String label; - - private String type; -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionXPath2.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionXPath2.java deleted file mode 100644 index 0abd8aae68..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertionXPath2.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.metersphere.sdk.dto.api.request.assertion; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.apache.commons.lang3.StringUtils; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsAssertionXPath2 extends MsAssertionType { - private String expression; - - public MsAssertionXPath2() { - setType(MsAssertionType.XPATH2); - } - - public boolean isValid() { - return StringUtils.isNotBlank(expression) && isEnable(); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertions.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertions.java deleted file mode 100644 index a28fd36816..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsAssertions.java +++ /dev/null @@ -1,21 +0,0 @@ -package io.metersphere.sdk.dto.api.request.assertion; - -import io.metersphere.plugin.api.annotation.PluginSubType; -import io.metersphere.plugin.api.dto.TestElementDTO; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@Data -@EqualsAndHashCode(callSuper = true) -@PluginSubType("MsAssertions") -public class MsAssertions extends TestElementDTO { - private String xpathType; - private boolean scenarioAss; - private List regex; - private List jsonPath; - private List jsr223; - private List xpath2; - private MsAssertionDuration duration; -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsBodyAssertionType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsBodyAssertionType.java new file mode 100644 index 0000000000..33e23fa235 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/MsBodyAssertionType.java @@ -0,0 +1,23 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +/** + * body断言中的断言类型 + */ +public enum MsBodyAssertionType { + /** + * 正则断言 + */ + REGEX, + /** + * XPath断言 + */ + XPATH, + /** + * JSONPath断言 + */ + JSON_PATH, + /** + * 文档断言 + */ + DOCUMENT +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseBodyAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseBodyAssertion.java new file mode 100644 index 0000000000..6e4f2acc75 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseBodyAssertion.java @@ -0,0 +1,43 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import io.metersphere.sdk.dto.api.request.assertion.body.DocumentAssertion; +import io.metersphere.sdk.dto.api.request.assertion.body.JSONPathAssertion; +import io.metersphere.sdk.dto.api.request.assertion.body.RegexAssertion; +import io.metersphere.sdk.dto.api.request.assertion.body.XPathAssertion; +import lombok.Data; + +/** + * 请求体断言 + * @Author: jianxing + * @CreateTime: 2023-11-22 15:33 + */ +@Data +@JsonTypeName("RESPONSE_BODY") +public class ResponseBodyAssertion extends MsAssertion { + /** + * 断言类型 + * 根据断言类型,选择对应的断言 + * 这里跟前端数据结构有差异 + * 后端从设计层面支持多种断言,前端只支持一种 + * 同时切换可以同时持久化两种类型 + * 值为 MsBodyAssertionType + */ + private String assertionType; + /** + * jsonPath断言 + */ + private JSONPathAssertion jsonPathAssertion; + /** + * xpath断言 + */ + private XPathAssertion xpathAssertion; + /** + * 文档断言 + */ + private DocumentAssertion documentAssertion; + /** + * 正则断言 + */ + private RegexAssertion regexAssertion; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseCodeAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseCodeAssertion.java new file mode 100644 index 0000000000..36a29bc71a --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseCodeAssertion.java @@ -0,0 +1,25 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +/** + * @Author: jianxing + * @CreateTime: 2023-11-22 15:33 + */ +@Data +@JsonTypeName("RESPONSE_CODE") +public class ResponseCodeAssertion extends MsAssertion { + /** + * 匹配条件 + * 不校验即忽略状态 + * 选择其他条件时,也忽略状态 + * 不校验可搭配其他校验使用 + * 值为 MsAssertionCondition + */ + private String condition; + /** + * 匹配值 + */ + private String value; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseHeaderAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseHeaderAssertion.java new file mode 100644 index 0000000000..e7efa8c4c3 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseHeaderAssertion.java @@ -0,0 +1,40 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +import java.util.List; + +/** + * 响应头断言 + * @Author: jianxing + * @CreateTime: 2023-11-22 15:33 + */ +@Data +@JsonTypeName("RESPONSE_HEADER") +public class ResponseHeaderAssertion extends MsAssertion { + + private List assertions; + + + @Data + public static class ResponseHeaderAssertionItem { + /** + * 是否启用 + */ + private Boolean enable = true; + /** + * 响应头 + */ + private String header; + /** + * 匹配条件 + * 值为 MsAssertionCondition + */ + private String condition; + /** + * 匹配值 + */ + private String value; + } +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseTimeAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseTimeAssertion.java new file mode 100644 index 0000000000..2e359fae48 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ResponseTimeAssertion.java @@ -0,0 +1,19 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +/** + * 响应时间断言 + * @Author: jianxing + * @CreateTime: 2023-11-22 15:33 + */ +@Data +@JsonTypeName("RESPONSE_TIME") +public class ResponseTimeAssertion extends MsAssertion { + /** + * 最大响应时间 + * 响应时间在xx毫秒内 + */ + private Long maxResponseTime; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ScriptAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ScriptAssertion.java new file mode 100644 index 0000000000..1a9279af1b --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/ScriptAssertion.java @@ -0,0 +1,31 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +/** + * 变量断言 + * @Author: jianxing + * @CreateTime: 2023-11-22 15:33 + */ +@Data +@JsonTypeName("SCRIPT") +public class ScriptAssertion extends MsAssertion { + /** + * 脚本描述 + */ + private String description; + /** + * 脚本内容 + */ + private String content; + /** + * 是否使用功能脚本 + * 公共脚本和手动录入脚本只能二选一 + */ + private Boolean enableCommonScript; + /** + * 引用公共脚本的ID + */ + private String commonScriptId; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/VariableAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/VariableAssertion.java new file mode 100644 index 0000000000..d068a4dee7 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/VariableAssertion.java @@ -0,0 +1,38 @@ +package io.metersphere.sdk.dto.api.request.assertion; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +import java.util.List; + +/** + * 变量断言 + * @Author: jianxing + * @CreateTime: 2023-11-22 15:33 + */ +@Data +@JsonTypeName("VARIABLE") +public class VariableAssertion { + + private List variableAssertionItem; + @Data + public static class VariableAssertionItem { + /** + * 是否启用 + */ + private Boolean enable = true; + /** + * 变量名 + */ + private String name; + /** + * 匹配条件 + * 值为 MsAssertionCondition + */ + private String condition; + /** + * 匹配值 + */ + private String value; + } +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/BodyAssertionItem.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/BodyAssertionItem.java new file mode 100644 index 0000000000..0d99cfb033 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/BodyAssertionItem.java @@ -0,0 +1,13 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + +import lombok.Data; + +/** + * body 断言基类 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:25 + */ +@Data +public abstract class BodyAssertionItem { + private Boolean enable = true; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/DocumentAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/DocumentAssertion.java new file mode 100644 index 0000000000..cd97dfc365 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/DocumentAssertion.java @@ -0,0 +1,34 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + +import lombok.Data; + +/** + * 文档断言 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:19 + */ +@Data +public class DocumentAssertion extends BodyAssertionItem { + /** + * 跟随定义的apiId + * 传空为不跟随接口定义 + */ + private String followApiId; + /** + * 文档类型 + * json 或者 xml + * 根据文档类型,选择对应的文档 + * 这里跟前端数据结构有差异 + * 后端从设计层面支持多种文档格式,前端只支持一种 + * 同时切换可以同时持久化两种格式 + */ + private String documentType; + /** + * json格式的文档断言 + */ + private DocumentAssertionElement jsonAssertion; + /** + * xml格式的文档断言 + */ + private DocumentAssertionElement xmlAssertion; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/DocumentAssertionElement.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/DocumentAssertionElement.java new file mode 100644 index 0000000000..47b62c2999 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/DocumentAssertionElement.java @@ -0,0 +1,47 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + +import lombok.Data; + +import java.util.List; + +/** + * @Author: jianxing + * @CreateTime: 2023-11-23 11:43 + */ +@Data +public class DocumentAssertionElement { + private String id; + /** + * 参数名 + */ + private String paramName; + /** + * 必含 + */ + private Boolean include = false; + /** + * 类型 + */ + private String type; + /** + * 类型校验 + */ + private Boolean typeVerification = false; + /** + * 匹配条件 + */ + private String condition; + /** + * 匹配值 + * 即预期结果 + */ + private Object expectedResult; + /** + * 组内校验 + */ + private Boolean arrayVerification; + /** + * 子对象 + */ + private List children; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/JSONPathAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/JSONPathAssertion.java new file mode 100644 index 0000000000..4e43608579 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/JSONPathAssertion.java @@ -0,0 +1,21 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + +import lombok.Data; + +import java.util.List; + +/** + * + * JSONPath断言 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:04 + */ +@Data +public class JSONPathAssertion { + + /** + * 断言列表 + */ + private List assertions; +} + diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/JSONPathAssertionItem.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/JSONPathAssertionItem.java new file mode 100644 index 0000000000..d2808f24b1 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/JSONPathAssertionItem.java @@ -0,0 +1,17 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + +import lombok.Data; + +/** + * + * JSONPath断言 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:04 + */ +@Data +public class JSONPathAssertionItem extends BodyAssertionItem { + private String expression; + private String condition; + private String value; +} + diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/RegexAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/RegexAssertion.java new file mode 100644 index 0000000000..abe79af215 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/RegexAssertion.java @@ -0,0 +1,18 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + +import lombok.Data; + +import java.util.List; + +/** + * 正则断言 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:03 + */ +@Data +public class RegexAssertion { + /** + * 断言列表 + */ + private List assertions; +} \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/RegexAssertionItem.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/RegexAssertionItem.java new file mode 100644 index 0000000000..f22dc8c393 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/RegexAssertionItem.java @@ -0,0 +1,13 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + +import lombok.Data; + +/** + * 正则断言 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:03 + */ +@Data +public class RegexAssertionItem extends BodyAssertionItem { + private String expression; +} \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/XPathAssertion.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/XPathAssertion.java new file mode 100644 index 0000000000..a647539788 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/XPathAssertion.java @@ -0,0 +1,24 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + + +import lombok.Data; + +import java.util.List; + +/** + * XPath断言 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:18 + */ +@Data +public class XPathAssertion { + /** + * 响应内容格式 + * xml 或者 html + */ + private String format; + /** + * xpath断言 + */ + private List assertions; +} \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/XPathAssertionItem.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/XPathAssertionItem.java new file mode 100644 index 0000000000..c3d8b16d5c --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/assertion/body/XPathAssertionItem.java @@ -0,0 +1,15 @@ +package io.metersphere.sdk.dto.api.request.assertion.body; + + +import lombok.Data; +/** + * XPath断言 + * @Author: jianxing + * @CreateTime: 2023-11-23 14:18 + */ +@Data +public class XPathAssertionItem extends BodyAssertionItem { + private String expression; + private String condition; + private String value; +} \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/Header.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/Header.java index 1ad8859a6b..9b4aca5c80 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/Header.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/Header.java @@ -7,6 +7,6 @@ import lombok.Data; * @CreateTime: 2023-11-06 16:59 */ @Data -public class Header extends KeyValueParam { +public class Header extends KeyValueEnableParam { } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/KeyValueEnableParam.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/KeyValueEnableParam.java new file mode 100644 index 0000000000..fd9f0befd7 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/KeyValueEnableParam.java @@ -0,0 +1,19 @@ +package io.metersphere.sdk.dto.api.request.http; + +import lombok.Data; + +/** + * @Author: jianxing + * @CreateTime: 2023-11-06 17:27 + */ +@Data +public class KeyValueEnableParam extends KeyValueParam { + /** + * 是否启用 + */ + private Boolean enable = true; + /** + * 描述 + */ + private String description; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/KeyValueParam.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/KeyValueParam.java index 757a7e320d..1c02f1b97a 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/KeyValueParam.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/KeyValueParam.java @@ -16,12 +16,4 @@ public class KeyValueParam { * 值 */ private String value; - /** - * 是否启用 - */ - private Boolean enable = true; - /** - * 描述 - */ - private String description; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/MsHTTPElement.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/MsHTTPElement.java index fdfb3231a6..b275eb469f 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/MsHTTPElement.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/MsHTTPElement.java @@ -1,9 +1,10 @@ package io.metersphere.sdk.dto.api.request.http; import io.metersphere.plugin.api.spi.AbstractMsTestElement; +import io.metersphere.sdk.dto.api.request.assertion.MsAssertionConfig; import io.metersphere.sdk.dto.api.request.http.auth.HTTPAuth; import io.metersphere.sdk.dto.api.request.http.body.Body; -import io.metersphere.sdk.dto.api.request.processors.MsProcessor; +import io.metersphere.sdk.dto.api.request.processors.MsProcessorConfig; import lombok.Data; import lombok.EqualsAndHashCode; @@ -51,12 +52,15 @@ public class MsHTTPElement extends AbstractMsTestElement { */ private HTTPAuth authConfig; /** - * 前置处理器 + * 前置处理器配置 */ - private List preProcessors; + private MsProcessorConfig preProcessorConfig; /** - * 后置处理器 + * 后置处理器配置 */ - private List postProcessors; - // todo 断言和提取 待设计 + private MsProcessorConfig postProcessorConfig; + /** + * 断言配置 + */ + private MsAssertionConfig assertionConfig; } \ No newline at end of file diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/QueryParam.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/QueryParam.java index 419f4853aa..bb3b9aea6f 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/QueryParam.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/QueryParam.java @@ -7,7 +7,7 @@ import lombok.Data; * @CreateTime: 2023-11-06 16:59 */ @Data -public class QueryParam extends KeyValueParam { +public class QueryParam extends KeyValueEnableParam { /** * 参数类型 diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/RestParam.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/RestParam.java index ec5bc309ab..54b86cefaa 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/RestParam.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/RestParam.java @@ -7,7 +7,7 @@ import lombok.Data; * @CreateTime: 2023-11-06 16:59 */ @Data -public class RestParam extends KeyValueParam { +public class RestParam extends KeyValueEnableParam { /** * 参数类型 * 默认string,可选integer、number、array diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataKV.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataKV.java index bb00493f8c..f3f72b9c25 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataKV.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/http/body/FormDataKV.java @@ -1,6 +1,6 @@ package io.metersphere.sdk.dto.api.request.http.body; -import io.metersphere.sdk.dto.api.request.http.KeyValueParam; +import io.metersphere.sdk.dto.api.request.http.KeyValueEnableParam; import lombok.Data; /** @@ -8,7 +8,7 @@ import lombok.Data; * @CreateTime: 2023-11-06 18:11 */ @Data -public class FormDataKV extends KeyValueParam { +public class FormDataKV extends KeyValueEnableParam { private String paramType; private Boolean required = false; private Integer minLength; diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtract.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtract.java deleted file mode 100644 index ed298eb324..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtract.java +++ /dev/null @@ -1,18 +0,0 @@ -package io.metersphere.sdk.dto.api.request.post.extract; - -import io.metersphere.plugin.api.annotation.PluginSubType; -import io.metersphere.plugin.api.dto.TestElementDTO; -import lombok.Data; -import lombok.EqualsAndHashCode; - -import java.util.List; - -@Data -@EqualsAndHashCode(callSuper = true) -@PluginSubType("MsExtract") -public class MsExtract extends TestElementDTO { - private String xpathType; - private List regex; - private List json; - private List xpath; -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractCommon.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractCommon.java deleted file mode 100644 index 62faf0c1d9..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractCommon.java +++ /dev/null @@ -1,19 +0,0 @@ -package io.metersphere.sdk.dto.api.request.post.extract; - -import lombok.Data; -import lombok.EqualsAndHashCode; -import org.apache.commons.lang3.StringUtils; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsExtractCommon extends MsExtractType { - private String variable; - private String value; - private String expression; - private String description; - private boolean multipleMatching; - - public boolean isValid() { - return StringUtils.isNotBlank(variable) && StringUtils.isNotBlank(expression); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractJSONPath.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractJSONPath.java deleted file mode 100644 index 23343f017c..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractJSONPath.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.metersphere.sdk.dto.api.request.post.extract; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsExtractJSONPath extends MsExtractCommon { - public MsExtractJSONPath() { - setType(JSON_PATH); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractRegex.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractRegex.java deleted file mode 100644 index 3c679f40c8..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractRegex.java +++ /dev/null @@ -1,14 +0,0 @@ -package io.metersphere.sdk.dto.api.request.post.extract; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsExtractRegex extends MsExtractCommon { - private String useHeaders; - private String template; - public MsExtractRegex() { - setType(MsExtractType.REGEX); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractType.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractType.java deleted file mode 100644 index 595feb134d..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractType.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.metersphere.sdk.dto.api.request.post.extract; - -import lombok.Data; - -@Data -public class MsExtractType { - public final static String REGEX = "Regex"; - public final static String JSON_PATH = "JSONPath"; - public final static String XPATH = "XPath"; - - private String type; -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractXPath.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractXPath.java deleted file mode 100644 index 22e0a0dfe7..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/extract/MsExtractXPath.java +++ /dev/null @@ -1,12 +0,0 @@ -package io.metersphere.sdk.dto.api.request.post.extract; - -import lombok.Data; -import lombok.EqualsAndHashCode; - -@EqualsAndHashCode(callSuper = true) -@Data -public class MsExtractXPath extends MsExtractCommon { - public MsExtractXPath() { - setType(MsExtractType.XPATH); - } -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/processors/MsPostJSR223Processor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/processors/MsPostJSR223Processor.java deleted file mode 100644 index 5e745fb0a8..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/post/processors/MsPostJSR223Processor.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.metersphere.sdk.dto.api.request.post.processors; - -import io.metersphere.plugin.api.annotation.PluginSubType; -import io.metersphere.plugin.api.dto.TestElementDTO; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -@PluginSubType("MSPostJSR223Processor") -public class MsPostJSR223Processor extends TestElementDTO { - private String script; - private String scriptLanguage; - private Boolean jsrEnable; - -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/pre/processors/MsPreJSR223Processor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/pre/processors/MsPreJSR223Processor.java deleted file mode 100644 index 1c4dbaf037..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/pre/processors/MsPreJSR223Processor.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.metersphere.sdk.dto.api.request.pre.processors; - -import io.metersphere.plugin.api.annotation.PluginSubType; -import io.metersphere.plugin.api.dto.TestElementDTO; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -@PluginSubType("MSPreJSR223Processor") -public class MsPreJSR223Processor extends TestElementDTO { - private String script; - private String scriptLanguage; - private Boolean jsrEnable; -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/CommonScriptProcessor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/CommonScriptProcessor.java new file mode 100644 index 0000000000..68898e123a --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/CommonScriptProcessor.java @@ -0,0 +1,25 @@ +package io.metersphere.sdk.dto.api.request.processors; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import io.metersphere.sdk.dto.api.request.http.KeyValueParam; +import lombok.Data; + +import java.util.List; + +/** + * 公共脚本处理器 + * @Author: jianxing + * @CreateTime: 2023-11-07 09:59 + */ +@Data +@JsonTypeName("COMMON_SCRIPT") +public class CommonScriptProcessor extends MsProcessor { + /** + * 脚本ID + */ + private String scriptId; + /** + * 入参 + */ + private List params; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/ExtractPostProcessor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/ExtractPostProcessor.java new file mode 100644 index 0000000000..23e85eb260 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/ExtractPostProcessor.java @@ -0,0 +1,20 @@ +package io.metersphere.sdk.dto.api.request.processors; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import io.metersphere.sdk.dto.api.request.processors.extract.MsExtract; +import lombok.Data; + +import java.util.List; + +/** + * @Author: jianxing + * @CreateTime: 2023-11-22 11:08 + */ +@Data +@JsonTypeName("EXTRACT") +public class ExtractPostProcessor extends MsProcessor { + /** + * 提取器列表 + */ + private List extractors; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsJSR223Processor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsJSR223Processor.java deleted file mode 100644 index a5037c1f9f..0000000000 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsJSR223Processor.java +++ /dev/null @@ -1,15 +0,0 @@ -package io.metersphere.sdk.dto.api.request.processors; - -import io.metersphere.plugin.api.annotation.PluginSubType; -import io.metersphere.plugin.api.dto.TestElementDTO; -import lombok.Data; -import lombok.EqualsAndHashCode; - -@Data -@EqualsAndHashCode(callSuper = true) -@PluginSubType("MsJSR223Processor") -public class MsJSR223Processor extends TestElementDTO { - private String script; - private String scriptLanguage; - private Boolean jsrEnable; -} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsProcessor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsProcessor.java index e602e29cd1..1b4e62ec23 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsProcessor.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsProcessor.java @@ -14,6 +14,16 @@ import lombok.Data; @JsonSubTypes.Type(value = ScriptProcessor.class), @JsonSubTypes.Type(value = SQLProcessor.class), @JsonSubTypes.Type(value = TimeWaitingProcessor.class), + @JsonSubTypes.Type(value = CommonScriptProcessor.class), + @JsonSubTypes.Type(value = ExtractPostProcessor.class), }) public abstract class MsProcessor { + /** + * 名称 + */ + private String name; + /** + * 是否启用 + */ + private Boolean enable = true; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsProcessorConfig.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsProcessorConfig.java new file mode 100644 index 0000000000..6f685f5471 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/MsProcessorConfig.java @@ -0,0 +1,21 @@ +package io.metersphere.sdk.dto.api.request.processors; + +import lombok.Data; + +import java.util.List; + +/** + * @Author: jianxing + * @CreateTime: 2023-11-07 10:17 + */ +@Data +public class MsProcessorConfig { + /** + * 是否启用全局前置 + */ + private Boolean enableGlobal; + /** + * 处理器 + */ + private List processors; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/SQLProcessor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/SQLProcessor.java index 511d9b63e9..bc92c41980 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/SQLProcessor.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/SQLProcessor.java @@ -1,6 +1,7 @@ package io.metersphere.sdk.dto.api.request.processors; import com.fasterxml.jackson.annotation.JsonTypeName; +import io.metersphere.sdk.dto.api.request.http.KeyValueEnableParam; import io.metersphere.sdk.dto.api.request.http.KeyValueParam; import lombok.Data; @@ -32,7 +33,7 @@ public class SQLProcessor extends MsProcessor { /** * 变量列表 */ - private List variables; + private List variables; /** * 环境ID */ @@ -42,7 +43,7 @@ public class SQLProcessor extends MsProcessor { */ private String dataSourceId; /** - * 是否启用 + * 提取参数 */ - private Boolean enable; + private List extractParams; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/ScriptProcessor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/ScriptProcessor.java index c7f01cba59..8ff93095a2 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/ScriptProcessor.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/ScriptProcessor.java @@ -13,5 +13,4 @@ public class ScriptProcessor extends MsProcessor { private String script; private String scriptLanguage; private Boolean jsrEnable; - private Boolean enable; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/TimeWaitingProcessor.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/TimeWaitingProcessor.java index bd7ee99a39..249e6c9029 100644 --- a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/TimeWaitingProcessor.java +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/TimeWaitingProcessor.java @@ -11,5 +11,4 @@ import lombok.Data; @JsonTypeName("TIME_WAITING") public class TimeWaitingProcessor extends MsProcessor { private Integer delay; - private Boolean enable; } diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/JSONPathExtract.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/JSONPathExtract.java new file mode 100644 index 0000000000..ec1e57e836 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/JSONPathExtract.java @@ -0,0 +1,12 @@ +package io.metersphere.sdk.dto.api.request.processors.extract; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +/** + * JSONPath提取 + */ +@Data +@JsonTypeName("JSON_PATH") +public class JSONPathExtract extends ResultMatchingExtract { +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/MsExtract.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/MsExtract.java new file mode 100644 index 0000000000..6011f083e0 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/MsExtract.java @@ -0,0 +1,31 @@ +package io.metersphere.sdk.dto.api.request.processors.extract; + +import com.fasterxml.jackson.annotation.JsonSubTypes; +import com.fasterxml.jackson.annotation.JsonTypeInfo; +import lombok.Data; + +@Data +@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, property = "extractType") +@JsonSubTypes({ + @JsonSubTypes.Type(value = RegexExtract.class), + @JsonSubTypes.Type(value = JSONPathExtract.class), + @JsonSubTypes.Type(value = XPathExtract.class) +}) +public abstract class MsExtract { + /** + * 参数名 + */ + private String paramName; + /** + * 参数类型 + */ + private String paramType; + /** + * 提取范围 + */ + private String extractScope; + /** + * 表达式 + */ + private String expression; +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/RegexExtract.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/RegexExtract.java new file mode 100644 index 0000000000..f273cb8934 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/RegexExtract.java @@ -0,0 +1,25 @@ +package io.metersphere.sdk.dto.api.request.processors.extract; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +@Data +@JsonTypeName("REGEX") +public class RegexExtract extends ResultMatchingExtract { + /** + * 表达式匹配规则 + * 值为 ExpressionRuleType + */ + private String expressionMatchingRule; + + public enum ExpressionRuleType { + /** + * 匹配表达式 + */ + EXPRESSION, + /** + * 匹配组 + */ + GROUP + } +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/ResultMatchingExtract.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/ResultMatchingExtract.java new file mode 100644 index 0000000000..6c9a4cd740 --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/ResultMatchingExtract.java @@ -0,0 +1,31 @@ +package io.metersphere.sdk.dto.api.request.processors.extract; + +import lombok.Data; + +@Data +public abstract class ResultMatchingExtract extends MsExtract { + /** + * 结果匹配规则 + * 值为 ResultMatchingRuleType + */ + private String resultMatchingRule; + /** + * 匹配第几条结果 + */ + private Integer resultMatchingRuleNum; + + public enum ResultMatchingRuleType { + /** + * 随机匹配 + */ + RANDOM, + /** + * 指定匹配 + */ + SPECIFIC, + /** + * 全部匹配 + */ + ALL + } +} diff --git a/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/XPathExtract.java b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/XPathExtract.java new file mode 100644 index 0000000000..3644c9642a --- /dev/null +++ b/backend/framework/sdk/src/main/java/io/metersphere/sdk/dto/api/request/processors/extract/XPathExtract.java @@ -0,0 +1,13 @@ +package io.metersphere.sdk.dto.api.request.processors.extract; + +import com.fasterxml.jackson.annotation.JsonTypeName; +import lombok.Data; + +/** + * XPath提取 + */ +@Data +@JsonTypeName("X_PATH") +public class XPathExtract extends MsExtract { + private String responseFormat; +} \ No newline at end of file diff --git a/backend/services/api-test/src/main/java/io/metersphere/api/util/ApiDataUtils.java b/backend/services/api-test/src/main/java/io/metersphere/api/util/ApiDataUtils.java index a37fefbb18..15e663acde 100644 --- a/backend/services/api-test/src/main/java/io/metersphere/api/util/ApiDataUtils.java +++ b/backend/services/api-test/src/main/java/io/metersphere/api/util/ApiDataUtils.java @@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.databind.json.JsonMapper; import com.fasterxml.jackson.databind.jsontype.NamedType; import com.fasterxml.jackson.databind.type.CollectionType; -import io.metersphere.sdk.dto.api.request.post.processors.MsPostJSR223Processor; import io.metersphere.sdk.dto.api.request.sampler.MsDebugSampler; import io.metersphere.sdk.exception.MSException; @@ -32,7 +31,6 @@ public class ApiDataUtils { static { // 默认内置的子组件 - namedTypes.add(new NamedType(MsPostJSR223Processor.class, MsPostJSR223Processor.class.getSimpleName())); namedTypes.add(new NamedType(MsDebugSampler.class, MsDebugSampler.class.getSimpleName())); setObjectMapper(objectMapper); 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 a3e10c7b47..4a2fde05cb 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 @@ -4,15 +4,19 @@ import io.metersphere.sdk.dto.api.request.http.body.Body; import io.metersphere.api.dto.definition.HttpResponse; import io.metersphere.api.util.ApiDataUtils; import io.metersphere.plugin.api.spi.AbstractMsTestElement; +import io.metersphere.sdk.constants.MsAssertionCondition; +import io.metersphere.sdk.dto.api.request.assertion.*; +import io.metersphere.sdk.dto.api.request.assertion.body.*; import io.metersphere.sdk.dto.api.request.http.*; import io.metersphere.sdk.dto.api.request.http.auth.BasicAuth; import io.metersphere.sdk.dto.api.request.http.auth.DigestAuth; import io.metersphere.sdk.dto.api.request.http.auth.HTTPAuth; import io.metersphere.sdk.dto.api.request.http.auth.NoAuth; import io.metersphere.sdk.dto.api.request.http.body.*; -import io.metersphere.sdk.dto.api.request.processors.SQLProcessor; -import io.metersphere.sdk.dto.api.request.processors.ScriptProcessor; -import io.metersphere.sdk.dto.api.request.processors.TimeWaitingProcessor; +import io.metersphere.sdk.dto.api.request.processors.*; +import io.metersphere.sdk.dto.api.request.processors.extract.JSONPathExtract; +import io.metersphere.sdk.dto.api.request.processors.extract.RegexExtract; +import io.metersphere.sdk.dto.api.request.processors.extract.XPathExtract; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; @@ -127,7 +131,7 @@ public class MsHTTPElementTest { sqlProcessor.setScript("script"); sqlProcessor.setEnable(true); sqlProcessor.setDataSourceId("dataSourceId"); - KeyValueParam keyValueParam = new KeyValueParam(); + KeyValueEnableParam keyValueParam = new KeyValueEnableParam(); keyValueParam.setKey("key"); keyValueParam.setValue("value"); sqlProcessor.setVariables(List.of(keyValueParam)); @@ -141,8 +145,83 @@ public class MsHTTPElementTest { timeWaitingProcessor.setEnable(true); processors.add(timeWaitingProcessor); - msHTTPElement.setPreProcessors(processors); - msHTTPElement.setPostProcessors(processors); + CommonScriptProcessor commonScriptProcessor = new CommonScriptProcessor(); + commonScriptProcessor.setEnable(true); + commonScriptProcessor.setScriptId("11111"); + KeyValueParam commonScriptParam = new KeyValueParam(); + commonScriptParam.setKey("11"); + commonScriptParam.setValue("11"); + commonScriptProcessor.setParams(List.of(commonScriptParam)); + processors.add(commonScriptProcessor); + + ExtractPostProcessor extractPostProcessor = new ExtractPostProcessor(); + RegexExtract regexExtract = new RegexExtract(); + regexExtract.setExpressionMatchingRule(""); + JSONPathExtract jsonPathExtract = new JSONPathExtract(); + jsonPathExtract.setExpression(""); + XPathExtract xPathExtract = new XPathExtract(); + xPathExtract.setExpression(""); + extractPostProcessor.setExtractors(List.of(regexExtract, jsonPathExtract, xPathExtract)); + processors.add(extractPostProcessor); + + MsProcessorConfig msProcessorConfig = new MsProcessorConfig(); + msProcessorConfig.setProcessors(processors); + + msHTTPElement.setPreProcessorConfig(msProcessorConfig); + msHTTPElement.setPostProcessorConfig(msProcessorConfig); + String json = ApiDataUtils.toJSONString(msHTTPElement); + Assertions.assertNotNull(json); + Assertions.assertEquals(ApiDataUtils.parseObject(json, AbstractMsTestElement.class), msHTTPElement); + } + + @Test + public void msAssertionTest() { + + MsHTTPElement msHTTPElement = getMsHttpElement(); + + List assertions = new ArrayList<>(); + + ResponseCodeAssertion responseCodeAssertion = new ResponseCodeAssertion(); + responseCodeAssertion.setCondition(MsAssertionCondition.EMPTY.name()); + responseCodeAssertion.setValue("value"); + responseCodeAssertion.setName("name"); + assertions.add(responseCodeAssertion); + + ResponseHeaderAssertion responseHeaderAssertion = new ResponseHeaderAssertion(); + ResponseHeaderAssertion.ResponseHeaderAssertionItem responseHeaderAssertionItem = new ResponseHeaderAssertion.ResponseHeaderAssertionItem(); + responseHeaderAssertionItem.setHeader("header"); + responseHeaderAssertionItem.setValue("value"); + responseHeaderAssertionItem.setCondition(MsAssertionCondition.EMPTY.name()); + responseHeaderAssertion.setAssertions(List.of(responseHeaderAssertionItem)); + assertions.add(responseHeaderAssertion); + + ResponseBodyAssertion responseBodyAssertion = new ResponseBodyAssertion(); + responseBodyAssertion.setAssertionType(MsBodyAssertionType.JSON_PATH.name()); + RegexAssertion regexAssertion = new RegexAssertion(); + regexAssertion.setAssertions(List.of(new RegexAssertionItem())); + responseBodyAssertion.setRegexAssertion(regexAssertion); + responseBodyAssertion.setDocumentAssertion(new DocumentAssertion()); + responseBodyAssertion.setJsonPathAssertion(new JSONPathAssertion()); + responseBodyAssertion.setXpathAssertion(new XPathAssertion()); + assertions.add(responseBodyAssertion); + + ResponseTimeAssertion responseTimeAssertion = new ResponseTimeAssertion(); + responseTimeAssertion.setMaxResponseTime(1000L); + responseTimeAssertion.setEnable(true); + responseTimeAssertion.setName("aa"); + assertions.add(responseTimeAssertion); + + ScriptAssertion scriptAssertion = new ScriptAssertion(); + scriptAssertion.setCommonScriptId("1111"); + scriptAssertion.setContent("1111"); + scriptAssertion.setDescription("1111"); + scriptAssertion.setName("1111"); + assertions.add(scriptAssertion); + + MsAssertionConfig msAssertionConfig = new MsAssertionConfig(); + msAssertionConfig.setEnableGlobal(false); + msAssertionConfig.setAssertions(assertions); + msHTTPElement.setAssertionConfig(msAssertionConfig); String json = ApiDataUtils.toJSONString(msHTTPElement); Assertions.assertNotNull(json); Assertions.assertEquals(ApiDataUtils.parseObject(json, AbstractMsTestElement.class), msHTTPElement); diff --git a/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java b/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java index c9d1dc3fbb..2cae7aa1ac 100644 --- a/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java +++ b/backend/services/api-test/src/test/java/io/metersphere/api/controller/PluginSubTypeTests.java @@ -5,19 +5,19 @@ import io.metersphere.api.util.ApiDataUtils; import io.metersphere.plugin.api.dto.TestElementDTO; import io.metersphere.plugin.api.spi.AbstractMsTestElement; import io.metersphere.plugin.api.spi.MsTestElement; +import io.metersphere.sdk.dto.api.request.http.MsHTTPElement; import io.metersphere.sdk.dto.api.request.logic.controller.MsLoopController; -import io.metersphere.sdk.dto.api.request.post.processors.MsPostJSR223Processor; -import io.metersphere.sdk.dto.api.request.sampler.MsDebugSampler; import io.metersphere.system.base.BaseApiPluginTestService; import io.metersphere.system.service.PluginLoadService; -import io.metersphere.system.uid.IDGenerator; import jakarta.annotation.Resource; import org.junit.jupiter.api.*; import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; import org.springframework.boot.test.context.SpringBootTest; +import java.io.InputStream; import java.util.LinkedList; import java.util.List; +import java.util.function.Consumer; @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) @@ -33,34 +33,14 @@ public class PluginSubTypeTests { @Test @Order(0) - public void pluginSubTypeTest() throws Exception { - MsDebugSampler debugSampler = new MsDebugSampler(); - debugSampler.setName("测试DebugSampler"); - debugSampler.setUuid(IDGenerator.nextStr()); - LinkedList hashTree = new LinkedList<>(); - hashTree.add(debugSampler); - MsPostJSR223Processor msjsr223Processor = new MsPostJSR223Processor(); - msjsr223Processor.setName("测试jsr223"); - msjsr223Processor.setJsrEnable(true); - msjsr223Processor.setChildren(hashTree); - - String json = ApiDataUtils.toJSONString(msjsr223Processor); - Assertions.assertNotNull(json); - TestElementDTO testElementDTO = ApiDataUtils.parseObject(json, TestElementDTO.class); - Assertions.assertNotNull(testElementDTO); - } - - @Test - @Order(1) public void resolverTest() throws Exception { - // ApiDataUtils.setResolver(MsLoopController.class); List namedTypes = new LinkedList<>(); namedTypes.add(new NamedType(MsLoopController.class, MsLoopController.class.getSimpleName())); ApiDataUtils.setResolver(namedTypes); } @Test - @Order(2) + @Order(1) public void newPluginSubTypeTest() throws Exception { MsLoopController loopController = new MsLoopController(); loopController.setName("测试loopController"); @@ -72,26 +52,7 @@ public class PluginSubTypeTests { } @Test - @Order(3) - public void retrySubTypeTest() throws Exception { - MsDebugSampler debugSampler = new MsDebugSampler(); - debugSampler.setName("测试DebugSampler"); - debugSampler.setUuid(IDGenerator.nextStr()); - LinkedList hashTree = new LinkedList<>(); - hashTree.add(debugSampler); - MsPostJSR223Processor msjsr223Processor = new MsPostJSR223Processor(); - msjsr223Processor.setName("测试jsr223"); - msjsr223Processor.setJsrEnable(true); - msjsr223Processor.setChildren(hashTree); - - String json = ApiDataUtils.toJSONString(msjsr223Processor); - Assertions.assertNotNull(json); - TestElementDTO testElementDTO = ApiDataUtils.parseObject(json, TestElementDTO.class); - Assertions.assertNotNull(testElementDTO); - } - - @Test - @Order(4) + @Order(2) public void jdbcPluginSubTypeTest() throws Exception { // 上传 jdbc 插件 baseApiPluginTestService.addJdbcPlugin(); @@ -110,4 +71,42 @@ public class PluginSubTypeTests { AbstractMsTestElement testElementDTO = ApiDataUtils.parseObject(jdbcJson, AbstractMsTestElement.class); Assertions.assertNotNull(testElementDTO); } + + @Test + @Order(3) + public void testApiDataUtils() throws Exception { + // 校验异常,增加覆盖率 + Assertions.assertTrue(isFuncSuccess((v) -> { + InputStream in = null; + ApiDataUtils.parseObject(in, AbstractMsTestElement.class); + })); + Assertions.assertTrue(isFuncSuccess((v) -> ApiDataUtils.parseObject("{"))); + Assertions.assertTrue(isFuncSuccess((v) -> ApiDataUtils.parseArray(null, AbstractMsTestElement.class))); + + ApiDataUtils.setResolver(MsHTTPElement.class); + // 检验 parseArray + String msHttpJson = """ + [{ + "polymorphicName": "MsHTTPElement", + "test": "测试MsHTTPElement" + }] + """; + ApiDataUtils.parseArray(msHttpJson, AbstractMsTestElement.class); + } + + /** + * 判断函数是否抛出异常 + * + * @param func + * @return + * @throws Exception + */ + public boolean isFuncSuccess(Consumer func) { + try { + func.accept(""); + } catch (Exception e) { + return true; + } + return false; + } }