16
16
package com .optimizely .ab .optimizelyconfig ;
17
17
18
18
import com .optimizely .ab .config .*;
19
+ import com .optimizely .ab .config .audience .Audience ;
19
20
import org .junit .Before ;
20
21
import org .junit .Test ;
21
22
import org .junit .runner .RunWith ;
22
23
import org .mockito .Mock ;
23
24
import org .mockito .runners .MockitoJUnitRunner ;
24
25
25
- import java .util .ArrayList ;
26
- import java .util .List ;
27
- import java .util .Map ;
26
+ import java .util .*;
28
27
29
28
import static com .optimizely .ab .config .DatafileProjectConfigTestUtils .*;
29
+ import static java .util .Arrays .asList ;
30
+ import static java .util .Collections .singletonList ;
30
31
import static org .junit .Assert .*;
31
32
32
33
@ RunWith (MockitoJUnitRunner .class )
@@ -38,14 +39,14 @@ public class OptimizelyConfigServiceTest {
38
39
39
40
@ Before
40
41
public void initialize () throws Exception {
41
- projectConfig = new DatafileProjectConfig . Builder (). withDatafile ( validConfigJsonV4 ()). build ();
42
+ projectConfig = generateConfig ();
42
43
optimizelyConfigService = new OptimizelyConfigService (projectConfig );
43
44
}
44
45
45
46
@ Test
46
47
public void testGetExperimentsMap () {
47
48
Map <String , OptimizelyExperiment > optimizelyExperimentMap = optimizelyConfigService .getExperimentsMap ();
48
- assertEquals (optimizelyExperimentMap .size (), 13 );
49
+ assertEquals (optimizelyExperimentMap .size (), 2 );
49
50
50
51
List <Experiment > experiments = getAllExperimentsFromDatafile ();
51
52
experiments .forEach (experiment -> {
@@ -72,7 +73,7 @@ public void testRevision() {
72
73
public void testGetFeaturesMap () {
73
74
Map <String , OptimizelyExperiment > optimizelyExperimentMap = optimizelyConfigService .getExperimentsMap ();
74
75
Map <String , OptimizelyFeature > optimizelyFeatureMap = optimizelyConfigService .getFeaturesMap (optimizelyExperimentMap );
75
- assertEquals (optimizelyFeatureMap .size (), 7 );
76
+ assertEquals (optimizelyFeatureMap .size (), 2 );
76
77
77
78
projectConfig .getFeatureFlags ().forEach (featureFlag -> {
78
79
List <String > experimentIds = featureFlag .getExperimentIds ();
@@ -229,4 +230,164 @@ private List<Experiment> getAllExperimentsFromDatafile() {
229
230
experiments .addAll (projectConfig .getExperiments ());
230
231
return experiments ;
231
232
}
233
+
234
+ private ProjectConfig generateConfig () {
235
+ return new DatafileProjectConfig (
236
+ "2360254204" ,
237
+ true ,
238
+ true ,
239
+ "3918735994" ,
240
+ "1480511547" ,
241
+ "4" ,
242
+ asList (
243
+ new Attribute (
244
+ "553339214" ,
245
+ "house"
246
+ ),
247
+ new Attribute (
248
+ "58339410" ,
249
+ "nationality"
250
+ )
251
+ ),
252
+ Collections .<Audience >emptyList (),
253
+ Collections .<Audience >emptyList (),
254
+ asList (
255
+ new EventType (
256
+ "3785620495" ,
257
+ "basic_event" ,
258
+ asList ("1323241596" , "2738374745" , "3042640549" , "3262035800" , "3072915611" )
259
+ ),
260
+ new EventType (
261
+ "3195631717" ,
262
+ "event_with_paused_experiment" ,
263
+ asList ("2667098701" )
264
+ )
265
+ ),
266
+ asList (
267
+ new Experiment (
268
+ "1323241596" ,
269
+ "basic_experiment" ,
270
+ "Running" ,
271
+ "1630555626" ,
272
+ Collections .<String >emptyList (),
273
+ null ,
274
+ asList (
275
+ new Variation (
276
+ "1423767502" ,
277
+ "A" ,
278
+ Collections .<FeatureVariableUsageInstance >emptyList ()
279
+ ),
280
+ new Variation (
281
+ "3433458314" ,
282
+ "B" ,
283
+ Collections .<FeatureVariableUsageInstance >emptyList ()
284
+ )
285
+ ),
286
+ Collections .singletonMap ("Harry Potter" , "A" ),
287
+ asList (
288
+ new TrafficAllocation (
289
+ "1423767502" ,
290
+ 5000
291
+ ),
292
+ new TrafficAllocation (
293
+ "3433458314" ,
294
+ 10000
295
+ )
296
+ )
297
+ ),
298
+ new Experiment (
299
+ "3262035800" ,
300
+ "multivariate_experiment" ,
301
+ "Running" ,
302
+ "3262035800" ,
303
+ asList ("3468206642" ),
304
+ null ,
305
+ asList (
306
+ new Variation (
307
+ "1880281238" ,
308
+ "Fred" ,
309
+ true ,
310
+ asList (
311
+ new FeatureVariableUsageInstance (
312
+ "675244127" ,
313
+ "F"
314
+ ),
315
+ new FeatureVariableUsageInstance (
316
+ "4052219963" ,
317
+ "red"
318
+ )
319
+ )
320
+ ),
321
+ new Variation (
322
+ "3631049532" ,
323
+ "Feorge" ,
324
+ true ,
325
+ asList (
326
+ new FeatureVariableUsageInstance (
327
+ "675244127" ,
328
+ "F"
329
+ ),
330
+ new FeatureVariableUsageInstance (
331
+ "4052219963" ,
332
+ "eorge"
333
+ )
334
+ )
335
+ )
336
+ ),
337
+ Collections .singletonMap ("Fred" , "Fred" ),
338
+ asList (
339
+ new TrafficAllocation (
340
+ "1880281238" ,
341
+ 2500
342
+ ),
343
+ new TrafficAllocation (
344
+ "3631049532" ,
345
+ 5000
346
+ ),
347
+ new TrafficAllocation (
348
+ "4204375027" ,
349
+ 7500
350
+ ),
351
+ new TrafficAllocation (
352
+ "2099211198" ,
353
+ 10000
354
+ )
355
+ )
356
+ )
357
+ ),
358
+ asList (
359
+ new FeatureFlag (
360
+ "4195505407" ,
361
+ "boolean_feature" ,
362
+ "" ,
363
+ Collections .<String >emptyList (),
364
+ Collections .<FeatureVariable >emptyList ()
365
+ ),
366
+ new FeatureFlag (
367
+ "3263342226" ,
368
+ "multi_variate_feature" ,
369
+ "813411034" ,
370
+ asList ("3262035800" ),
371
+ asList (
372
+ new FeatureVariable (
373
+ "675244127" ,
374
+ "first_letter" ,
375
+ "H" ,
376
+ null ,
377
+ FeatureVariable .VariableType .STRING
378
+ ),
379
+ new FeatureVariable (
380
+ "4052219963" ,
381
+ "rest_of_name" ,
382
+ "arry" ,
383
+ null ,
384
+ FeatureVariable .VariableType .STRING
385
+ )
386
+ )
387
+ )
388
+ ),
389
+ Collections .<Group >emptyList (),
390
+ Collections .<Rollout >emptyList ()
391
+ );
392
+ }
232
393
}
0 commit comments