fix(接口测试): 修复jsonPath对空数组断言失败的缺陷
--bug=1028041 --user=王孝刚 【接口测试】github#25720,接口对空列表断言不生效&对非空列表断言失败 https://www.tapd.cn/55049933/s/1395952
This commit is contained in:
parent
a785a3fbdc
commit
08b3f4c241
|
@ -276,6 +276,7 @@ export default {
|
|||
this.debugForm.path = url.pathname;
|
||||
} else {
|
||||
this.debugForm.path = url;
|
||||
this.debugForm.url = url;
|
||||
}
|
||||
},
|
||||
getURL(urlStr) {
|
||||
|
|
|
@ -129,7 +129,6 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
|
|||
public boolean isUseRegex() {
|
||||
return getPropertyAsBoolean(ISREGEX, true);
|
||||
}
|
||||
private static final String KEY_PRE = "[]";
|
||||
|
||||
private void doAssert(String jsonString) {
|
||||
Object value = JsonPath.read(jsonString, getJsonPath());
|
||||
|
@ -213,7 +212,7 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
|
|||
}
|
||||
|
||||
for (Object subj : value.toArray()) {
|
||||
if (!StringUtils.equalsAnyIgnoreCase(getOption(), "NOT_CONTAINS", "EQUALS")) {
|
||||
if (!StringUtils.equals(getOption(), "NOT_CONTAINS")) {
|
||||
if (subj == null && this.isExpectNull() || isEquals(subj)) {
|
||||
return true;
|
||||
}
|
||||
|
@ -221,7 +220,7 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
|
|||
result.add(isEquals(subj));
|
||||
}
|
||||
}
|
||||
if (CollectionUtils.isNotEmpty(result) && StringUtils.equalsAnyIgnoreCase(getOption(), "NOT_CONTAINS", "EQUALS")) {
|
||||
if (CollectionUtils.isNotEmpty(result) && StringUtils.equals(getOption(), "NOT_CONTAINS")) {
|
||||
if (result.stream().filter(item -> item == true).collect(Collectors.toList()).size() == result.size()) {
|
||||
return true;
|
||||
} else {
|
||||
|
@ -255,9 +254,6 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
|
|||
private boolean isEquals(Object subj) {
|
||||
String str = DocumentUtils.objectToString(subj, decimalFormatter);
|
||||
if (isUseRegex()) {
|
||||
if (StringUtils.equals(str,KEY_PRE)) {
|
||||
return false;
|
||||
}
|
||||
if (USE_JAVA_REGEX) {
|
||||
return JMeterUtils.compilePattern(getExpectedValue()).matcher(str).matches();
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue