use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_rollout.
@Test
public void decide_rollout() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String flagKey = "feature_1";
String experimentKey = "18322080788";
String variationKey = "18257766532";
String experimentId = "18322080788";
String variationId = "18257766532";
OptimizelyJSON variablesExpected = optimizely.getAllFeatureVariables(flagKey, userId);
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertEquals(decision.getVariationKey(), variationKey);
assertTrue(decision.getEnabled());
assertEquals(decision.getVariables().toMap(), variablesExpected.toMap());
assertEquals(decision.getRuleKey(), experimentKey);
assertEquals(decision.getFlagKey(), flagKey);
assertEquals(decision.getUserContext(), user);
assertTrue(decision.getReasons().isEmpty());
DecisionMetadata metadata = new DecisionMetadata.Builder().setFlagKey(flagKey).setRuleKey(experimentKey).setRuleType(FeatureDecision.DecisionSource.ROLLOUT.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_evaluateAttributeValueOutOfRange.
@Test
public void decideReasons_evaluateAttributeValueOutOfRange() {
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, Collections.singletonMap("age", (float) Math.pow(2, 54)));
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_gotVariationFromUserProfile.
@Test
public void decideReasons_gotVariationFromUserProfile() throws Exception {
// embedding experiment: "exp_no_audience"
String flagKey = "feature_2";
// "exp_no_audience"
String experimentId = "10420810910";
String experimentKey = "exp_no_audience";
String variationId2 = "10418510624";
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, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(decision.getReasons().contains(String.format("Returning previously activated variation \"%s\" of experiment \"%s\" for user \"%s\" from user profile.", variationKey2, experimentKey, userId)));
}
use of com.optimizely.ab.optimizelydecision.OptimizelyDecision in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_featureTest.
// decide
@Test
public void decide_featureTest() {
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";
OptimizelyJSON variablesExpected = optimizely.getAllFeatureVariables(flagKey, userId);
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertEquals(decision.getVariationKey(), variationKey);
assertTrue(decision.getEnabled());
assertEquals(decision.getVariables().toMap(), variablesExpected.toMap());
assertEquals(decision.getRuleKey(), experimentKey);
assertEquals(decision.getFlagKey(), flagKey);
assertEquals(decision.getUserContext(), user);
assertTrue(decision.getReasons().isEmpty());
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_userNotInExperiment.
@Test
public void decideReasons_userNotInExperiment() {
String flagKey = "feature_1";
String experimentKey = "exp_with_audience";
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
assertTrue(decision.getReasons().contains(String.format("User \"%s\" does not meet conditions to be in experiment \"%s\".", userId, experimentKey)));
}
Aggregations