use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_userDoesntMeetConditionsForTargetingRule.
@Test
public void decideReasons_userDoesntMeetConditionsForTargetingRule() {
String flagKey = "feature_1";
OptimizelyUserContext user = optimizely.createUserContext(userId);
user.setAttribute("country", "CA");
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(decision.getReasons().contains(String.format("User \"%s\" does not meet conditions for targeting rule \"%d\".", userId, 1)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_conditionNoMatchingAudience.
@Test
public void decideReasons_conditionNoMatchingAudience() throws ConfigParseException {
String flagKey = "feature_1";
String audienceId = "invalid_id";
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 decide_doNotSendEvent_withOption.
@Test
public void decide_doNotSendEvent_withOption() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String flagKey = "feature_2";
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.DISABLE_DECISION_EVENT));
assertEquals(decision.getVariationKey(), "variation_with_traffic");
// impression event not expected here
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideOptions_defaultDecideOptions.
@Test
public void decideOptions_defaultDecideOptions() {
List<OptimizelyDecideOption> options = Arrays.asList(OptimizelyDecideOption.EXCLUDE_VARIABLES);
optimizely = Optimizely.builder().withDatafile(datafile).withDefaultDecideOptions(options).build();
String flagKey = "feature_1";
OptimizelyUserContext user = optimizely.createUserContext(userId);
// should be excluded by DefaultDecideOption
OptimizelyDecision decision = user.decide(flagKey);
assertTrue(decision.getVariables().toMap().size() == 0);
decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS, OptimizelyDecideOption.EXCLUDE_VARIABLES));
// other options should work as well
assertTrue(decision.getReasons().size() > 0);
// redundant setting ignored
assertTrue(decision.getVariables().toMap().size() == 0);
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_userNotBucketedIntoExperimentInGroup.
@Test
public void decideReasons_userNotBucketedIntoExperimentInGroup() {
String flagKey = "feature_3";
// "group_exp_2"
String experimentId = "10420843432";
FeatureFlag flag = getSpyFeatureFlag(flagKey);
when(flag.getExperimentIds()).thenReturn(Arrays.asList(experimentId));
addSpyFeatureFlag(flag);
OptimizelyDecision decision = callDecideWithIncludeReasons(flagKey);
assertTrue(decision.getReasons().contains(String.format("User with bucketingId \"tester\" is not in experiment \"group_exp_2\" of group 13142870430.")));
}
Aggregations