diff --git a/arex-compare-core/pom.xml b/arex-compare-core/pom.xml index 9477835..858ba7a 100644 --- a/arex-compare-core/pom.xml +++ b/arex-compare-core/pom.xml @@ -5,7 +5,7 @@ arex-compare-parent com.arextest - 0.2.14 + 0.2.15 4.0.0 diff --git a/arex-compare-core/src/main/java/com/arextest/diff/handler/log/register/LogRegister.java b/arex-compare-core/src/main/java/com/arextest/diff/handler/log/register/LogRegister.java index 3969741..ff887eb 100644 --- a/arex-compare-core/src/main/java/com/arextest/diff/handler/log/register/LogRegister.java +++ b/arex-compare-core/src/main/java/com/arextest/diff/handler/log/register/LogRegister.java @@ -185,6 +185,7 @@ private static LogEntity produceLog(Object obj1, Object obj2, int unmatchedType, LogEntity log = new LogEntity(obj1, obj2, getUnmatchedPair(unmatchedType, compareContext).buildListKeys(currentListKeys)); + log.simplifyLogMsg(); log.getLogTag().setErrorType(errorType); return log; } diff --git a/arex-compare-core/src/main/java/com/arextest/diff/model/CompareOptions.java b/arex-compare-core/src/main/java/com/arextest/diff/model/CompareOptions.java index df36d9a..e04e015 100644 --- a/arex-compare-core/src/main/java/com/arextest/diff/model/CompareOptions.java +++ b/arex-compare-core/src/main/java/com/arextest/diff/model/CompareOptions.java @@ -106,7 +106,8 @@ public class CompareOptions { private Boolean ipIgnore; /** - * This option is true, only compare the list elements which are existed in the baseMsg and testMsg + * This option is true, only compare the list elements which are existed in the baseMsg and + * testMsg */ private Boolean onlyCompareExistListElements; @@ -366,4 +367,5 @@ public Boolean getIpIgnore() { public Boolean getOnlyCompareExistListElements() { return onlyCompareExistListElements; } + } diff --git a/arex-compare-core/src/main/java/com/arextest/diff/model/GlobalOptions.java b/arex-compare-core/src/main/java/com/arextest/diff/model/GlobalOptions.java index 0379df4..8209885 100644 --- a/arex-compare-core/src/main/java/com/arextest/diff/model/GlobalOptions.java +++ b/arex-compare-core/src/main/java/com/arextest/diff/model/GlobalOptions.java @@ -64,7 +64,8 @@ public class GlobalOptions { private Boolean ipIgnore; /** - * This option is true, only compare the list elements which are existed in the baseMsg and testMsg + * This option is true, only compare the list elements which are existed in the baseMsg and + * testMsg */ private Boolean onlyCompareExistListElements; diff --git a/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogEntity.java b/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogEntity.java index 51140f6..a37931e 100644 --- a/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogEntity.java +++ b/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogEntity.java @@ -1,6 +1,7 @@ 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; @@ -40,9 +41,10 @@ public LogEntity() { } public LogEntity(Object baseValue, Object testValue, UnmatchedPairEntity pathPair) { - this.baseValue = valueToString(baseValue); - this.testValue = valueToString(testValue); + this.baseValue = baseValue; + this.testValue = testValue; this.pathPair = pathPair; + addNodeErrorType(); processLogInfo(this.baseValue, this.testValue, pathPair.getUnmatchedType()); } @@ -111,30 +113,6 @@ public void setAddRefPkNodePathRight(String addRefPkNodePathRight) { this.addRefPkNodePathRight = addRefPkNodePathRight; } - // public String getPath() { - // return path; - // } - // - // public void setPath(String path) { - // this.path = path; - // } - // - // public String getLeftPath() { - // return leftPath; - // } - // - // public void setLeftPath(String leftPath) { - // this.leftPath = leftPath; - // } - // - // public String getRightPath() { - // return rightPath; - // } - // - // public void setRightPath(String rightPath) { - // this.rightPath = rightPath; - // } - public int getWarn() { return warn; } @@ -151,29 +129,9 @@ public void setLogTag(LogTag logTag) { this.logTag = logTag; } - // private void processPath() { - // if (this.pathPair != null) { - // if (this.pathPair.getLeftUnmatchedPath().size() >= this.pathPair.getRightUnmatchedPath().size()) { - // this.path = ListUti.convertPathToStringForShow(this.pathPair.getLeftUnmatchedPath()); - // } else { - // this.path = ListUti.convertPathToStringForShow(this.pathPair.getRightUnmatchedPath()); - // } - // this.leftPath = ListUti.convertPathToStringForShow(this.pathPair.getLeftUnmatchedPath()); - // this.rightPath = ListUti.convertPathToStringForShow(this.pathPair.getRightUnmatchedPath()); - // } - // } - - 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() { + this.baseValue = valueToString(baseValue); + this.testValue = valueToString(testValue); } private void processLogInfo(Object baseValue, Object testValue, int unmatchedType) { @@ -231,6 +189,67 @@ private void processLogInfo(Object baseValue, Object testValue, int unmatchedTyp } } + private String valueToString(Object value) { + if (value instanceof NullNode || value == null) { + return null; + } + if (value instanceof ObjectNode) { + return "[Object]"; + } + if (value instanceof ArrayNode) { + return "[List]"; + } + if (value instanceof JsonNode) { + return ((JsonNode) value).asText(); + } + 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(); + return convertJsonNodeToString(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 simpleClassName; + } + } + + @Override public String toString() { if (this.pathPair == null) { diff --git a/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogTag.java b/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogTag.java index 269fdbd..3a3d833 100644 --- a/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogTag.java +++ b/arex-compare-core/src/main/java/com/arextest/diff/model/log/LogTag.java @@ -9,6 +9,8 @@ public class LogTag implements Serializable { */ private int errorType = 0; + private NodeErrorType nodeErrorType; + public LogTag() { } @@ -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; + } + } } diff --git a/arex-compare-core/src/test/java/com/arextest/diff/sdk/CompareSDKTest.java b/arex-compare-core/src/test/java/com/arextest/diff/sdk/CompareSDKTest.java index 0c4a5e4..a4464ed 100644 --- a/arex-compare-core/src/test/java/com/arextest/diff/sdk/CompareSDKTest.java +++ b/arex-compare-core/src/test/java/com/arextest/diff/sdk/CompareSDKTest.java @@ -857,5 +857,38 @@ public void testNullEqualsNotExist() { Assertions.assertEquals(0, result3.getLogs().size()); } + @Test + public void testSimplifyLogEntityMsg() { + CompareSDK sdk = new CompareSDK(); + + String baseMsg = "{\n" + + " \"studentName\": \"xiaoming\",\n" + + " \"classInfo\": {\n" + + " \"name\": \"classA\",\n" + + " \"location\": \"floor_A\"\n" + + " }\n" + + "}"; + String testMsg = "{\n" + + " \"studentName\": \"xiaoming\"\n" + + "}"; + + CompareResult compare = sdk.compare(baseMsg, testMsg); + Assertions.assertEquals("[Object]", compare.getLogs().get(0).getBaseValue()); + } + + @Test + public void testOutPutErrorValueType() { + CompareSDK sdk = new CompareSDK(); + + String baseMsg = "{\n" + + " \"score\": \"18\"" + + "}"; + String testMsg = "{\n" + + " \"score\": 19\n" + + "}"; + + CompareResult compare = sdk.compare(baseMsg, testMsg); + Assertions.assertEquals("18", compare.getLogs().get(0).getBaseValue()); + } } \ No newline at end of file diff --git a/pom.xml b/pom.xml index f2f1b7b..72ac67d 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ com.arextest arex-compare-parent pom - 0.2.14 + 0.2.15 arex-compare-extension arex-compare-core