diff --git a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertionType.java b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertionType.java index c1947934f8..69ff369f4e 100644 --- a/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertionType.java +++ b/api-test/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/MsAssertionType.java @@ -11,6 +11,7 @@ public class MsAssertionType { 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/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java index af8397af2a..8d82a88a78 100644 --- a/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java +++ b/api-test/backend/src/main/java/io/metersphere/service/MsHashTreeService.java @@ -98,6 +98,15 @@ public class MsHashTreeService { private static final String RESULT_VARIABLE = "resultVariable"; private static final String ENV_Id = "environmentId"; + private final static String JSON_PATH="jsonPath"; + private final static String JSR223="jsr223"; + private final static String XPATH="xpath2"; + private final static String REGEX="regex"; + private final static String DURATION="duration"; + private final static String DOCUMENT="document"; + private final static String LABEL="label"; + private final static String SCENARIO_REF="SCENARIO-REF-STEP"; + public void setHashTree(JSONArray hashTree) { // 将引用转成复制 if (hashTree == null) { @@ -191,7 +200,7 @@ public class MsHashTreeService { List pre = ElementUtil.mergeHashTree(groupMap.get(PRE), targetGroupMap.get(PRE)); List post = ElementUtil.mergeHashTree(groupMap.get(POST), targetGroupMap.get(POST)); - List rules = ElementUtil.mergeHashTree(groupMap.get(ASSERTIONS), targetGroupMap.get(ASSERTIONS)); + List rules = mergeAssertions(groupMap.get(ASSERTIONS), targetGroupMap.get(ASSERTIONS)); List step = new LinkedList<>(); if (CollectionUtils.isNotEmpty(pre)) { step.addAll(pre); @@ -232,6 +241,68 @@ public class MsHashTreeService { return element; } + public List mergeAssertions(List sourceHashTree, List targetHashTree) { + try { + if (CollectionUtils.isNotEmpty(targetHashTree)) { + JSONObject target = targetHashTree.get(0); + + if (CollectionUtils.isNotEmpty(sourceHashTree)) { + JSONObject source = sourceHashTree.get(0); + //jsonPath + JSONArray jsonPathTar = target.optJSONArray(JSON_PATH); + JSONArray jsonPathSource = source.optJSONArray(JSON_PATH); + mergeArray(target, jsonPathTar, jsonPathSource, JSON_PATH); + //jsr223 + JSONArray jsr223Tar = target.optJSONArray(JSR223); + JSONArray jsr223Source = source.optJSONArray(JSR223); + mergeArray(target, jsr223Tar, jsr223Source, JSR223); + //xpath + JSONArray xpathTar = target.optJSONArray(XPATH); + JSONArray xpathSource = source.optJSONArray(XPATH); + mergeArray(target, xpathTar, xpathSource, XPATH); + //regex + JSONArray regexTar = target.optJSONArray(REGEX); + JSONArray regexSource = source.optJSONArray(REGEX); + mergeArray(target, regexTar, regexSource, REGEX); + //duration + JSONObject durationTar = target.optJSONObject(DURATION); + JSONObject durationSource = source.optJSONObject(DURATION); + mergeObject(target, durationTar, durationSource, DURATION); + //document + JSONObject documentTar = target.optJSONObject(DOCUMENT); + JSONObject documentSource = source.optJSONObject(DOCUMENT); + mergeObject(target, documentTar, documentSource, DOCUMENT); + sourceHashTree.remove(0); + sourceHashTree.add(target); + } + } + } catch (Exception e) { + LogUtil.error("mergeAssertions error", e); + } + return sourceHashTree; + } + + private static void mergeObject(JSONObject target, JSONObject durationTar, JSONObject durationSource, String type) { + if (durationSource != null && durationSource.has(LABEL) && + StringUtils.equals(durationSource.optString(LABEL), SCENARIO_REF)) { + durationTar = durationSource; + } + target.remove(type); + target.put(type, durationTar); + } + + private static void mergeArray(JSONObject target, JSONArray jsonArray, JSONArray source, String type) { + if (!source.isEmpty()) { + source.forEach(obj -> { + JSONObject jsonObject = (JSONObject) obj; + if (StringUtils.equals(jsonObject.optString(LABEL), SCENARIO_REF)) { + jsonArray.put(jsonObject); + } + }); + } + target.remove(type); + target.put(type, jsonArray); + } private void getCaseIds(JSONObject element, List caseIds) { if (StringUtils.equalsIgnoreCase(element.optString(REF_TYPE), CASE) && element.has(ID)) { diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionDuration.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionDuration.vue index 1bb00894f2..02312bd13f 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionDuration.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionDuration.vue @@ -3,7 +3,7 @@ - + {{ $t('api_test.request.assertions.add') }} @@ -55,6 +55,11 @@ export default { }, }, + created() { + if (this.duration && !this.duration.valid && this.duration.value === 0 && this.isReadOnly) { + this.duration.label = "SCENARIO-REF-STEP"; + } + }, methods: { add() { if (this.validate()) { diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsonPath.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsonPath.vue index 7d463bc52a..e16b1ec3a3 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsonPath.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsonPath.vue @@ -4,7 +4,7 @@ - + {{ $t('api_test.request.assertions.add') }} @@ -102,6 +102,9 @@ export default { created() { if (!this.jsonPath.option) { this.jsonPath.option = 'REGEX'; + if (this.jsonPath && this.isReadOnly) { + this.jsonPath.label = "SCENARIO-REF-STEP"; + } } this.showTip = !this.jsonPath || !this.jsonPath.expression || this.jsonPath.expression.length < 50; }, diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsr223.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsr223.vue index 9975fd2699..e96961e2c4 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsr223.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionJsr223.vue @@ -5,10 +5,10 @@ {{ assertion.desc }}
- + {{ $t('commons.edit') }} - + {{ $t('api_test.request.assertions.add') }}
@@ -19,16 +19,16 @@
- + - +
@@ -167,6 +167,11 @@ export default { }; }, + created() { + if (this.assertion.valid === undefined && this.isReadOnly) { + this.assertion.label = "SCENARIO-REF-STEP"; + } + }, methods: { add() { this.list.push(new AssertionJSR223(this.assertion)); diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionRegex.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionRegex.vue index f654276bcf..491b74c3bd 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionRegex.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionRegex.vue @@ -3,7 +3,7 @@ - + {{ $t('api_test.request.assertions.ignore_status') }} @@ -34,26 +34,26 @@ v-model="regex.enable" class="enable-switch" size="mini" - :disabled="isReadOnly" + :disabled="isReadOnly && !regex.label" style="width: 30px; margin-right: 10px" /> - + {{ $t('api_test.request.assertions.add') }} @@ -102,6 +102,9 @@ export default { }, }, created() { + if (!this.regex.description && this.isReadOnly) { + this.regex.label = "SCENARIO-REF-STEP"; + } this.showTip = !this.regex || !this.regex.description || this.regex.description.length < 80; }, methods: { diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionText.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionText.vue index 718204090c..fc415a192d 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionText.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionText.vue @@ -3,7 +3,7 @@ - + {{ $t('api_test.request.assertions.ignore_status') }} - + {{ $t('api_test.request.assertions.add') }} @@ -72,8 +72,14 @@ export default { condition: '', assumeSuccess: false, value: '', + label: '', }; }, + created() { + if (this.isReadOnly) { + this.label = 'SCENARIO-REF-STEP'; + } + }, methods: { add: function () { @@ -110,6 +116,7 @@ export default { expression: expression, description: description, assumeSuccess: this.assumeSuccess, + label: this.label, }); }, }, diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionXPath2.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionXPath2.vue index 784a395f74..9e606be2a7 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertionXPath2.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertionXPath2.vue @@ -3,7 +3,7 @@ - + {{ $t('api_test.request.assertions.add') }} @@ -67,6 +67,12 @@ export default { }, }, + created() { + if (this.xPath2.valid === undefined && this.isReadOnly) { + this.xPath2.label = "SCENARIO-REF-STEP"; + } + }, + methods: { add: function () { this.list.push(this.getXPath2()); diff --git a/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue b/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue index 81de6aeaac..eb7e8956a5 100644 --- a/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue +++ b/api-test/frontend/src/business/definition/components/assertion/ApiAssertions.vue @@ -6,7 +6,6 @@ @@ -15,7 +14,6 @@ @@ -78,12 +78,12 @@ size="mini" circle @click="remove()" - :disabled="assertions.disabled && !assertions.root" /> + :disabled="isReadOnly && !assertions.document.label && !assertions.root" /> - + diff --git a/api-test/frontend/src/business/definition/components/assertion/document/DocumentHeader.vue b/api-test/frontend/src/business/definition/components/assertion/document/DocumentHeader.vue index 16339e1bd7..718d746433 100644 --- a/api-test/frontend/src/business/definition/components/assertion/document/DocumentHeader.vue +++ b/api-test/frontend/src/business/definition/components/assertion/document/DocumentHeader.vue @@ -8,7 +8,7 @@ - + {{ $t('api_test.request.assertions.add') }} @@ -32,6 +32,11 @@ export default { default: false, }, }, + created() { + if (this.document && !this.document.originalData && !this.document.rootData && this.isReadOnly) { + this.document.label = "SCENARIO-REF-STEP"; + } + }, methods: { add() { diff --git a/api-test/frontend/src/business/definition/components/step/JmxStep.vue b/api-test/frontend/src/business/definition/components/step/JmxStep.vue index fcffc3151b..01600d447d 100644 --- a/api-test/frontend/src/business/definition/components/step/JmxStep.vue +++ b/api-test/frontend/src/business/definition/components/step/JmxStep.vue @@ -114,7 +114,7 @@ :request="request" :apiId="apiId" :draggable="true" - :is-read-only="data.disabled" + :is-read-only="request.disabled" :assertions="data" />