fix (接口测试): 修复文档断言长度校验问题

--bug=1008114 --user=赵勇 【接口定义】-编辑接口-添加json文档断言长度等于/不等于 内容校验错误 https://www.tapd.cn/55049933/s/1073003
This commit is contained in:
fit2-zhao 2021-11-23 14:32:27 +08:00 committed by fit2-zhao
parent 9200595458
commit df492f8957
1 changed files with 15 additions and 14 deletions

View File

@ -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<DecimalFormat> 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;
}
}