Class DefaultResultComparator
- java.lang.Object
-
- de.gebit.integrity.runner.comparator.DefaultResultComparator
-
- All Implemented Interfaces:
ResultComparator
public class DefaultResultComparator extends java.lang.Object implements ResultComparator
The standard result comparator component.- Author:
- Rene Schneider - initial API and implementation
-
-
Field Summary
Fields Modifier and Type Field Description protected ParameterResolverparameterResolverThe parameter resolver to use.protected ValueConvertervalueConverterThe value converter to use.
-
Constructor Summary
Constructors Constructor Description DefaultResultComparator()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ComparisonResultcompareResult(java.lang.Object aFixtureResult, ValueOrEnumValueOrOperationCollection anExpectedResult, FixtureWrapper<?> aFixtureInstance, MethodReference aFixtureMethod, java.lang.String aPropertyName)Compares the expected result with the actual result obtained from a test fixture.protected ComparisonResultconvertAndPerformEqualityCheck(java.lang.Object aSingleFixtureResult, ValueOrEnumValueOrOperation aSingleExpectedResult, java.lang.Class<?> aConversionTargetType)Converts a fixture result and an expected result value for comparison (usually by converting the expected result to match the fixture result, but nested objects are handled differently and converted to maps for comparison).protected ComparisonResultconvertAndPerformEqualityCheck(java.lang.Object aSingleFixtureResult, java.lang.Object aSingleExpectedResult, ValueOrEnumValueOrOperation anOriginalSingleExpectedResult, java.lang.Class<?> aConversionTargetType, boolean anExpectedResultWasEmptyOptionalFlag)protected ComparisonResultperformEqualityCheck(java.lang.Object aConvertedResult, java.lang.Object aConvertedExpectedResult, ValueOrEnumValueOrOperation aRawExpectedResult)Perform the actual equality check between a real result returned from a fixture and a converted result gathered from the test scripts.protected ComparisonResultperformEqualityCheckForDates(java.util.Date aResult, java.util.Date anExpectedResult, java.lang.Object aRawExpectedResult)Compare twoDates for equality.protected ComparisonResultperformEqualityCheckForJava8Dates(java.time.temporal.Temporal aResult, java.time.temporal.Temporal anExpectedResult, java.lang.Object aRawExpectedResult)Compare twoTemporals for equality.protected MapComparisonResultperformEqualityCheckForMaps(java.util.Map<?,?> aResult, java.util.Map<?,?> anExpectedResult, ValueOrEnumValueOrOperation aRawExpectedResult)Compare twoMaps for equality.protected ComparisonResultperformEqualityCheckForObjects(java.lang.Object aResult, java.lang.Object anExpectedResult, java.lang.Object aRawExpectedResult)Compare two objects.protected ComparisonResultperformRegexCheck(java.lang.String aFixtureResult, RegexValue anExpectedResult)Performs the regular expression based comparison between a fixture result and an expected regex.
-
-
-
Field Detail
-
valueConverter
@Inject protected ValueConverter valueConverter
The value converter to use.
-
parameterResolver
@Inject protected ParameterResolver parameterResolver
The parameter resolver to use.
-
-
Method Detail
-
compareResult
public ComparisonResult compareResult(java.lang.Object aFixtureResult, ValueOrEnumValueOrOperationCollection anExpectedResult, FixtureWrapper<?> aFixtureInstance, MethodReference aFixtureMethod, java.lang.String aPropertyName) throws java.lang.ClassNotFoundException, UnexecutableException, java.lang.InstantiationException
Description copied from interface:ResultComparatorCompares the expected result with the actual result obtained from a test fixture.- Specified by:
compareResultin interfaceResultComparator- Parameters:
aFixtureResult- the test fixture resultanExpectedResult- the expected result as specified in the test scriptaFixtureInstance- the fixture instance that was usedaFixtureMethod- the fixture method that was calledaPropertyName- the name of the result property to be compared (null if it's the default result)- Returns:
- true if the comparison was successful, false if the results are not considered equal
- Throws:
java.lang.ClassNotFoundExceptionUnexecutableExceptionjava.lang.InstantiationException
-
convertAndPerformEqualityCheck
protected ComparisonResult convertAndPerformEqualityCheck(java.lang.Object aSingleFixtureResult, ValueOrEnumValueOrOperation aSingleExpectedResult, java.lang.Class<?> aConversionTargetType) throws ParameterUtil.UnresolvableVariableException, UnexecutableException
Converts a fixture result and an expected result value for comparison (usually by converting the expected result to match the fixture result, but nested objects are handled differently and converted to maps for comparison). The final results are then compared.- Parameters:
aSingleFixtureResult- the fixture resultaSingleExpectedResult- the expected resultaConversionTargetType- the target type for conversion- Returns:
- true if both values are considered equal, false if not
- Throws:
ParameterUtil.UnresolvableVariableExceptionUnexecutableException
-
convertAndPerformEqualityCheck
protected ComparisonResult convertAndPerformEqualityCheck(java.lang.Object aSingleFixtureResult, java.lang.Object aSingleExpectedResult, ValueOrEnumValueOrOperation anOriginalSingleExpectedResult, java.lang.Class<?> aConversionTargetType, boolean anExpectedResultWasEmptyOptionalFlag) throws ParameterUtil.UnresolvableVariableException, UnexecutableException
-
performRegexCheck
protected ComparisonResult performRegexCheck(java.lang.String aFixtureResult, RegexValue anExpectedResult)
Performs the regular expression based comparison between a fixture result and an expected regex. The pattern provided must be "found" in the value (it does not have to match the entire value, except if the pattern is anchored to the start and/or end).- Parameters:
aFixtureResult- the fixture result as a StringanExpectedResult- the expected result- Returns:
SimpleComparisonResult.EQUAL(pattern found) orSimpleComparisonResult.NOT_EQUAL(pattern not found)
-
performEqualityCheck
protected ComparisonResult performEqualityCheck(java.lang.Object aConvertedResult, java.lang.Object aConvertedExpectedResult, ValueOrEnumValueOrOperation aRawExpectedResult)
Perform the actual equality check between a real result returned from a fixture and a converted result gathered from the test scripts. A few special cases are handled here, but if no special case applies, this just runs a standard equals() comparison.- Parameters:
aConvertedResult- the actual resultaConvertedExpectedResult- the expected result from the scripts, converted to the same type as the actual resultaRawExpectedResult- the raw expected result object from the scripts (if determinable, null otherwise)- Returns:
- true if equal, false otherwise
-
performEqualityCheckForMaps
protected MapComparisonResult performEqualityCheckForMaps(java.util.Map<?,?> aResult, java.util.Map<?,?> anExpectedResult, ValueOrEnumValueOrOperation aRawExpectedResult)
Compare twoMaps for equality. Maps are considered equal if all the values in the expected result are found in the actual result (there may well be more keys in the actual result than expected, except if one of the maps declares one of these "inexistent", in which case it may NOT exist in the other!).- Parameters:
aResult- the result returned by the fixtureanExpectedResult- the expected result as in the script, converted for comparisonaRawExpectedResult- the raw expected result as in the script, before conversion- Returns:
- true if equal, false otherwise
-
performEqualityCheckForDates
protected ComparisonResult performEqualityCheckForDates(java.util.Date aResult, java.util.Date anExpectedResult, java.lang.Object aRawExpectedResult)
Compare twoDates for equality.- Parameters:
aResult- the result returned by the fixtureanExpectedResult- the expected result as in the script, converted for comparisonaRawExpectedResult- the raw expected result as in the script, before conversion- Returns:
- true if equal, false otherwise
-
performEqualityCheckForJava8Dates
protected ComparisonResult performEqualityCheckForJava8Dates(java.time.temporal.Temporal aResult, java.time.temporal.Temporal anExpectedResult, java.lang.Object aRawExpectedResult)
Compare twoTemporals for equality.- Parameters:
aResult- the result returned by the fixtureanExpectedResult- the expected result as in the script, converted for comparisonaRawExpectedResult- the raw expected result as in the script, before conversion- Returns:
- true if equal, false otherwise
-
performEqualityCheckForObjects
protected ComparisonResult performEqualityCheckForObjects(java.lang.Object aResult, java.lang.Object anExpectedResult, java.lang.Object aRawExpectedResult)
Compare two objects. At this point it is expected that the previous stages have done all conversion work, iteration through arrays etc.- Parameters:
aResult- the result returned by the fixtureanExpectedResult- the expected result as in the script, converted for comparisonaRawExpectedResult- the raw expected result as in the script, before conversion- Returns:
- true if equal, false otherwise
-
-