Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: ouput the type of error node #59

Merged
merged 5 commits into from
Aug 14, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -37,6 +37,8 @@ public List<LogEntity> doHandler(RulesConfig rulesConfig, KeyComputeResponse key
compareContext.logProcess = logProcess;
compareContext.quickCompare = rulesConfig.isQuickCompare();

compareContext.simplifyLogEntity = rulesConfig.isSimplifyLogEntity();

if (msgStructureFuture != null) {
MutablePair<MsgStructure, MsgStructure> msgStructureMutablePair = msgStructureFuture.join();
compareContext.baseMsgStructure = msgStructureMutablePair.getLeft();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(compareContext.simplifyLogEntity);
log.getLogTag().setErrorType(errorType);
return log;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,10 +106,17 @@ 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;

/**
* This option is true, the log entity message is simplified
* The baseMsg and testMsg are only output when leaf nodes
*/
private Boolean simplifyLogEntity;

public CompareOptions() {
}

Expand Down Expand Up @@ -299,6 +306,11 @@ public CompareOptions putOnlyCompareExistListElements(Boolean onlyCompareExistLi
return this;
}

public CompareOptions putSimplifyLogEntity(Boolean simplifyLogEntity) {
this.simplifyLogEntity = simplifyLogEntity;
return this;
}

public String getCategoryType() {
return categoryType;
}
Expand Down Expand Up @@ -366,4 +378,9 @@ public Boolean getIpIgnore() {
public Boolean getOnlyCompareExistListElements() {
return onlyCompareExistListElements;
}

public Boolean getSimplifyLogEntity() {
return simplifyLogEntity;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,17 @@ 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;

/**
* This option is true, the log entity message is simplified
* The baseMsg and testMsg are only output when leaf nodes
*/
private Boolean simplifyLogEntity;

public GlobalOptions() {
this.nameToLower = false;
this.nullEqualsEmpty = false;
Expand Down Expand Up @@ -132,6 +139,11 @@ public GlobalOptions putOnlyCompareExistListElements(Boolean onlyCompareExistLis
return this;
}

public GlobalOptions putSimplifyLogEntity(Boolean simplifyLogEntity) {
this.simplifyLogEntity = simplifyLogEntity;
return this;
}

public String getPluginJarUrl() {
return pluginJarUrl;
}
Expand Down Expand Up @@ -176,4 +188,8 @@ public Boolean getOnlyCompareExistListElements() {
return onlyCompareExistListElements;
}

public Boolean getSimplifyLogEntity() {
return simplifyLogEntity;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public class RulesConfig {

private boolean onlyCompareExistListElements;

private boolean simplifyLogEntity;

//region: inner processed class
private List<List<ExpressionNodeEntity>> expressionExclusions;

Expand Down Expand Up @@ -227,6 +229,14 @@ public void setOnlyCompareExistListElements(boolean onlyCompareExistListElements
this.onlyCompareExistListElements = onlyCompareExistListElements;
}

public boolean isSimplifyLogEntity() {
return simplifyLogEntity;
}

public void setSimplifyLogEntity(boolean simplifyLogEntity) {
this.simplifyLogEntity = simplifyLogEntity;
}

public List<List<ExpressionNodeEntity>> getExpressionExclusions() {
return expressionExclusions;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ public class CompareContext {

public byte ignoreReferenceNotFound = 0;

public boolean simplifyLogEntity = false;

public CompareContext() {
this.currentTraceLeft = new ArrayList<>();
this.currentTraceRight = new ArrayList<>();
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 @@ -40,9 +42,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());
}

Expand Down Expand Up @@ -111,30 +114,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;
}
Expand All @@ -151,29 +130,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(boolean simplifyLogEntity) {
this.baseValue = valueToString(baseValue, simplifyLogEntity);
this.testValue = valueToString(testValue, simplifyLogEntity);
}

private void processLogInfo(Object baseValue, Object testValue, int unmatchedType) {
Expand Down Expand Up @@ -231,6 +190,65 @@ private void processLogInfo(Object baseValue, Object testValue, int unmatchedTyp
}
}

private String valueToString(Object value, boolean simplifyLogEntity) {
if (value instanceof NullNode || value == null) {
return null;
}
if (value instanceof ObjectNode || value instanceof ArrayNode) {
return simplifyLogEntity ? null : value.toString();
}
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();
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;
coryhh marked this conversation as resolved.
Show resolved Hide resolved
}
}


@Override
public String toString() {
if (this.pathPair == null) {
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;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ private static void globalOptionsToRules(GlobalOptions globalOptions, RulesConfi
if (globalOptions.getOnlyCompareExistListElements() != null) {
rulesConfig.setOnlyCompareExistListElements(globalOptions.getOnlyCompareExistListElements());
}
if (globalOptions.getSimplifyLogEntity() != null) {
rulesConfig.setSimplifyLogEntity(globalOptions.getSimplifyLogEntity());
}
}

private static void optionsToRules(CompareOptions compareOptions, RulesConfig rulesConfig) {
Expand Down Expand Up @@ -131,6 +134,9 @@ private static void optionsToRules(CompareOptions compareOptions, RulesConfig ru
if (compareOptions.getOnlyCompareExistListElements() != null) {
rulesConfig.setOnlyCompareExistListElements(compareOptions.getOnlyCompareExistListElements());
}
if (compareOptions.getSimplifyLogEntity() != null) {
rulesConfig.setSimplifyLogEntity(compareOptions.getSimplifyLogEntity());
}
}

private static Map<List<String>, List<TransformMethod>> decompressAndTransformConvert(
Expand Down
Loading
Loading