feat(接口自动化): 断言规则增加大于小于 #1002278

【【github#5188】[FEATURE]JSONpath 断言提供大于和小于功能 #5188】 https://www.tapd.cn/55049933/prong/stories/view/1155049933001002278
This commit is contained in:
fit2-zhao 2021-08-04 12:15:47 +08:00 committed by fit2-zhao
parent 0bec34f980
commit b7dfe536a7
2 changed files with 31 additions and 0 deletions

View File

@ -126,6 +126,12 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
case "NOT_EQUALS": case "NOT_EQUALS":
msg = "Value not equals to be '%s', but found '%s'"; msg = "Value not equals to be '%s', but found '%s'";
break; break;
case "GT":
msg = "Value > '%s', but found '%s'";
break;
case "LT":
msg = "Value < '%s', but found '%s'";
break;
} }
} else { } else {
msg = "Value expected to be '%s', but found '%s'"; msg = "Value expected to be '%s', but found '%s'";
@ -153,6 +159,22 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
} }
} }
private boolean isGt(String v1, String v2) {
try {
return Long.parseLong(v1) > Long.parseLong(v2);
} catch (Exception e) {
return false;
}
}
private boolean isLt(String v1, String v2) {
try {
return Long.parseLong(v1) < Long.parseLong(v2);
} catch (Exception e) {
return false;
}
}
private boolean isEquals(Object subj) { private boolean isEquals(Object subj) {
String str = objectToString(subj); String str = objectToString(subj);
if (this.isUseRegex()) { if (this.isUseRegex()) {
@ -174,6 +196,13 @@ public class JSONPathAssertion extends AbstractTestElement implements Serializab
case "NOT_EQUALS": case "NOT_EQUALS":
refFlag = !str.equals(getExpectedValue()); refFlag = !str.equals(getExpectedValue());
break; break;
case "GT":
refFlag = isGt(str, getExpectedValue());
break;
case "LT":
refFlag = isLt(str, getExpectedValue());
break;
} }
return refFlag; return refFlag;
} }

View File

@ -11,6 +11,8 @@
<el-option :label="$t('api_test.request.assertions.not_contains')" value="NOT_CONTAINS"/> <el-option :label="$t('api_test.request.assertions.not_contains')" value="NOT_CONTAINS"/>
<el-option :label="$t('api_test.request.assertions.equals')" value="EQUALS"/> <el-option :label="$t('api_test.request.assertions.equals')" value="EQUALS"/>
<el-option :label="$t('commons.adv_search.operators.not_equals')" value="NOT_EQUALS"/> <el-option :label="$t('commons.adv_search.operators.not_equals')" value="NOT_EQUALS"/>
<el-option :label="$t('commons.adv_search.operators.gt')" value="GT"/>
<el-option :label="$t('commons.adv_search.operators.lt')" value="LT"/>
<el-option label="正则匹配" value="REGEX"/> <el-option label="正则匹配" value="REGEX"/>
</el-select> </el-select>
<el-input :disabled="isReadOnly" v-model="jsonPath.expect" size="small" show-word-limit <el-input :disabled="isReadOnly" v-model="jsonPath.expect" size="small" show-word-limit