fix(接口定义): 修复xml断言相关问题的缺陷

--bug=1018082 --user=王孝刚 【接口测试】文档结构断言-xml-跟随接口定义,断言没有生效
https://www.tapd.cn/55049933/s/1264707
--bug=1018081 --user=王孝刚
【接口测试】接口文档断言 - 跟随接口定义,关闭后重新打开才显示
https://www.tapd.cn/55049933/s/1264710
--bug=1018080 --user=王孝刚
【接口测试】接口文档结构断言-xml格式,删除、添加断言内容报错
https://www.tapd.cn/55049933/s/1264715
--bug=1018078 --user=王孝刚
【接口测试】xml文档结构断言错误,并且关闭后再打开就没有了 https://www.tapd.cn/55049933/s/1264740
This commit is contained in:
wxg0103 2022-10-17 17:38:02 +08:00 committed by f2c-ci-robot[bot]
parent 80e2a7fed0
commit 6a7e7c5386
6 changed files with 22 additions and 24 deletions

View File

@ -3,11 +3,11 @@ package io.metersphere.commons.utils;
import io.metersphere.api.dto.definition.request.assertions.document.DocumentElement; import io.metersphere.api.dto.definition.request.assertions.document.DocumentElement;
import io.metersphere.commons.constants.PropertyConstant; import io.metersphere.commons.constants.PropertyConstant;
import io.metersphere.utils.DocumentUtils; import io.metersphere.utils.DocumentUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import net.sf.json.util.JSONTokener; import net.sf.json.util.JSONTokener;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
import org.dom4j.Element; import org.dom4j.Element;
import org.json.JSONArray;
import org.json.JSONObject;
import org.json.XML; import org.json.XML;
import java.util.LinkedList; import java.util.LinkedList;
@ -71,6 +71,7 @@ public class JSONToDocumentUtil {
JSONArray array = JSONUtil.parseArray(json); JSONArray array = JSONUtil.parseArray(json);
jsonDataFormatting(array, children); jsonDataFormatting(array, children);
} else { } else {
roots.add(new DocumentElement().newRoot(PropertyConstant.ARRAY, children));
JSONArray array = JSONUtil.parseArray(json); JSONArray array = JSONUtil.parseArray(json);
jsonDataFormatting(array, roots); jsonDataFormatting(array, roots);
} }
@ -80,6 +81,7 @@ public class JSONToDocumentUtil {
JSONObject object = JSONUtil.parseObject(json); JSONObject object = JSONUtil.parseObject(json);
jsonDataFormatting(object, children); jsonDataFormatting(object, children);
} else { } else {
roots.add(new DocumentElement().newRoot(PropertyConstant.OBJECT, children));
JSONObject object = JSONUtil.parseObject(json); JSONObject object = JSONUtil.parseObject(json);
jsonDataFormatting(object, roots); jsonDataFormatting(object, roots);
} }

View File

@ -235,7 +235,11 @@ export function mergeRequestDocumentData(request) {
if (index !== -1) { if (index !== -1) {
if (request.hashTree[index].document && request.hashTree[index].document.originalData && request.hashTree[index].document.tableData.size && request.hashTree[index].document.tableData.size !== 0) { if (request.hashTree[index].document && request.hashTree[index].document.originalData && request.hashTree[index].document.tableData.size && request.hashTree[index].document.tableData.size !== 0) {
mergeDocumentData(request.hashTree[index].document.originalData, request.hashTree[index].document.tableData); mergeDocumentData(request.hashTree[index].document.originalData, request.hashTree[index].document.tableData);
if (request.hashTree[index].document.type === 'json') {
request.hashTree[index].document.data.json = request.hashTree[index].document.originalData; request.hashTree[index].document.data.json = request.hashTree[index].document.originalData;
} else {
request.hashTree[index].document.data.xml = request.hashTree[index].document.originalData;
}
} }
} }
} }

View File

