fix (接口测试): 修复json断言数组校验问题
--bug=1008219 --user=赵勇 【接口测试】文档结构断言,json结构,数组值没校验 https://www.tapd.cn/55049933/s/1073920
This commit is contained in:
parent
1e719d1294
commit
b4801f4ba0
|
@ -81,7 +81,16 @@ public class Document {
|
||||||
if (StringUtils.isEmpty(item.getGroupId())) {
|
if (StringUtils.isEmpty(item.getGroupId())) {
|
||||||
if (!item.getId().equals("root")) {
|
if (!item.getId().equals("root")) {
|
||||||
if (parentNode != null) {
|
if (parentNode != null) {
|
||||||
item.setJsonPath(parentNode.getJsonPath() + "." + item.getName());
|
if (parentNode.getType().equals("array") && item.getType().equals("string")) {
|
||||||
|
try {
|
||||||
|
int index = StringUtils.isNotEmpty(item.getName()) ? Integer.parseInt(item.getName()) : 0;
|
||||||
|
item.setJsonPath(parentNode.getJsonPath() + "[" + index + "]");
|
||||||
|
} catch (Exception e) {
|
||||||
|
item.setJsonPath(parentNode.getJsonPath() + "." + item.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
item.setJsonPath(parentNode.getJsonPath() + "." + item.getName());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
item.setJsonPath("$." + item.getName());
|
item.setJsonPath("$." + item.getName());
|
||||||
}
|
}
|
||||||
|
@ -107,7 +116,16 @@ public class Document {
|
||||||
for (DocumentElement item : dataList) {
|
for (DocumentElement item : dataList) {
|
||||||
if (StringUtils.isEmpty(item.getGroupId())) {
|
if (StringUtils.isEmpty(item.getGroupId())) {
|
||||||
if (parentNode != null) {
|
if (parentNode != null) {
|
||||||
item.setJsonPath(parentNode.getJsonPath() + "." + item.getName());
|
if (StringUtils.equals(parentNode.getType(), "array") && item.getType().equals("string")) {
|
||||||
|
try {
|
||||||
|
int index = StringUtils.isNotEmpty(item.getName()) ? Integer.parseInt(item.getName()) : 0;
|
||||||
|
item.setJsonPath(parentNode.getJsonPath() + "[" + index + "]");
|
||||||
|
} catch (Exception e) {
|
||||||
|
item.setJsonPath(parentNode.getJsonPath() + "." + item.getName());
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
item.setJsonPath(parentNode.getJsonPath() + "." + item.getName());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
item.setJsonPath("$." + item.getName());
|
item.setJsonPath("$." + item.getName());
|
||||||
}
|
}
|
||||||
|
|
|
@ -46,7 +46,7 @@ public class DocumentElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public DocumentElement(String name, String type, Object expectedOutcome, boolean typeVerification, List<DocumentElement>children) {
|
public DocumentElement(String name, String type, Object expectedOutcome, boolean typeVerification, List<DocumentElement> children) {
|
||||||
this.id = UUID.randomUUID().toString();
|
this.id = UUID.randomUUID().toString();
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.expectedOutcome = expectedOutcome;
|
this.expectedOutcome = expectedOutcome;
|
||||||
|
@ -62,6 +62,25 @@ public class DocumentElement {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public DocumentElement(String name, String type, Object expectedOutcome, boolean typeVerification, boolean arrayVerification, List<DocumentElement> children) {
|
||||||
|
this.id = UUID.randomUUID().toString();
|
||||||
|
this.name = name;
|
||||||
|
this.expectedOutcome = expectedOutcome;
|
||||||
|
this.type = type;
|
||||||
|
this.typeVerification = typeVerification;
|
||||||
|
this.arrayVerification = arrayVerification;
|
||||||
|
this.children = children == null ? this.children = new LinkedList<>() : children;
|
||||||
|
this.rowspan = 1;
|
||||||
|
this.contentVerification = "value_eq";
|
||||||
|
if (StringUtils.equalsAny(type, "object", "array")) {
|
||||||
|
this.contentVerification = "none";
|
||||||
|
} else if (expectedOutcome == null || StringUtils.isEmpty(expectedOutcome.toString())) {
|
||||||
|
this.contentVerification = "none";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public DocumentElement(String id, String name, String type, Object expectedOutcome, List<DocumentElement> children) {
|
public DocumentElement(String id, String name, String type, Object expectedOutcome, List<DocumentElement> children) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.name = name;
|
this.name = name;
|
||||||
|
|
|
@ -74,7 +74,7 @@ public class JSONSchemaToDocumentUtils {
|
||||||
Object value = null;
|
Object value = null;
|
||||||
boolean required = requiredList.contains(propertyName);
|
boolean required = requiredList.contains(propertyName);
|
||||||
if (object.has("default")) {
|
if (object.has("default")) {
|
||||||
value = object.get("default") != null ? object.get("default").toString() : "";
|
value = object.get("default") != null ? object.get("default").getAsString() : "";
|
||||||
concept.add(new DocumentElement(propertyName, propertyObjType, value, required, null));
|
concept.add(new DocumentElement(propertyName, propertyObjType, value, required, null));
|
||||||
} else if (object.has("enum")) {
|
} else if (object.has("enum")) {
|
||||||
try {
|
try {
|
||||||
|
@ -97,7 +97,7 @@ public class JSONSchemaToDocumentUtils {
|
||||||
} else if (propertyObjType.equals("string")) {
|
} else if (propertyObjType.equals("string")) {
|
||||||
// 先设置空值
|
// 先设置空值
|
||||||
if (object.has("default")) {
|
if (object.has("default")) {
|
||||||
value = object.get("default") != null ? object.get("default").toString() : "";
|
value = object.get("default") != null ? object.get("default").getAsString() : "";
|
||||||
}
|
}
|
||||||
if (object.has("mock") && object.get("mock").getAsJsonObject() != null && StringUtils.isNotEmpty(object.get("mock").getAsJsonObject().get("mock").getAsString()) && StringUtils.isNotEmpty(object.get("mock").getAsJsonObject().get("mock").getAsString())) {
|
if (object.has("mock") && object.get("mock").getAsJsonObject() != null && StringUtils.isNotEmpty(object.get("mock").getAsJsonObject().get("mock").getAsString()) && StringUtils.isNotEmpty(object.get("mock").getAsJsonObject().get("mock").getAsString())) {
|
||||||
value = ScriptEngineUtils.buildFunctionCallString(object.get("mock").getAsJsonObject().get("mock").getAsString());
|
value = ScriptEngineUtils.buildFunctionCallString(object.get("mock").getAsJsonObject().get("mock").getAsString());
|
||||||
|
@ -140,7 +140,7 @@ public class JSONSchemaToDocumentUtils {
|
||||||
concept.add(new DocumentElement(propertyName, propertyObjType, value, required, null));
|
concept.add(new DocumentElement(propertyName, propertyObjType, value, required, null));
|
||||||
} else if (propertyObjType.equals("array")) {
|
} else if (propertyObjType.equals("array")) {
|
||||||
List<DocumentElement> elements = new LinkedList<>();
|
List<DocumentElement> elements = new LinkedList<>();
|
||||||
concept.add(new DocumentElement(propertyName, propertyObjType, "", requiredList.contains(propertyName), elements));
|
concept.add(new DocumentElement(propertyName, propertyObjType, "", requiredList.contains(propertyName), true, elements));
|
||||||
JsonArray jsonArray = object.get("items").getAsJsonArray();
|
JsonArray jsonArray = object.get("items").getAsJsonArray();
|
||||||
analyzeArray(propertyName, jsonArray, elements, requiredList);
|
analyzeArray(propertyName, jsonArray, elements, requiredList);
|
||||||
} else if (propertyObjType.equals("object")) {
|
} else if (propertyObjType.equals("object")) {
|
||||||
|
|
Loading…
Reference in New Issue