From df492f89575ebc58135bd3bcabea6d0c5c53c9a5 Mon Sep 17 00:00:00 2001 From: fit2-zhao Date: Tue, 23 Nov 2021 14:32:27 +0800 Subject: [PATCH] =?UTF-8?q?fix=20(=E6=8E=A5=E5=8F=A3=E6=B5=8B=E8=AF=95):?= =?UTF-8?q?=20=E4=BF=AE=E5=A4=8D=E6=96=87=E6=A1=A3=E6=96=AD=E8=A8=80?= =?UTF-8?q?=E9=95=BF=E5=BA=A6=E6=A0=A1=E9=AA=8C=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --bug=1008114 --user=赵勇 【接口定义】-编辑接口-添加json文档断言长度等于/不等于 内容校验错误 https://www.tapd.cn/55049933/s/1073003 --- .../assertions/document/DocumentUtils.java | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/document/DocumentUtils.java b/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/document/DocumentUtils.java index bb14fc2266..71ad3bda99 100644 --- a/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/document/DocumentUtils.java +++ b/backend/src/main/java/io/metersphere/api/dto/definition/request/assertions/document/DocumentUtils.java @@ -19,7 +19,7 @@ public class DocumentUtils { boolean isTrue = true; if (CollectionUtils.isNotEmpty(elementCondition.getConditions())) { for (Condition item : elementCondition.getConditions()) { - String expectedValue = ifValue(item.getValue()); + String expectedValue = item.getValue() != null ? item.getValue().toString() : ""; String resValue = objectToString(subj, decimalFormatter); switch (item.getKey()) { case "value_eq": @@ -32,16 +32,16 @@ public class DocumentUtils { isTrue = StringUtils.contains(resValue, expectedValue); break; case "length_eq": - isTrue = getLength(subj, decimalFormatter) == getLength(item.getValue(), decimalFormatter); + isTrue = getLength(subj, decimalFormatter) == numberOf(item.getValue()); break; case "length_not_eq": - isTrue = getLength(subj, decimalFormatter) != getLength(item.getValue(), decimalFormatter); + isTrue = getLength(subj, decimalFormatter) != numberOf(item.getValue()); break; case "length_gt": - isTrue = getLength(subj, decimalFormatter) < getLength(item.getValue(), decimalFormatter); + isTrue = getLength(subj, decimalFormatter) > numberOf(item.getValue()); break; case "length_lt": - isTrue = getLength(subj, decimalFormatter) > getLength(item.getValue(), decimalFormatter); + isTrue = getLength(subj, decimalFormatter) < numberOf(item.getValue()); break; case "regular": Pattern pattern = JMeterUtils.getPatternCache().getPattern(expectedValue); @@ -69,7 +69,6 @@ public class DocumentUtils { } else { str = ((DecimalFormat) decimalFormatter.get()).format(subj); } - return str; } @@ -84,13 +83,6 @@ public class DocumentUtils { return 0; } - private static String ifValue(Object value) { - if (value != null) { - return value.toString(); - } - return ""; - } - private static int getLength(Object value, ThreadLocal decimalFormatter) { if (value != null) { if (value instanceof Map) { @@ -106,6 +98,16 @@ public class DocumentUtils { return 0; } + private static long numberOf(Object value) { + if (value != null) { + try { + return Long.parseLong(value.toString()); + } catch (Exception e) { + return 0; + } + } + return 0; + } public static String documentMsg(Object resValue, String condition) { String msg = ""; @@ -125,5 +127,4 @@ public class DocumentUtils { } return msg; } - }