use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.
the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTargetingInPreviousRulesButPassesRule3.
/**
* Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
* returns the variation of "English Citizens" rule
* when the user fails targeting for previous rules, but passes targeting and traffic for Rule 3.
*/
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTargetingInPreviousRulesButPassesRule3() {
Bucketer mockBucketer = mock(Bucketer.class);
Rollout rollout = ROLLOUT_2;
Experiment englishCitizensRule = rollout.getExperiments().get(2);
Variation englishCitizenVariation = englishCitizensRule.getVariations().get(0);
Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
Variation everyoneElseVariation = everyoneElseRule.getVariations().get(0);
when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null);
when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(everyoneElseVariation);
when(mockBucketer.bucket(eq(englishCitizensRule), anyString())).thenReturn(englishCitizenVariation);
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, Collections.singletonMap(ATTRIBUTE_NATIONALITY_KEY, AUDIENCE_ENGLISH_CITIZENS_VALUE));
assertEquals(englishCitizenVariation, featureDecision.variation);
assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
// verify user is only bucketed once for everyone else rule
verify(mockBucketer, times(1)).bucket(any(Experiment.class), anyString());
}
use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.
the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsAllAudienceButSatisfiesTraffic.
/**
* Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
* returns the variation of "Everyone Else" rule
* when the user fails targeting for all rules, but is bucketed into the "Everyone Else" rule.
*/
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsAllAudienceButSatisfiesTraffic() {
Bucketer mockBucketer = mock(Bucketer.class);
Rollout rollout = ROLLOUT_2;
Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
Variation expectedVariation = everyoneElseRule.getVariations().get(0);
when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation);
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, Collections.<String, String>emptyMap());
assertEquals(expectedVariation, featureDecision.variation);
assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
// verify user is only bucketed once for everyone else rule
verify(mockBucketer, times(1)).bucket(any(Experiment.class), anyString());
}
use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.
the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleAndPassesInEveryoneElse.
/**
* Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
* returns the variation of "Everyone Else" rule
* when the user passes targeting for a rule, but was failed the traffic allocation for that rule,
* and is bucketed successfully into the "Everyone Else" rule.
*/
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleAndPassesInEveryoneElse() {
Bucketer mockBucketer = mock(Bucketer.class);
Rollout rollout = ROLLOUT_2;
Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
Variation expectedVariation = everyoneElseRule.getVariations().get(0);
when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null);
when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation);
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, Collections.singletonMap(ATTRIBUTE_HOUSE_KEY, AUDIENCE_GRYFFINDOR_VALUE));
assertEquals(expectedVariation, featureDecision.variation);
assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
// verify user is only bucketed once for everyone else rule
verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString());
}
use of com.optimizely.ab.config.Rollout in project java-sdk by optimizely.
the class DecisionServiceTest method getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleButWouldPassForAnotherRuleAndPassesInEveryoneElse.
/**
* Verify that {@link DecisionService#getVariationForFeatureInRollout(FeatureFlag, String, Map)}
* returns the variation of "Everyone Else" rule
* when the user passes targeting for a rule, but was failed the traffic allocation for that rule,
* and is bucketed successfully into the "Everyone Else" rule.
* Fallback bucketing should not evaluate any other audiences.
* Even though the user would satisfy a later rollout rule, they are never evaluated for it or bucketed into it.
*/
@Test
public void getVariationForFeatureInRolloutReturnsVariationWhenUserFailsTrafficInRuleButWouldPassForAnotherRuleAndPassesInEveryoneElse() {
Bucketer mockBucketer = mock(Bucketer.class);
Rollout rollout = ROLLOUT_2;
Experiment englishCitizensRule = rollout.getExperiments().get(2);
Variation englishCitizenVariation = englishCitizensRule.getVariations().get(0);
Experiment everyoneElseRule = rollout.getExperiments().get(rollout.getExperiments().size() - 1);
Variation expectedVariation = everyoneElseRule.getVariations().get(0);
when(mockBucketer.bucket(any(Experiment.class), anyString())).thenReturn(null);
when(mockBucketer.bucket(eq(everyoneElseRule), anyString())).thenReturn(expectedVariation);
when(mockBucketer.bucket(eq(englishCitizensRule), anyString())).thenReturn(englishCitizenVariation);
DecisionService decisionService = new DecisionService(mockBucketer, mockErrorHandler, v4ProjectConfig, null);
FeatureDecision featureDecision = decisionService.getVariationForFeatureInRollout(FEATURE_FLAG_MULTI_VARIATE_FEATURE, genericUserId, ProjectConfigTestUtils.createMapOfObjects(ProjectConfigTestUtils.createListOfObjects(ATTRIBUTE_HOUSE_KEY, ATTRIBUTE_NATIONALITY_KEY), ProjectConfigTestUtils.createListOfObjects(AUDIENCE_GRYFFINDOR_VALUE, AUDIENCE_ENGLISH_CITIZENS_VALUE)));
assertEquals(expectedVariation, featureDecision.variation);
assertEquals(FeatureDecision.DecisionSource.ROLLOUT, featureDecision.decisionSource);
// verify user is only bucketed once for everyone else rule
verify(mockBucketer, times(2)).bucket(any(Experiment.class), anyString());
}
Aggregations