use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method setForcedDecisionsAndCallDecideExperimentRuleToDecision.
@Test
public void setForcedDecisionsAndCallDecideExperimentRuleToDecision() {
String flagKey = "feature_1";
String ruleKey = "exp_with_audience";
String variationKey = "a";
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
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());
optimizely.addDecisionNotificationHandler(decisionNotification -> {
Assert.assertEquals(decisionNotification.getDecisionInfo().get(DECISION_EVENT_DISPATCHED), true);
isListenerCalled = true;
});
isListenerCalled = false;
// Test to confirm decide uses proper FD
OptimizelyDecision decision = optimizelyUserContext.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(isListenerCalled);
String variationId = "10389729780";
String experimentId = "10390977673";
eventHandler.expectImpression(experimentId, variationId, userId, Collections.emptyMap());
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_userNotBucketedIntoTargetingRule.
@Test
public void decideReasons_userNotBucketedIntoTargetingRule() {
String flagKey = "feature_1";
// experimentKey of rollout[2]
String experimentKey = "3332020494";
OptimizelyUserContext user = optimizely.createUserContext(userId);
user.setAttribute("browser", "safari");
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(decision.getReasons().contains(String.format("User with bucketingId \"%s\" is not in any variation of experiment \"%s\".", userId, experimentKey)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_sdkNotReady.
// errors
@Test
public void decide_sdkNotReady() {
String flagKey = "feature_1";
Optimizely optimizely = new Optimizely.Builder().build();
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertNull(decision.getVariationKey());
assertFalse(decision.getEnabled());
assertTrue(decision.getVariables().isEmpty());
assertEquals(decision.getFlagKey(), flagKey);
assertEquals(decision.getUserContext(), user);
assertEquals(decision.getReasons().size(), 1);
assertEquals(decision.getReasons().get(0), DecisionMessage.SDK_NOT_READY.reason());
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_userBucketedIntoTargetingRule.
@Test
public void decideReasons_userBucketedIntoTargetingRule() {
String flagKey = "feature_1";
OptimizelyUserContext user = optimizely.createUserContext(userId);
user.setAttribute("country", "US");
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(decision.getReasons().contains(String.format("The user \"%s\" was bucketed into a rollout for feature flag \"%s\".", userId, flagKey)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_sendEvent.
// send events
@Test
public void decide_sendEvent() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String flagKey = "feature_2";
String variationKey = "variation_with_traffic";
String experimentId = "10420810910";
String variationId = "10418551353";
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertEquals(decision.getVariationKey(), variationKey);
eventHandler.expectImpression(experimentId, variationId, userId, Collections.emptyMap());
}
Aggregations