From 3d2e0362c823a159d92e17634704296138d9225e Mon Sep 17 00:00:00 2001 From: song-tianyang Date: Tue, 21 Dec 2021 12:56:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(Mock=E6=B5=8B=E8=AF=95):=20=E8=A7=A3?= =?UTF-8?q?=E5=86=B3Mock=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95=E6=97=B6?= =?UTF-8?q?=E9=83=A8=E5=88=86rest=E5=8F=82=E6=95=B0=E6=97=A0=E6=B3=95?= =?UTF-8?q?=E5=8C=B9=E9=85=8D=E7=9A=84=E7=BC=BA=E9=99=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1009070 --user=宋天阳 【接口测试】mock测试,rest参数匹配失败 https://www.tapd.cn/55049933/s/1084084 --- .../java/io/metersphere/api/dto/mock/MockApiUtils.java | 9 +-------- .../io/metersphere/api/service/MockConfigService.java | 6 ++++-- 2 files changed, 5 insertions(+), 10 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java b/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java index 8c75206225..fc73959566 100644 --- a/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java +++ b/backend/src/main/java/io/metersphere/api/dto/mock/MockApiUtils.java @@ -489,14 +489,7 @@ public class MockApiUtils { return returnJson; } else if (StringUtils.startsWithIgnoreCase(request.getContentType(), "text/xml")) { String xmlString = readXml(request); - - org.json.JSONObject xmlJSONObj = XML.toJSONObject(xmlString); - String jsonStr = xmlJSONObj.toString(); - JSONObject object = null; - try { - object = JSONObject.parseObject(jsonStr); - } catch (Exception e) { - } + JSONObject object = XMLUtils.XmlToJson(xmlString); return object; } else if (StringUtils.startsWithIgnoreCase(request.getContentType(), "application/x-www-form-urlencoded")) { JSONObject object = new JSONObject(); diff --git a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java index ab46220191..7c7790d764 100644 --- a/backend/src/main/java/io/metersphere/api/service/MockConfigService.java +++ b/backend/src/main/java/io/metersphere/api/service/MockConfigService.java @@ -365,8 +365,10 @@ public class MockConfigService { if (jsonObject.containsKey("name") && jsonObject.containsKey("value")) { String headerName = jsonObject.getString("name"); String headerValue = jsonObject.getString("value"); - if (!requestHeaderMap.containsKey(headerName) || !StringUtils.equals(requestHeaderMap.get(headerName), headerValue)) { - return false; + if(StringUtils.isNotEmpty(headerName)){ + if (!requestHeaderMap.containsKey(headerName) || !StringUtils.equals(requestHeaderMap.get(headerName), headerValue)) { + return false; + } } } }