2929import com .basistech .util .LanguageCode ;
3030import com .fasterxml .jackson .core .JsonProcessingException ;
3131import com .fasterxml .jackson .core .type .TypeReference ;
32- import com .fasterxml .jackson .databind .JsonNode ;
32+ import com .fasterxml .jackson .databind .MapperFeature ;
3333import com .fasterxml .jackson .databind .ObjectMapper ;
34+ import com .fasterxml .jackson .databind .SerializationFeature ;
3435import org .junit .jupiter .api .Test ;
3536
3637import java .util .List ;
@@ -42,13 +43,13 @@ class RecordSimilarityRequestTest {
4243
4344 private static final ObjectMapper MAPPER = ApiModelMixinModule .setupObjectMapper (new ObjectMapper ());
4445
45- private static final String EXPECTED_JSON = "{\" fields\" :{\" dob2 \" :{\" type\" :\" rni_date \" ,\" weight\" :0.1 },\" primaryName \" :{\" type\" :\" rni_name \" ,\" weight\" :0.5 },\" dob \" :{\" type\" :\" rni_date\" ,\" weight\" :0.2 },\" addr \" :{\" type\" :\" rni_address \" ,\" weight\" :0.5}},\" properties\" :{\" threshold \" :0.7 ,\" includeExplainInfo \" :true },\" records\" :{\" left\" :[{\" dob2 \" :{ \" date \" :\" 1993/04/ 16\" } ,\" primaryName \" :{\" text \" :\" Ethan R \" ,\" entityType\" :\" PERSON\" ,\" language\" :\" eng\" ,\" languageOfOrigin\" :\" eng\" ,\" script\" :\" Latn\" } ,\" dob \" :\" 1993-04-16 \" , \" addr \" :\" 123 Roadlane Ave \" },{ \" primaryName\" :{\" text\" :\" Evan R\" },\" dob\" :{\" date\" :\" 1993-04-16\" }}] ,\" right \" :[ {\" primaryName \" :{ \" text\" :\" Seth R\" , \" language \" :\" eng \" },\" dob\" :{\" date\" :\" 1993-04-16\" }},{ \" dob2\" :{\" date\" :\" 1993/04/16\" },\" primaryName\" :\" Ivan R\" , \" dob \" :{ \" date \" : \" 1993-04-16 \" }, \" addr \" :{ \" address \" : \" 123 Roadlane Ave \" } }]}}" ;
46+ private static final String EXPECTED_JSON = "{\" fields\" :{\" addr \" :{\" type\" :\" rni_address \" ,\" weight\" :0.5 },\" dob \" :{\" type\" :\" rni_date \" ,\" weight\" :0.2 },\" dob2 \" :{\" type\" :\" rni_date\" ,\" weight\" :0.1 },\" primaryName \" :{\" type\" :\" rni_name \" ,\" weight\" :0.5}},\" properties\" :{\" includeExplainInfo \" :true ,\" threshold \" :0.7 },\" records\" :{\" left\" :[{\" addr \" :\" 123 Roadlane Ave \" , \" dob \" :\" 1993-04- 16\" ,\" dob2 \" :{\" date \" :\" 1993/04/16 \" } ,\" primaryName \" :{ \" entityType\" :\" PERSON\" ,\" language\" :\" eng\" ,\" languageOfOrigin\" :\" eng\" ,\" script\" :\" Latn\" ,\" text \" :\" Ethan R \" }},{ \" dob \" :{ \" date \" : \" 1993-04-16 \" }, \" primaryName\" :{\" text\" :\" Evan R\" }}] ,\" right \" :[{ \" dob\" :{\" date\" :\" 1993-04-16\" },\" primaryName \" :{\" language \" :\" eng \" , \" text\" :\" Seth R\" }},{ \" addr \" :{ \" address \" : \" 123 Roadlane Ave \" },\" dob\" :{\" date\" :\" 1993-04-16\" }, \" dob2\" :{\" date\" :\" 1993/04/16\" },\" primaryName\" :\" Ivan R\" }]}}" ;
4647 private static final RecordSimilarityRequest EXPECTED_REQUEST = RecordSimilarityRequest .builder ()
4748 .fields (Map .of (
4849 "primaryName" , RecordSimilarityFieldInfo .builder ().type (RecordFieldType .RNI_NAME ).weight (0.5 ).build (),
4950 "dob" , RecordSimilarityFieldInfo .builder ().type (RecordFieldType .RNI_DATE ).weight (0.2 ).build (),
5051 "dob2" , RecordSimilarityFieldInfo .builder ().type (RecordFieldType .RNI_DATE ).weight (0.1 ).build (),
51- "addr" , RecordSimilarityFieldInfo .builder ().type (RecordFieldType .RNI_DATE ).weight (0.5 ).build ()))
52+ "addr" , RecordSimilarityFieldInfo .builder ().type (RecordFieldType .RNI_ADDRESS ).weight (0.5 ).build ()))
5253 .properties (RecordSimilarityProperties .builder ().threshold (0.7 ).includeExplainInfo (true ).build ())
5354 .records (RecordSimilarityRecords .builder ()
5455 .left (
@@ -87,15 +88,18 @@ class RecordSimilarityRequestTest {
8788
8889 @ Test
8990 void testDeserialization () throws JsonProcessingException {
91+ MAPPER .enable (MapperFeature .SORT_PROPERTIES_ALPHABETICALLY );
92+ MAPPER .enable (SerializationFeature .ORDER_MAP_ENTRIES_BY_KEYS );
9093 final RecordSimilarityRequest request = MAPPER .readValue (EXPECTED_JSON , new TypeReference <>() { });
9194 assertEquals (EXPECTED_REQUEST , request );
9295 }
9396
9497 @ Test
9598 void testSerialization () throws JsonProcessingException {
96- final JsonNode expectedJson = MAPPER .readTree (EXPECTED_JSON );
97- final JsonNode actualJson = MAPPER .valueToTree (EXPECTED_REQUEST );
98- assertEquals (expectedJson , actualJson );
99+ // For testing, force ordering
100+ MAPPER .enable (MapperFeature .SORT_PROPERTIES_ALPHABETICALLY );
101+ MAPPER .enable (SerializationFeature .ORDER_MAP_ENTRIES_BY_KEYS );
102+ assertEquals (EXPECTED_JSON , MAPPER .writeValueAsString (EXPECTED_REQUEST ));
99103 }
100104
101105}
0 commit comments