Search in sources :

Example 31 with OptimizelyDecision

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

Example 32 with OptimizelyDecision

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

Example 33 with OptimizelyDecision

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

Example 34 with OptimizelyDecision

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

Example 35 with OptimizelyDecision

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.")));
}
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