1111import org .junit .jupiter .params .provider .MethodSource ;
1212
1313import java .time .Duration ;
14+ import java .time .Instant ;
1415import java .util .List ;
1516
1617import static org .assertj .core .api .Assertions .assertThat ;
1718import static org .junit .jupiter .api .Assertions .*;
1819
1920@ SuppressWarnings ("unused" )
20- public class V2ApiOperatorTest {
21+ public class OperatorTest {
2122 /*
2223 TODO:
2324 /v2/token/generate - Add failure case
@@ -31,6 +32,7 @@ public class V2ApiOperatorTest {
3132
3233 private static final ObjectMapper OBJECT_MAPPER = Mapper .getInstance ();
3334 private static final String CLIENT_SITE_ID = EnvUtil .getEnv (Const .Config .Operator .CLIENT_SITE_ID );
35+ private static final int RAW_UID_SIZE = 44 ;
3436
3537 @ ParameterizedTest (name = "/v2/token/generate - {0} - {2}" )
3638 @ MethodSource ({
@@ -96,39 +98,108 @@ public void testV2TokenValidate(String label, Operator operator, String operator
9698
9799 @ ParameterizedTest (name = "/v2/identity/map - {0} - {2}" )
98100 @ MethodSource ({
99- "suite.operator.TestData#identityMapBatchEmailArgs" ,
100- "suite.operator.TestData#identityMapBatchPhoneArgs" ,
101101 "suite.operator.TestData#identityMapBatchBadEmailArgs" ,
102102 "suite.operator.TestData#identityMapBatchBadPhoneArgs"
103103 })
104- public void testV2IdentityMap (String label , Operator operator , String operatorName , String payload ) throws Exception {
104+ public void testV2IdentityMapUnmapped (String label , Operator operator , String operatorName , String payload ) throws Exception {
105105 JsonNode response = operator .v2IdentityMap (payload );
106106
107- // TODO: Assert the value
108107 assertThat (response .at ("/status" ).asText ()).isEqualTo ("success" );
108+ assertThat (response .at ("/body/unmapped/0/reason" ).asText ()).isEqualTo ("invalid identifier" );
109109 }
110110
111111 @ ParameterizedTest (name = "/v2/identity/map - {0} - {2}" )
112112 @ MethodSource ({
113- "suite.operator.TestData#identityMapBigBatchArgs"
113+ "suite.operator.TestData#identityMapBatchEmailArgs" ,
114+ "suite.operator.TestData#identityMapBatchPhoneArgs" ,
114115 })
115- public void testV2IdentityMapLargeBatch (String label , Operator operator , String operatorName , String payload , List <String > diis ) {
116- assertTimeoutPreemptively (Duration .ofSeconds (5 ), () -> { // Validate we didn't make mapping too slow.
117- JsonNode response = operator .v2IdentityMap (payload );
116+ public void testV2IdentityMapMapped (String label , Operator operator , String operatorName , String payload ) throws Exception {
117+ JsonNode response = operator .v2IdentityMap (payload );
118118
119- assertThat (response .at ("/status" ).asText ()).isEqualTo ("success" );
119+ // TODO: Assert the value
120+ assertThat (response .at ("/status" ).asText ()).isEqualTo ("success" );
121+ }
120122
121- var mapped = response .at ("/body/mapped" );
122- assertThat (mapped .size ()).isEqualTo (10_000 );
123+ @ ParameterizedTest (name = "/v2/identity/map - {0} - {2}" )
124+ @ MethodSource ({"suite.operator.TestData#identityMapArgs" })
125+ public void testV2IdentityMap (
126+ String label ,
127+ Operator operator ,
128+ String operatorName ,
129+ IdentityMapInput input ,
130+ List <String > diis
131+ ) {
132+ assertTimeoutPreemptively (Duration .ofSeconds (5 ), () -> { // Validate we didn't make mapping too slow.
133+ var response = operator .v2IdentityMap (input );
134+
135+ assertThat (response .isSuccess ()).isTrue ();
136+
137+ assertThat (response .getUnmappedIdentities ()).isEmpty ();
138+
139+ var allMappedDiis = response .getMappedIdentities ();
140+ assertThat (allMappedDiis .size ()).isEqualTo (10_000 );
141+
142+ for (var dii : diis ) {
143+ var mappedDii = allMappedDiis .get (dii );
144+ assertThat (mappedDii ).isNotNull ();
145+ assertThat (mappedDii .getRawUid ().length ()).isEqualTo (RAW_UID_SIZE );
146+ assertThat (mappedDii .getBucketId ()).isNotBlank ();
147+ }
148+ });
149+ }
123150
124- for (int i = 0 ; i < 10_000 ; i ++) {
125- assertThat (mapped .get (i ).get ("identifier" ).asText ()).isEqualTo (diis .get (i ));
126- assertThat (mapped .get (i ).get ("advertising_id" ).asText ()).isNotNull ().isNotEmpty ();
127- assertThat (mapped .get (i ).get ("bucket_id" ).asText ()).isNotNull ().isNotEmpty ();
151+ @ ParameterizedTest (name = "/v3/identity/map - {0} - {2}" )
152+ @ MethodSource ({"suite.operator.TestData#identityMapV3Args" })
153+ public void testV3IdentityMapLargeBatch (
154+ String label ,
155+ Operator operator ,
156+ String operatorName ,
157+ IdentityMapV3Input input ,
158+ List <String > diis
159+ ) {
160+ assertTimeoutPreemptively (Duration .ofSeconds (5 ), () -> { // Validate we didn't make mapping too slow.
161+ var response = operator .v3IdentityMap (input );
162+
163+ assertThat (response .isSuccess ()).isTrue ();
164+
165+ assertThat (response .getUnmappedIdentities ()).isEmpty ();
166+
167+ var allMappedDiis = response .getMappedIdentities ();
168+ assertThat (allMappedDiis .size ()).isEqualTo (10_000 );
169+
170+ for (var dii : diis ) {
171+ var mappedDii = allMappedDiis .get (dii );
172+ assertThat (mappedDii ).isNotNull ();
173+
174+ // Current UID should always be there and should have correct length
175+ assertThat (mappedDii .getCurrentRawUid ().length ()).isEqualTo (RAW_UID_SIZE );
176+
177+ // Previous UID is there for 90 days after rotation only, then it's null.
178+ // If it's there, it should have the correct size
179+ assertThat (mappedDii .getPreviousRawUid ()).satisfiesAnyOf (
180+ uid -> assertThat (uid ).isNull (),
181+ uid -> assertThat (uid ).hasSize (RAW_UID_SIZE )
182+ );
183+
184+ // Sanity check that refresh from is a date not too far in the past.
185+ // If it is, either there is an Operator issue or salt rotation hasn't been running for a long time.
186+ assertThat (mappedDii .getRefreshFrom ()).isAfter (Instant .now ().minus (Duration .ofHours (1 )));
128187 }
129188 });
130189 }
131190
191+ @ ParameterizedTest (name = "/v3/identity/map - {0} - {2}" )
192+ @ MethodSource ({
193+ "suite.operator.TestData#identityMapV3BatchBadEmailArgs" ,
194+ "suite.operator.TestData#identityMapV3BatchBadPhoneArgs"
195+ })
196+ public void testV3IdentityMapUnmapped (String label , Operator operator , String operatorName , String payload , String identityType ) throws Exception {
197+ JsonNode response = operator .v3IdentityMap (payload );
198+
199+ assertThat (response .at ("/status" ).asText ()).isEqualTo ("success" );
200+ assertThat (response .at ("/body/" + identityType + "/0/e" ).asText ()).isEqualTo ("invalid identifier" );
201+ }
202+
132203
133204 @ ParameterizedTest (name = "/v2/identity/map - VALIDATE EMAIL - {0} - {2}" )
134205 @ MethodSource ({
0 commit comments