@@ -279,6 +279,100 @@ public void activateEndToEndWithTypedAudienceInt() throws Exception {
279
279
verify (mockEventHandler ).dispatchEvent (logEventToDispatch );
280
280
}
281
281
282
+ /**
283
+ * Verify that activating using typed audiences works for numeric match exact using double and integer.
284
+ */
285
+ @ Test
286
+ public void activateEndToEndWithTypedAudienceIntExactDouble () throws Exception {
287
+ Experiment activatedExperiment ;
288
+ Map <String , Object > testUserAttributes = new HashMap <String , Object >();
289
+ String bucketingKey = testBucketingIdKey ;
290
+ String userId = testUserId ;
291
+ String bucketingId = testBucketingId ;
292
+ if (datafileVersion >= 4 ) {
293
+ activatedExperiment = validProjectConfig .getExperimentKeyMapping ().get (EXPERIMENT_TYPEDAUDIENCE_EXPERIMENT_KEY );
294
+ testUserAttributes .put (ATTRIBUTE_INTEGER_KEY , 1.0 ); // should be equal 1.
295
+ }
296
+ else {
297
+ return ; // only test on v4 datafiles.
298
+ }
299
+ testUserAttributes .put (bucketingKey , bucketingId );
300
+ Variation bucketedVariation = activatedExperiment .getVariations ().get (0 );
301
+ EventFactory mockEventFactory = mock (EventFactory .class );
302
+
303
+ Optimizely optimizely = Optimizely .builder (validDatafile , mockEventHandler )
304
+ .withBucketing (mockBucketer )
305
+ .withEventBuilder (mockEventFactory )
306
+ .withConfig (validProjectConfig )
307
+ .withErrorHandler (mockErrorHandler )
308
+ .build ();
309
+
310
+
311
+ when (mockEventFactory .createImpressionEvent (validProjectConfig , activatedExperiment , bucketedVariation , testUserId ,
312
+ testUserAttributes ))
313
+ .thenReturn (logEventToDispatch );
314
+
315
+ when (mockBucketer .bucket (activatedExperiment , bucketingId ))
316
+ .thenReturn (bucketedVariation );
317
+
318
+ // activate the experiment
319
+ Variation actualVariation = optimizely .activate (activatedExperiment .getKey (), userId , testUserAttributes );
320
+
321
+ // verify that the bucketing algorithm was called correctly
322
+ verify (mockBucketer ).bucket (activatedExperiment , bucketingId );
323
+ assertThat (actualVariation , is (bucketedVariation ));
324
+
325
+ // verify that dispatchEvent was called with the correct LogEvent object
326
+ verify (mockEventHandler ).dispatchEvent (logEventToDispatch );
327
+ }
328
+
329
+ /**
330
+ * Verify that activating using typed audiences works for numeric match exact using double and integer.
331
+ */
332
+ @ Test
333
+ public void activateEndToEndWithTypedAudienceIntExact () throws Exception {
334
+ Experiment activatedExperiment ;
335
+ Map <String , Object > testUserAttributes = new HashMap <String , Object >();
336
+ String bucketingKey = testBucketingIdKey ;
337
+ String userId = testUserId ;
338
+ String bucketingId = testBucketingId ;
339
+ if (datafileVersion >= 4 ) {
340
+ activatedExperiment = validProjectConfig .getExperimentKeyMapping ().get (EXPERIMENT_TYPEDAUDIENCE_EXPERIMENT_KEY );
341
+ testUserAttributes .put (ATTRIBUTE_INTEGER_KEY , 1 ); // should be equal 1.
342
+ }
343
+ else {
344
+ return ; // only test on v4 datafiles.
345
+ }
346
+ testUserAttributes .put (bucketingKey , bucketingId );
347
+ Variation bucketedVariation = activatedExperiment .getVariations ().get (0 );
348
+ EventFactory mockEventFactory = mock (EventFactory .class );
349
+
350
+ Optimizely optimizely = Optimizely .builder (validDatafile , mockEventHandler )
351
+ .withBucketing (mockBucketer )
352
+ .withEventBuilder (mockEventFactory )
353
+ .withConfig (validProjectConfig )
354
+ .withErrorHandler (mockErrorHandler )
355
+ .build ();
356
+
357
+
358
+ when (mockEventFactory .createImpressionEvent (validProjectConfig , activatedExperiment , bucketedVariation , testUserId ,
359
+ testUserAttributes ))
360
+ .thenReturn (logEventToDispatch );
361
+
362
+ when (mockBucketer .bucket (activatedExperiment , bucketingId ))
363
+ .thenReturn (bucketedVariation );
364
+
365
+ // activate the experiment
366
+ Variation actualVariation = optimizely .activate (activatedExperiment .getKey (), userId , testUserAttributes );
367
+
368
+ // verify that the bucketing algorithm was called correctly
369
+ verify (mockBucketer ).bucket (activatedExperiment , bucketingId );
370
+ assertThat (actualVariation , is (bucketedVariation ));
371
+
372
+ // verify that dispatchEvent was called with the correct LogEvent object
373
+ verify (mockEventHandler ).dispatchEvent (logEventToDispatch );
374
+ }
375
+
282
376
/**
283
377
* Verify that the {@link Optimizely#activate(Experiment, String, Map)} call correctly builds an endpoint url and
284
378
* request params and passes them through {@link EventHandler#dispatchEvent(LogEvent)}.
0 commit comments