use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_forcedVariationFound.
@Test
public void decideReasons_forcedVariationFound() {
String flagKey = "feature_1";
String variationKey = "b";
Experiment experiment = getSpyExperiment(flagKey);
when(experiment.getUserIdToVariationKeyMap()).thenReturn(Collections.singletonMap(userId, variationKey));
addSpyExperiment(experiment);
OptimizelyDecision decision = callDecideWithIncludeReasons(flagKey);
assertTrue(decision.getReasons().contains(String.format("User \"%s\" is forced in variation \"%s\".", userId, variationKey)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideOptions_bypassUPS.
// options
@Test
public void decideOptions_bypassUPS() throws Exception {
// embedding experiment: "exp_no_audience"
String flagKey = "feature_2";
// "exp_no_audience"
String experimentId = "10420810910";
String variationId1 = "10418551353";
String variationId2 = "10418510624";
String variationKey1 = "variation_with_traffic";
String variationKey2 = "variation_no_traffic";
UserProfileService ups = mock(UserProfileService.class);
when(ups.lookup(userId)).thenReturn(createUserProfileMap(experimentId, variationId2));
optimizely = new Optimizely.Builder().withDatafile(datafile).withUserProfileService(ups).build();
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
// should return variationId2 set by UPS
assertEquals(decision.getVariationKey(), variationKey2);
decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.IGNORE_USER_PROFILE_SERVICE));
// should ignore variationId2 set by UPS and return variationId1
assertEquals(decision.getVariationKey(), variationKey1);
// also should not save either
verify(ups, never()).save(anyObject());
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_missingAttributeValue.
@Test
public void decideReasons_missingAttributeValue() {
String flagKey = "feature_1";
String audienceId = "age_18";
Experiment experiment = getSpyExperiment(flagKey);
when(experiment.getAudienceIds()).thenReturn(Arrays.asList(audienceId));
addSpyExperiment(experiment);
OptimizelyDecision decision = callDecideWithIncludeReasons(flagKey);
assertTrue(decision.getReasons().contains(String.format("Audiences for experiment \"%s\" collectively evaluated to null.", experiment.getKey())));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method setForcedDecisionsAndCallDecide.
@Test
public void setForcedDecisionsAndCallDecide() {
String flagKey = "feature_2";
String ruleKey = "exp_no_audience";
String variationKey = "variation_with_traffic";
OptimizelyUserContext optimizelyUserContext = new OptimizelyUserContext(optimizely, userId, Collections.emptyMap());
OptimizelyDecisionContext optimizelyDecisionContext = new OptimizelyDecisionContext(flagKey, ruleKey);
OptimizelyForcedDecision optimizelyForcedDecision = new OptimizelyForcedDecision(variationKey);
optimizelyUserContext.setForcedDecision(optimizelyDecisionContext, optimizelyForcedDecision);
assertEquals(variationKey, optimizelyUserContext.getForcedDecision(optimizelyDecisionContext).getVariationKey());
// Test to confirm decide uses proper FD
OptimizelyDecision decision = optimizelyUserContext.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertNotNull(decision);
assertTrue(decision.getReasons().contains(String.format("Variation (%s) is mapped to flag (%s), rule (%s) and user (%s) in the forced decision map.", variationKey, flagKey, ruleKey, userId)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_sdkNotReady.
// reasons (errors)
@Test
public void decideReasons_sdkNotReady() {
String flagKey = "feature_1";
Optimizely optimizely = new Optimizely.Builder().build();
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertEquals(decision.getReasons().size(), 1);
assertEquals(decision.getReasons().get(0), DecisionMessage.SDK_NOT_READY.reason());
}
Aggregations