Skip to content

Commit 4b8d019

Browse files
committed
Updated OptimizelyConfigServiceTest by removing the dependency of config json file and created hardcoded config
1 parent b3766bf commit 4b8d019

File tree

1 file changed

+167
-6
lines changed

1 file changed

+167
-6
lines changed

core-api/src/test/java/com/optimizely/ab/optimizelyconfig/OptimizelyConfigServiceTest.java

Lines changed: 167 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,18 @@
1616
package com.optimizely.ab.optimizelyconfig;
1717

1818
import com.optimizely.ab.config.*;
19+
import com.optimizely.ab.config.audience.Audience;
1920
import org.junit.Before;
2021
import org.junit.Test;
2122
import org.junit.runner.RunWith;
2223
import org.mockito.Mock;
2324
import org.mockito.runners.MockitoJUnitRunner;
2425

25-
import java.util.ArrayList;
26-
import java.util.List;
27-
import java.util.Map;
26+
import java.util.*;
2827

2928
import static com.optimizely.ab.config.DatafileProjectConfigTestUtils.*;
29+
import static java.util.Arrays.asList;
30+
import static java.util.Collections.singletonList;
3031
import static org.junit.Assert.*;
3132

3233
@RunWith(MockitoJUnitRunner.class)
@@ -38,14 +39,14 @@ public class OptimizelyConfigServiceTest {
3839

3940
@Before
4041
public void initialize() throws Exception {
41-
projectConfig = new DatafileProjectConfig.Builder().withDatafile(validConfigJsonV4()).build();
42+
projectConfig = generateConfig();
4243
optimizelyConfigService = new OptimizelyConfigService(projectConfig);
4344
}
4445

4546
@Test
4647
public void testGetExperimentsMap() {
4748
Map<String, OptimizelyExperiment> optimizelyExperimentMap = optimizelyConfigService.getExperimentsMap();
48-
assertEquals(optimizelyExperimentMap.size(), 13);
49+
assertEquals(optimizelyExperimentMap.size(), 2);
4950

5051
List<Experiment> experiments = getAllExperimentsFromDatafile();
5152
experiments.forEach(experiment -> {
@@ -72,7 +73,7 @@ public void testRevision() {
7273
public void testGetFeaturesMap() {
7374
Map<String, OptimizelyExperiment> optimizelyExperimentMap = optimizelyConfigService.getExperimentsMap();
7475
Map<String, OptimizelyFeature> optimizelyFeatureMap = optimizelyConfigService.getFeaturesMap(optimizelyExperimentMap);
75-
assertEquals(optimizelyFeatureMap.size(), 7);
76+
assertEquals(optimizelyFeatureMap.size(), 2);
7677

7778
projectConfig.getFeatureFlags().forEach(featureFlag -> {
7879
List<String> experimentIds = featureFlag.getExperimentIds();
@@ -229,4 +230,164 @@ private List<Experiment> getAllExperimentsFromDatafile() {
229230
experiments.addAll(projectConfig.getExperiments());
230231
return experiments;
231232
}
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+
}
232393
}

0 commit comments

Comments
 (0)