Search in sources :

Example 21 with OptimizelyDecision

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);
}
Also used : ForwardingEventProcessor(com.optimizely.ab.event.ForwardingEventProcessor) OptimizelyJSON(com.optimizely.ab.optimizelyjson.OptimizelyJSON) OptimizelyDecision(com.optimizely.ab.optimizelydecision.OptimizelyDecision) FlagDecisionNotificationBuilder(com.optimizely.ab.notification.DecisionNotification.FlagDecisionNotificationBuilder) DecisionMetadata(com.optimizely.ab.event.internal.payload.DecisionMetadata) Test(org.junit.Test)

Example 22 with OptimizelyDecision

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())));
}
Also used : OptimizelyDecision(com.optimizely.ab.optimizelydecision.OptimizelyDecision) Test(org.junit.Test)

Example 23 with OptimizelyDecision

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)));
}
Also used : OptimizelyDecision(com.optimizely.ab.optimizelydecision.OptimizelyDecision) FlagDecisionNotificationBuilder(com.optimizely.ab.notification.DecisionNotification.FlagDecisionNotificationBuilder) UserProfileService(com.optimizely.ab.bucketing.UserProfileService) Test(org.junit.Test)

Example 24 with OptimizelyDecision

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);
}
Also used : ForwardingEventProcessor(com.optimizely.ab.event.ForwardingEventProcessor) OptimizelyJSON(com.optimizely.ab.optimizelyjson.OptimizelyJSON) OptimizelyDecision(com.optimizely.ab.optimizelydecision.OptimizelyDecision) FlagDecisionNotificationBuilder(com.optimizely.ab.notification.DecisionNotification.FlagDecisionNotificationBuilder) DecisionMetadata(com.optimizely.ab.event.internal.payload.DecisionMetadata) Test(org.junit.Test)

Example 25 with OptimizelyDecision

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)));
}
Also used : OptimizelyDecision(com.optimizely.ab.optimizelydecision.OptimizelyDecision) Test(org.junit.Test)

Aggregations

OptimizelyDecision (com.optimizely.ab.optimizelydecision.OptimizelyDecision)47 Test (org.junit.Test)46 FlagDecisionNotificationBuilder (com.optimizely.ab.notification.DecisionNotification.FlagDecisionNotificationBuilder)12 ForwardingEventProcessor (com.optimizely.ab.event.ForwardingEventProcessor)10 OptimizelyJSON (com.optimizely.ab.optimizelyjson.OptimizelyJSON)9 DecisionMetadata (com.optimizely.ab.event.internal.payload.DecisionMetadata)5 UserProfileService (com.optimizely.ab.bucketing.UserProfileService)2 OptimizelyUserContext (com.optimizely.ab.OptimizelyUserContext)1 OptimizelyDecideOption (com.optimizely.ab.optimizelydecision.OptimizelyDecideOption)1