use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_userAttributeInvalidMatch.
@Test
public void decideReasons_userAttributeInvalidMatch() {
String flagKey = "feature_1";
String audienceId = "invalid_match";
Experiment experiment = getSpyExperiment(flagKey);
when(experiment.getAudienceIds()).thenReturn(Arrays.asList(audienceId));
addSpyExperiment(experiment);
OptimizelyDecision decision = callDecideWithIncludeReasons(flagKey, Collections.singletonMap("age", 25));
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 decideReasons_userBucketedIntoExperimentInGroup.
@Test
public void decideReasons_userBucketedIntoExperimentInGroup() {
String flagKey = "feature_3";
// "group_exp_1"
String experimentId = "10390965532";
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 in experiment \"group_exp_1\" of group 13142870430.")));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideAll_oneFlag.
// decideAll
@Test
public void decideAll_oneFlag() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String flagKey = "feature_2";
String experimentKey = "exp_no_audience";
String variationKey = "variation_with_traffic";
String experimentId = "10420810910";
String variationId = "10418551353";
List<String> flagKeys = Arrays.asList(flagKey);
OptimizelyJSON variablesExpected = optimizely.getAllFeatureVariables(flagKey, userId);
OptimizelyUserContext user = optimizely.createUserContext(userId);
Map<String, OptimizelyDecision> decisions = user.decideForKeys(flagKeys);
assertTrue(decisions.size() == 1);
OptimizelyDecision decision = decisions.get(flagKey);
OptimizelyDecision expDecision = new OptimizelyDecision(variationKey, true, variablesExpected, experimentKey, flagKey, user, Collections.emptyList());
assertEquals(decision, expDecision);
DecisionMetadata metadata = new DecisionMetadata.Builder().setFlagKey(flagKey).setRuleKey(experimentKey).setRuleType(FeatureDecision.DecisionSource.FEATURE_TEST.toString()).setVariationKey(variationKey).setEnabled(true).build();
eventHandler.expectImpression(experimentId, variationId, userId, Collections.emptyMap(), metadata);
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideReasons_userBucketedIntoVariationInExperiment.
@Test
public void decideReasons_userBucketedIntoVariationInExperiment() {
String flagKey = "feature_2";
String experimentKey = "exp_no_audience";
String variationKey = "variation_with_traffic";
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(decision.getReasons().contains(String.format("User with bucketingId \"%s\" is in variation \"%s\" of experiment \"%s\".", userId, variationKey, experimentKey)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideAll_errorDecisionIncluded.
@Test
public void decideAll_errorDecisionIncluded() {
String flagKey1 = "feature_2";
String flagKey2 = "invalid_key";
List<String> flagKeys = Arrays.asList(flagKey1, flagKey2);
OptimizelyJSON variablesExpected1 = optimizely.getAllFeatureVariables(flagKey1, userId);
OptimizelyUserContext user = optimizely.createUserContext(userId);
Map<String, OptimizelyDecision> decisions = user.decideForKeys(flagKeys);
assertEquals(decisions.size(), 2);
assertEquals(decisions.get(flagKey1), new OptimizelyDecision("variation_with_traffic", true, variablesExpected1, "exp_no_audience", flagKey1, user, Collections.emptyList()));
assertEquals(decisions.get(flagKey2), OptimizelyDecision.newErrorDecision(flagKey2, user, DecisionMessage.FLAG_KEY_INVALID.reason(flagKey2)));
}
Aggregations