|
17 | 17 |
|
18 | 18 | import ch.qos.logback.classic.Level;
|
19 | 19 | import com.google.common.collect.ImmutableMap;
|
| 20 | +import com.google.common.collect.Ordering; |
20 | 21 | import com.optimizely.ab.bucketing.Bucketer;
|
21 | 22 | import com.optimizely.ab.bucketing.DecisionService;
|
22 | 23 | import com.optimizely.ab.bucketing.FeatureDecision;
|
@@ -3633,6 +3634,36 @@ public void getEnabledFeatureWithValidUserId() throws ConfigParseException{
|
3633 | 3634 |
|
3634 | 3635 | }
|
3635 | 3636 |
|
| 3637 | + /** |
| 3638 | + * Verify {@link Optimizely#getEnabledFeatures(String, Map)} calls into |
| 3639 | + * {@link Optimizely#isFeatureEnabled(String, String, Map)} for each featureFlag |
| 3640 | + * return sorted List of FeatureFlags |
| 3641 | + * Also checks that the orignal list directly from projectConfig is unsorted |
| 3642 | + */ |
| 3643 | + @Test |
| 3644 | + public void getEnabledFeatureCheckingListIsSorted() throws ConfigParseException{ |
| 3645 | + assumeTrue(datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString())); |
| 3646 | + |
| 3647 | + Optimizely spyOptimizely = spy(Optimizely.builder(validDatafile, mockEventHandler) |
| 3648 | + .withConfig(validProjectConfig) |
| 3649 | + .build()); |
| 3650 | + ArrayList<String> featureFlagsSortedList = (ArrayList<String>) spyOptimizely.getEnabledFeatures(genericUserId, |
| 3651 | + new HashMap<String, String>()); |
| 3652 | + assertFalse(featureFlagsSortedList.isEmpty()); |
| 3653 | + |
| 3654 | + //To get Unsorted list directly from project config |
| 3655 | + List<String> unSortedFeaturesListFromProjectConfig = new ArrayList<String>(); |
| 3656 | + for (FeatureFlag featureFlag : spyOptimizely.projectConfig.getFeatureFlags()){ |
| 3657 | + String featureKey = featureFlag.getKey(); |
| 3658 | + unSortedFeaturesListFromProjectConfig.add(featureKey); |
| 3659 | + } |
| 3660 | + |
| 3661 | + //unSortedFeaturesListFromProjectConfig will retain only the elements which are also contained in featureFlagsSortedList. |
| 3662 | + unSortedFeaturesListFromProjectConfig.retainAll(featureFlagsSortedList); |
| 3663 | + assertFalse(Ordering.natural().isOrdered(unSortedFeaturesListFromProjectConfig)); |
| 3664 | + |
| 3665 | + assertTrue(Ordering.natural().isOrdered(featureFlagsSortedList)); |
| 3666 | + } |
3636 | 3667 |
|
3637 | 3668 | /**
|
3638 | 3669 | * Verify {@link Optimizely#getEnabledFeatures(String, Map)} calls into
|
|
0 commit comments