Skip to content

Commit

Permalink
feat: output the type of error node
Browse files Browse the repository at this point in the history
  • Loading branch information
rchen9 committed Aug 12, 2024
1 parent c47863f commit 9ed302f
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 17 deletions.
2 changes: 1 addition & 1 deletion arex-compare-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>arex-compare-parent</artifactId>
<groupId>com.arextest</groupId>
<version>0.2.14</version>
<version>0.2.15</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public class CompareOptions {
*/
private Boolean onlyCompareExistListElements;

/*
/**
* This option is true, the log entity message is simplified
* The baseMsg and testMsg are only output when leaf nodes
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
package com.arextest.diff.model.log;

import com.arextest.diff.model.enumeration.UnmatchedType;
import com.arextest.diff.model.log.LogTag.NodeErrorType;
import com.arextest.diff.utils.ListUti;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.NullNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import java.io.Serializable;
import java.util.List;
import java.util.Optional;

public class LogEntity implements Serializable {

Expand Down Expand Up @@ -43,6 +45,7 @@ public LogEntity(Object baseValue, Object testValue, UnmatchedPairEntity pathPai
this.baseValue = baseValue;
this.testValue = testValue;
this.pathPair = pathPair;
addNodeErrorType();
processLogInfo(this.baseValue, this.testValue, pathPair.getUnmatchedType());
}

Expand Down Expand Up @@ -127,19 +130,6 @@ public void setLogTag(LogTag logTag) {
this.logTag = logTag;
}

// private String valueToString(Object value) {
// if (value instanceof NullNode || value == null) {
// return null;
// }
// if (value instanceof ObjectNode || value instanceof ArrayNode) {
// return null;
// }
// if (value instanceof JsonNode) {
// return ((JsonNode) value).asText();
// }
// return value.toString();
// }

public void simplifyLogMsg(boolean simplifyLogEntity) {
this.baseValue = valueToString(baseValue, simplifyLogEntity);
this.testValue = valueToString(testValue, simplifyLogEntity);
Expand Down Expand Up @@ -200,7 +190,7 @@ private void processLogInfo(Object baseValue, Object testValue, int unmatchedTyp
}
}

private static String valueToString(Object value, boolean simplifyLogEntity) {
private String valueToString(Object value, boolean simplifyLogEntity) {
if (value instanceof NullNode || value == null) {
return null;
}
Expand All @@ -213,6 +203,50 @@ private static String valueToString(Object value, boolean simplifyLogEntity) {
return value.toString();
}

private void addNodeErrorType() {
NodeErrorType nodeErrorType = new NodeErrorType();
nodeErrorType.setBaseNodeType(judgeNodeErrorType(baseValue));
nodeErrorType.setTestNodeType(judgeNodeErrorType(testValue));
logTag.setNodeErrorType(nodeErrorType);
}

private String judgeNodeErrorType(Object value) {
if (value == null) {
return "null";
}
String simpleName = value.getClass().getSimpleName();
String type = convertJsonNodeToString(simpleName);
return Optional.ofNullable(type).orElse(simpleName);
}

private String convertJsonNodeToString(String simpleClassName) {
switch (simpleClassName) {
case "ObjectNode":
return "object";
case "ArrayNode":
return "array";
case "NullNode":
return "null";
case "TextNode":
return "string";
case "IntNode":
return "int";
case "LongNode":
return "long";
case "DoubleNode":
return "double";
case "FloatNode":
return "float";
case "BigIntegerNode":
return "bigInteger";
case "BigDecimalNode":
return "bigDecimal";
case "BooleanNode":
return "boolean";
default:
return null;
}
}


@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ public class LogTag implements Serializable {
*/
private int errorType = 0;

private NodeErrorType nodeErrorType;

public LogTag() {
}

Expand All @@ -19,4 +21,37 @@ public int getErrorType() {
public void setErrorType(int errorType) {
this.errorType = errorType;
}

public NodeErrorType getNodeErrorType() {
return nodeErrorType;
}

public void setNodeErrorType(NodeErrorType nodeErrorType) {
this.nodeErrorType = nodeErrorType;
}

public static class NodeErrorType {

private String baseNodeType;
private String testNodeType;

public NodeErrorType() {
}

public String getBaseNodeType() {
return baseNodeType;
}

public void setBaseNodeType(String baseNodeType) {
this.baseNodeType = baseNodeType;
}

public String getTestNodeType() {
return testNodeType;
}

public void setTestNodeType(String testNodeType) {
this.testNodeType = testNodeType;
}
}
}
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<groupId>com.arextest</groupId>
<artifactId>arex-compare-parent</artifactId>
<packaging>pom</packaging>
<version>0.2.14</version>
<version>0.2.15</version>
<modules>
<module>arex-compare-extension</module>
<module>arex-compare-core</module>
Expand Down

0 comments on commit 9ed302f

Please sign in to comment.