-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
662 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
arex-compare-core/src/main/java/com/arextest/diff/compare/ScriptCompare.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package com.arextest.diff.compare; | ||
|
||
import com.arextest.diff.handler.log.LogMarker; | ||
import com.arextest.diff.handler.log.register.LogRegister; | ||
import com.arextest.diff.model.compare.CompareContext; | ||
import com.arextest.diff.model.exception.FindErrorException; | ||
import com.arextest.diff.model.script.ScriptCompareConfig.ScriptMethod; | ||
import com.arextest.diff.model.script.ScriptMethodContext; | ||
import com.arextest.diff.model.script.ScriptSandbox; | ||
import com.arextest.diff.utils.JacksonHelperUtil; | ||
import java.util.List; | ||
import javax.script.ScriptException; | ||
|
||
public class ScriptCompare { | ||
|
||
public static boolean isScriptComparisonRequired(List<String> fuzzyPath, | ||
CompareContext compareContext) { | ||
return compareContext.scriptCompareConfigMap != null | ||
&& compareContext.scriptCompareConfigMap.containsKey(fuzzyPath); | ||
} | ||
|
||
// custom compare | ||
public static void scriptCompare(Object obj1, Object obj2, List<String> fuzzyPath, | ||
CompareContext compareContext) | ||
throws ScriptException, NoSuchMethodException, FindErrorException { | ||
|
||
ScriptMethodContext context = new ScriptMethodContext(); | ||
context.setBasePath(compareContext.currentNodeLeft); | ||
context.setTestPath(compareContext.currentNodeRight); | ||
|
||
Object baseValue = JacksonHelperUtil.objectMapper.convertValue(obj1, Object.class); | ||
Object testValue = JacksonHelperUtil.objectMapper.convertValue(obj2, Object.class); | ||
ScriptSandbox scriptSandbox = compareContext.scriptSandbox; | ||
ScriptMethod scriptMethod = compareContext.scriptCompareConfigMap.get(fuzzyPath); | ||
Boolean result = scriptSandbox.invoke(context, baseValue, testValue, scriptMethod); | ||
if (result) { | ||
return; | ||
} | ||
LogRegister.register(obj1, obj2, LogMarker.VALUE_DIFF, compareContext); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 45 additions & 22 deletions
67
arex-compare-core/src/main/java/com/arextest/diff/handler/log/LogMarker.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,47 +1,70 @@ | ||
package com.arextest.diff.handler.log; | ||
|
||
public enum LogMarker { | ||
ZERO, | ||
|
||
// This marker indicates that there is a null value at the recursive entry | ||
NULL_CHECK, | ||
|
||
// This marker indicates that there is different type | ||
TYPE_DIFF, | ||
UNKNOWN(0), | ||
|
||
// This mark indicates that there is unmatched value at the comparison of value | ||
VALUE_DIFF(1), | ||
|
||
// This marker indicates that there is right missing at the comparison of object | ||
RIGHT_OBJECT_MISSING, | ||
RIGHT_OBJECT_MISSING(2), | ||
|
||
// This marker indicates that there is left missing at the comparison of object | ||
LEFT_OBJECT_MISSING, | ||
LEFT_OBJECT_MISSING(3), | ||
|
||
// This marker indicates that there is different count at the comparison of array | ||
DIFF_ARRAY_COUNT, | ||
// This mark indicates that there is left missing at the comparision of array | ||
LEFT_ARRAY_MISSING(4), | ||
|
||
// This marker indicates that there is right missing at the comparison of array | ||
RIGHT_ARRAY_MISSING, | ||
RIGHT_ARRAY_MISSING(5), | ||
|
||
// This marker indicates that there is not unique key at the left search of listkey | ||
REPEAT_LEFT_KEY, | ||
// This marker indicates that there is a null value at the recursive entry | ||
NULL_CHECK(6), | ||
|
||
// This mark indicates that there is right missing at the comparison of listKey mode | ||
RIGHT_ARRAY_MISSING_KEY, | ||
// This marker indicates that there is different type | ||
TYPE_DIFF(7), | ||
|
||
// This mark indicates that there is left missing at the comparision of array | ||
LEFT_ARRAY_MISSING, | ||
// This marker indicates that there is different count at the comparison of array | ||
DIFF_ARRAY_COUNT(8), | ||
|
||
// This marker indicates that there is not unique key at the left search of listkey | ||
REPEAT_LEFT_KEY(9), | ||
|
||
// This marker indicates that there is not unique key at the right search of listkey | ||
REPEAT_RIGHT_KEY, | ||
REPEAT_RIGHT_KEY(10), | ||
|
||
// This mark indicates that there is right missing at the comparison of listKey mode | ||
RIGHT_ARRAY_MISSING_KEY(11), | ||
|
||
// This mark indicates that there is left missing at the comparison of listKey mode | ||
LEFT_ARRAY_MISSING_KEY, | ||
LEFT_ARRAY_MISSING_KEY(12), | ||
|
||
// This mark indicates that there is left reference not fund at the comparison of value | ||
LEFT_REF_NOT_FOUND, | ||
LEFT_REF_NOT_FOUND(13), | ||
|
||
// This mark indicates that there is right reference not found at the comparison of value | ||
RIGHT_REF_NOT_FOUND, | ||
RIGHT_REF_NOT_FOUND(14); | ||
|
||
private Integer code; | ||
|
||
LogMarker(int code) { | ||
this.code = code; | ||
} | ||
|
||
public Integer getCode() { | ||
return code; | ||
} | ||
|
||
public static LogMarker from(int code) { | ||
for (LogMarker type : LogMarker.values()) { | ||
if (type.getCode() == code) { | ||
return type; | ||
} | ||
} | ||
return UNKNOWN; | ||
} | ||
|
||
|
||
// This mark indicates that there is unmatched value at the comparison of value | ||
VALUE_DIFF, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.