use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_userMeetsConditionsForTargetingRule.
@Test
public void decideReasons_userMeetsConditionsForTargetingRule() {
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 decideReasons_userNotBucketedIntoVariation.
@Test
public void decideReasons_userNotBucketedIntoVariation() {
String flagKey = "feature_2";
Experiment experiment = getSpyExperiment(flagKey);
when(experiment.getTrafficAllocation()).thenReturn(Arrays.asList(new TrafficAllocation("any-id", 0)));
addSpyExperiment(experiment);
OptimizelyDecision decision = callDecideWithIncludeReasons(flagKey, Collections.singletonMap("age", 25));
assertTrue(decision.getReasons().contains(String.format("User with bucketingId \"%s\" is not in any variation of experiment \"exp_no_audience\".", userId)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_forcedVariationFoundButInvalid.
@Test
public void decideReasons_forcedVariationFoundButInvalid() {
String flagKey = "feature_1";
String variationKey = "invalid-key";
Experiment experiment = getSpyExperiment(flagKey);
when(experiment.getUserIdToVariationKeyMap()).thenReturn(Collections.singletonMap(userId, variationKey));
addSpyExperiment(experiment);
OptimizelyDecision decision = callDecideWithIncludeReasons(flagKey);
assertTrue(decision.getReasons().contains(String.format("Variation \"%s\" is not in the datafile. Not activating user \"%s\".", variationKey, userId)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideOptions_excludeVariables.
@Test
public void decideOptions_excludeVariables() {
String flagKey = "feature_1";
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertTrue(decision.getVariables().toMap().size() > 0);
decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.EXCLUDE_VARIABLES));
assertTrue(decision.getVariables().toMap().size() == 0);
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_evaluateAttributeInvalidType.
@Test
public void decideReasons_evaluateAttributeInvalidType() {
String flagKey = "feature_1";
String audienceId = "13389130056";
Experiment experiment = getSpyExperiment(flagKey);
when(experiment.getAudienceIds()).thenReturn(Arrays.asList(audienceId));
addSpyExperiment(experiment);
OptimizelyDecision decision = callDecideWithIncludeReasons(flagKey, Collections.singletonMap("country", 25));
assertTrue(decision.getReasons().contains(String.format("Audiences for experiment \"%s\" collectively evaluated to null.", experiment.getKey())));
}
Aggregations