Package com.streambase.sb.unittest
Class FieldBasedTupleComparator
- java.lang.Object
-
- com.streambase.sb.unittest.FieldBasedTupleComparator
-
- All Implemented Interfaces:
TupleComparator
public class FieldBasedTupleComparator extends Object implements TupleComparator
ATupleComparator
that compares tuples in a naive field-by-field manner. Comparison of individual field types can be controlled usingFieldBasedTupleComparator.CompareFunctor
s. A subset of the fields for a tuple can by explicitly specifying the field names.DEFAULT_COMPARATOR
provides a reasonable default comparison of tuples.DEFAULT_COMPARE_REGISTRY
provides a filled in registry of defaultFieldBasedTupleComparator.CompareFunctor
s.- Since:
- 6.6
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
FieldBasedTupleComparator.CompareFunctor
A strategy object for handling comparisons of specific field types.static class
FieldBasedTupleComparator.DoubleCompareFunctor
Compare double values using a ratio test and a tolerance.static class
FieldBasedTupleComparator.IgnoreTimestampCompareFunctor
static class
FieldBasedTupleComparator.ListCompareFunctor
static class
FieldBasedTupleComparator.NaiveObjectCompareFunctor
static class
FieldBasedTupleComparator.RegexCompareFunctor
Check if the second argument matches the regex defined for the first argument.static class
FieldBasedTupleComparator.TupleCompareFunctor
-
Field Summary
Fields Modifier and Type Field Description static FieldBasedTupleComparator
DEFAULT_COMPARATOR
static DataType.Registry<FieldBasedTupleComparator.CompareFunctor>
DEFAULT_COMPARE_REGISTRY
static Map<DataType,FieldBasedTupleComparator.CompareFunctor>
DEFAULT_FUNCTOR_MAP
static FieldBasedTupleComparator
IGNORE_TIMESTAMP_COMPARATOR
static FieldBasedTupleComparator
REGEX_COMPARATOR
-
Constructor Summary
Constructors Constructor Description FieldBasedTupleComparator(DataType.Registry<FieldBasedTupleComparator.CompareFunctor> comparators, String... fields)
FieldBasedTupleComparator(FieldBasedTupleComparator baseComparator, String... fields)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
compare(Tuple expected, Tuple actual)
Compare two tuples.boolean
compareValues(CompleteDataType cdt, Object expected, Object actual)
Compare two values withCompleteDataType
cdt.String
formatForErrorMessage(Tuple t)
Convert the provided Tuple into a string appropriate for error messages.
-
-
-
Field Detail
-
DEFAULT_FUNCTOR_MAP
public static final Map<DataType,FieldBasedTupleComparator.CompareFunctor> DEFAULT_FUNCTOR_MAP
-
DEFAULT_COMPARE_REGISTRY
public static final DataType.Registry<FieldBasedTupleComparator.CompareFunctor> DEFAULT_COMPARE_REGISTRY
-
DEFAULT_COMPARATOR
public static final FieldBasedTupleComparator DEFAULT_COMPARATOR
-
REGEX_COMPARATOR
public static final FieldBasedTupleComparator REGEX_COMPARATOR
-
IGNORE_TIMESTAMP_COMPARATOR
public static final FieldBasedTupleComparator IGNORE_TIMESTAMP_COMPARATOR
-
-
Constructor Detail
-
FieldBasedTupleComparator
public FieldBasedTupleComparator(DataType.Registry<FieldBasedTupleComparator.CompareFunctor> comparators, String... fields) throws StreamBaseException
- Throws:
StreamBaseException
-
FieldBasedTupleComparator
public FieldBasedTupleComparator(FieldBasedTupleComparator baseComparator, String... fields) throws StreamBaseException
- Throws:
StreamBaseException
-
-
Method Detail
-
compare
public boolean compare(Tuple expected, Tuple actual) throws StreamBaseException
Description copied from interface:TupleComparator
Compare two tuples.- Specified by:
compare
in interfaceTupleComparator
- Parameters:
expected
- The expected valueactual
- The actual value- Returns:
- true if the tuples are equal
- Throws:
StreamBaseException
- error comparing tuples
-
compareValues
public boolean compareValues(CompleteDataType cdt, Object expected, Object actual) throws StreamBaseException
Description copied from interface:TupleComparator
Compare two values withCompleteDataType
cdt.- Specified by:
compareValues
in interfaceTupleComparator
- Parameters:
cdt
- TheCompleteDataType
for the objects being comparedexpected
- The expected valueactual
- The actual value- Returns:
- true if the values are equal
- Throws:
StreamBaseException
- error comparing tuples
-
formatForErrorMessage
public String formatForErrorMessage(Tuple t)
Description copied from interface:TupleComparator
Convert the provided Tuple into a string appropriate for error messages. Some comparators may wish to omit fields that are not salient to the comparison.- Specified by:
formatForErrorMessage
in interfaceTupleComparator
- Parameters:
t
- The tuple to format- Returns:
- A human readable string.
-
-