From b7af640080052aa3e4af612bd93192da9dee2823 Mon Sep 17 00:00:00 2001 From: q4speed Date: Wed, 28 Oct 2020 17:25:41 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):=20?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E8=84=9A=E6=9C=AC=E6=96=AD=E8=A8=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../scenario/assertions/AssertionJSR223.java | 20 ++ .../scenario/assertions/AssertionType.java | 1 + .../dto/scenario/assertions/Assertions.java | 1 + .../assertion/ApiAssertionDuration.vue | 4 +- .../assertion/ApiAssertionJsonPath.vue | 4 +- .../assertion/ApiAssertionJsr223.vue | 261 ++++++++++++++++++ .../assertion/ApiAssertionRegex.vue | 4 +- .../components/assertion/ApiAssertionText.vue | 4 +- .../components/assertion/ApiAssertions.vue | 8 +- .../assertion/ApiAssertionsEdit.vue | 100 ++++--- .../components/processor/Jsr233Processor.vue | 241 ++++++++-------- .../business/components/api/test/model/JMX.js | 6 + .../api/test/model/ScenarioModel.js | 57 +++- .../common/components/MsCodeEdit.vue | 3 +- frontend/src/i18n/en-US.js | 14 +- frontend/src/i18n/zh-CN.js | 15 +- frontend/src/i18n/zh-TW.js | 8 +- 17 files changed, 565 insertions(+), 186 deletions(-) create mode 100644 backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionJSR223.java create mode 100644 frontend/src/business/components/api/test/components/assertion/ApiAssertionJsr223.vue diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionJSR223.java b/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionJSR223.java new file mode 100644 index 0000000000..e492a46a59 --- /dev/null +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionJSR223.java @@ -0,0 +1,20 @@ +package io.metersphere.api.dto.scenario.assertions; + +import lombok.Data; +import lombok.EqualsAndHashCode; + +@EqualsAndHashCode(callSuper = true) +@Data +public class AssertionJSR223 extends AssertionType { + private String variable; + private String operator; + private String value; + private String desc; + private String name; + private String script; + private String language; + + public AssertionJSR223() { + setType(AssertionType.JSR223); + } +} diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionType.java b/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionType.java index 443ea969a9..207c960234 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionType.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/AssertionType.java @@ -7,6 +7,7 @@ public class AssertionType { 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"; private String type; diff --git a/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/Assertions.java b/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/Assertions.java index d910c0af13..ecbe07467b 100644 --- a/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/Assertions.java +++ b/backend/src/main/java/io/metersphere/api/dto/scenario/assertions/Assertions.java @@ -8,5 +8,6 @@ import java.util.List; public class Assertions { private List regex; private List jsonPath; + private List jsr223; private AssertionDuration duration; } diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue index c2de8c0adf..8e4865ecda 100644 --- a/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue +++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionDuration.vue @@ -7,7 +7,9 @@ - Add + + {{ $t('api_test.request.assertions.add') }} + diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionJsonPath.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionJsonPath.vue index 56b3a2408a..e17aed7471 100644 --- a/frontend/src/business/components/api/test/components/assertion/ApiAssertionJsonPath.vue +++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionJsonPath.vue @@ -11,7 +11,9 @@ - Add + + {{ $t('api_test.request.assertions.add') }} + diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionJsr223.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionJsr223.vue new file mode 100644 index 0000000000..a5a5bc7e66 --- /dev/null +++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionJsr223.vue @@ -0,0 +1,261 @@ + + + + + diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue index 40a06e7ddd..b7da96c490 100644 --- a/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue +++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionRegex.vue @@ -21,7 +21,9 @@ - Add + + {{ $t('api_test.request.assertions.add') }} + diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionText.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionText.vue index d3c6c28761..15ced9e0ef 100644 --- a/frontend/src/business/components/api/test/components/assertion/ApiAssertionText.vue +++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionText.vue @@ -29,7 +29,9 @@ - Add + + {{ $t('api_test.request.assertions.add') }} + diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertions.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertions.vue index de285e519c..0fbdb5f426 100644 --- a/frontend/src/business/components/api/test/components/assertion/ApiAssertions.vue +++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertions.vue @@ -9,6 +9,7 @@ + @@ -17,7 +18,10 @@ - Add + + + {{ $t('api_test.request.assertions.add') }} + @@ -33,11 +37,13 @@ import {ASSERTION_TYPE, Assertions} from "../../model/ScenarioModel"; import MsApiAssertionsEdit from "./ApiAssertionsEdit"; import MsApiAssertionJsonPath from "./ApiAssertionJsonPath"; + import MsApiAssertionJsr223 from "@/business/components/api/test/components/assertion/ApiAssertionJsr223"; export default { name: "MsApiAssertions", components: { + MsApiAssertionJsr223, MsApiAssertionJsonPath, MsApiAssertionsEdit, MsApiAssertionDuration, MsApiAssertionRegex, MsApiAssertionText}, diff --git a/frontend/src/business/components/api/test/components/assertion/ApiAssertionsEdit.vue b/frontend/src/business/components/api/test/components/assertion/ApiAssertionsEdit.vue index 722aae8eb4..0b880a76e1 100644 --- a/frontend/src/business/components/api/test/components/assertion/ApiAssertionsEdit.vue +++ b/frontend/src/business/components/api/test/components/assertion/ApiAssertionsEdit.vue @@ -2,81 +2,99 @@
- {{$t("api_test.request.assertions.regex")}} + {{ $t("api_test.request.assertions.regex") }}
- +
- {{'JSONPath'}} + {{ 'JSONPath' }}
- + +
+
+ +
+
+ {{ $t("api_test.request.assertions.script") }} +
+
+
- {{$t("api_test.request.assertions.response_time")}} + {{ $t("api_test.request.assertions.response_time") }}
- +
diff --git a/frontend/src/business/components/api/test/components/processor/Jsr233Processor.vue b/frontend/src/business/components/api/test/components/processor/Jsr233Processor.vue index a1af2e7e68..fd86a3a750 100644 --- a/frontend/src/business/components/api/test/components/processor/Jsr233Processor.vue +++ b/frontend/src/business/components/api/test/components/processor/Jsr233Processor.vue @@ -1,17 +1,21 @@ diff --git a/frontend/src/business/components/api/test/model/JMX.js b/frontend/src/business/components/api/test/model/JMX.js index 3a10643de3..1540aad191 100644 --- a/frontend/src/business/components/api/test/model/JMX.js +++ b/frontend/src/business/components/api/test/model/JMX.js @@ -501,6 +501,12 @@ export class JSR223Processor extends DefaultTestElement { } } +export class JSR223Assertion extends JSR223Processor { + constructor(testName, processor) { + super('JSR223Assertion', 'TestBeanGUI', 'JSR223Assertion', testName, processor) + } +} + export class JSR223PreProcessor extends JSR223Processor { constructor(testName, processor) { super('JSR223PreProcessor', 'TestBeanGUI', 'JSR223PreProcessor', testName, processor) diff --git a/frontend/src/business/components/api/test/model/ScenarioModel.js b/frontend/src/business/components/api/test/model/ScenarioModel.js index 5865527d6c..d8a11eb90c 100644 --- a/frontend/src/business/components/api/test/model/ScenarioModel.js +++ b/frontend/src/business/components/api/test/model/ScenarioModel.js @@ -25,7 +25,7 @@ import { ThreadGroup, XPath2Extractor, IfController as JMXIfController, - ConstantTimer as JMXConstantTimer, TCPSampler, + ConstantTimer as JMXConstantTimer, TCPSampler, JSR223Assertion, } from "./JMX"; import Mock from "mockjs"; import {funcFilters} from "@/common/js/func-filter"; @@ -94,7 +94,8 @@ export const ASSERTION_TYPE = { TEXT: "Text", REGEX: "Regex", JSON_PATH: "JSON", - DURATION: "Duration" + DURATION: "Duration", + JSR223: "JSR223", } export const ASSERTION_REGEX_SUBJECT = { @@ -716,16 +717,34 @@ export class KeyValue extends BaseConfig { } } +export class BeanShellProcessor extends BaseConfig { + constructor(options) { + super(); + this.script = undefined; + this.set(options); + } +} + +export class JSR223Processor extends BaseConfig { + constructor(options) { + super(); + this.script = undefined; + this.language = "beanshell"; + this.set(options); + } +} + export class Assertions extends BaseConfig { constructor(options) { super(); this.text = []; this.regex = []; this.jsonPath = []; + this.jsr223 = []; this.duration = undefined; this.set(options); - this.sets({text: Text, regex: Regex, jsonPath: JSONPath}, options); + this.sets({text: Text, regex: Regex, jsonPath: JSONPath, jsr223: AssertionJSR223}, options); } initOptions(options) { @@ -742,22 +761,23 @@ export class AssertionType extends BaseConfig { } } -export class BeanShellProcessor extends BaseConfig { +export class AssertionJSR223 extends AssertionType { constructor(options) { - super(); - this.script = undefined; - this.set(options); - } -} + super(ASSERTION_TYPE.JSR223); + this.variable = undefined; + this.operator = undefined; + this.value = undefined; + this.desc = undefined; - -export class JSR223Processor extends BaseConfig { - constructor(options) { - super(); + this.name = undefined; this.script = undefined; this.language = "beanshell"; this.set(options); } + + isValid() { + return !!this.script && !!this.language; + } } export class Text extends AssertionType { @@ -1402,6 +1422,12 @@ class JMXGenerator { }) } + if (assertions.jsr223.length > 0) { + assertions.jsr223.filter(this.filter).forEach(item => { + httpSamplerProxy.put(this.getJSR223Assertion(item)); + }) + } + if (assertions.duration.isValid()) { let name = "Response In Time: " + assertions.duration.value httpSamplerProxy.put(new DurationAssertion(name, assertions.duration.value)); @@ -1413,6 +1439,11 @@ class JMXGenerator { return new JSONPathAssertion(name, jsonPath); } + getJSR223Assertion(item) { + let name = item.desc; + return new JSR223Assertion(name, item); + } + getResponseAssertion(regex) { let name = regex.description; let type = JMX_ASSERTION_CONDITION.CONTAINS; // 固定用Match,自己写正则 diff --git a/frontend/src/business/components/common/components/MsCodeEdit.vue b/frontend/src/business/components/common/components/MsCodeEdit.vue index 0d755155a5..02d6c870fe 100644 --- a/frontend/src/business/components/common/components/MsCodeEdit.vue +++ b/frontend/src/business/components/common/components/MsCodeEdit.vue @@ -1,5 +1,5 @@