@ -198,7 +198,7 @@ export default {
if (this.document.type === "JSON") { if (this.document.type === "JSON") {
this.document.data.json = this.originalData; this.document.data.json = this.originalData;
} else if (this.document.type === "XML") { } else if (this.document.type === "XML") {
this.document.data.xml = this.tableData; this.document.data.xml = this.originalData;
} }
}, },
tableDataList(data) { tableDataList(data) {
@ -298,20 +298,19 @@ export default {
changeData() { changeData() {
if (this.document.data) { if (this.document.data) {
this.tableData = []; this.tableData = [];
if (this.document.type === "JSON") { if (this.document.type === 'JSON') {
this.document.data.jsonFollowAPI = this.checked ? this.apiId : ""; this.document.data.jsonFollowAPI = this.checked ? this.apiId : "";
if (this.document.data.jsonFollowAPI) { if (this.document.data.jsonFollowAPI) {
this.getDocument(); this.getDocument();
} else { } else {
this.tableDataList(this.document.data.json); this.tableDataList(this.document.data.json);
} }
} else if (this.document.type === 'XML') {
} else if (this.document.type === "XML") {
this.document.data.xmlFollowAPI = this.checked ? this.apiId : ""; this.document.data.xmlFollowAPI = this.checked ? this.apiId : "";
if (this.document.data.xmlFollowAPI) { if (this.document.data.xmlFollowAPI) {
this.getDocument(); this.getDocument();
} else { } else {
this.tableData = this.document.data.xml; this.tableDataList(this.document.data.xml);
} }
} }
this.reload(); this.reload();

View File

@ -122,7 +122,7 @@
:showScript="true" :showScript="true"
:headers="apiCase.request.headers " :headers="apiCase.request.headers "
:response="apiCase.responseData" :response="apiCase.responseData"
:request="apiCase.request" v-if="api.protocol==='HTTP'"/> :request="apiCase.request" :case-id="apiCase.apiDefinitionId" v-if="api.protocol==='HTTP'"/>
<tcp-format-parameters <tcp-format-parameters
:showScript="true" :showScript="true"
:show-pre-script="true" :show-pre-script="true"
@ -215,18 +215,11 @@
<script> <script>
import {citedScenarioCount, deleteToGc, editApiCase, editFollowsByParam, getApiCaseFollow} from "@/api/api-test-case"; import {citedScenarioCount, deleteToGc, editApiCase, editFollowsByParam, getApiCaseFollow} from "@/api/api-test-case";
import {createDefinition} from "@/api/definition"; import {createDefinition} from "@/api/definition";
import {relationGet} from "@/api/xpack"; import {relationGet, updateRuleRelation} from "@/api/xpack";
import {updateRuleRelation} from "@/api/xpack";
import {getUUID} from "metersphere-frontend/src/utils"; import {getUUID} from "metersphere-frontend/src/utils";
import { import {getCurrentProjectID, getCurrentUser} from "metersphere-frontend/src/utils/token";
getCurrentProjectID, import {hasLicense, hasPermission} from "metersphere-frontend/src/utils/permission";
getCurrentUser import {_getBodyUploadFiles, mergeRequestDocumentData} from "@/business/definition/api-definition";
} from "metersphere-frontend/src/utils/token";
import {
hasLicense,
hasPermission
} from "metersphere-frontend/src/utils/permission";
import {_getBodyUploadFiles} from "@/business/definition/api-definition";
import {API_METHOD_COLOUR, API_STATUS, PRIORITY} from "../../model/JsonData"; import {API_METHOD_COLOUR, API_STATUS, PRIORITY} from "../../model/JsonData";
import MsTag from "metersphere-frontend/src/components/MsTag"; import MsTag from "metersphere-frontend/src/components/MsTag";
import MsTipButton from "metersphere-frontend/src/components/MsTipButton"; import MsTipButton from "metersphere-frontend/src/components/MsTipButton";
@ -244,7 +237,6 @@ import ShowMoreBtn from "@/business/commons/ShowMoreBtn";
import MsChangeHistory from "@/business/history/ApiHistory"; import MsChangeHistory from "@/business/history/ApiHistory";
import {TYPE_TO_C} from "@/business/automation/scenario/Setting"; import {TYPE_TO_C} from "@/business/automation/scenario/Setting";
import ApiCaseHeader from "./ApiCaseHeader"; import ApiCaseHeader from "./ApiCaseHeader";
import {mergeRequestDocumentData} from "@/business/definition/api-definition";
import {deepClone} from "metersphere-frontend/src/utils/tableUtils"; import {deepClone} from "metersphere-frontend/src/utils/tableUtils";
import {useApiStore} from "@/store"; import {useApiStore} from "@/store";

View File

@ -163,7 +163,7 @@
</span> </span>
<ms-jmx-step <ms-jmx-step
:request="request" :request="request"
:apiId="request.id" :apiId="caseId || request.id"
:scenarioId="scenarioId" :scenarioId="scenarioId"
:response="response" :response="response"
@reload="reloadBody" @reload="reloadBody"
@ -215,6 +215,7 @@ export default {
props: { props: {
method: String, method: String,
request: {}, request: {},
caseId: String,
response: {}, response: {},
definitionTest: { definitionTest: {
type: Boolean, type: Boolean,

View File

@ -197,7 +197,7 @@ export default {
if (this.document.type === "JSON") { if (this.document.type === "JSON") {
this.document.data.json = this.originalData; this.document.data.json = this.originalData;
} else if (this.document.type === "XML") { } else if (this.document.type === "XML") {
this.document.data.xml = this.tableData; this.document.data.xml = this.originalData;
} }
}, },
tableDataList(data) { tableDataList(data) {
@ -310,7 +310,7 @@ export default {
if (this.document.data.xmlFollowAPI) { if (this.document.data.xmlFollowAPI) {
this.getDocument(); this.getDocument();
} else { } else {
this.tableData = this.document.data.xml; this.tableDataList(this.document.data.xml);
} }
} }
this.reload(); this.reload();