Search in sources :

Example 6 with OptimizelyDecision

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

Example 7 with OptimizelyDecision

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

Example 8 with OptimizelyDecision

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

Example 9 with OptimizelyDecision

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

Example 10 with OptimizelyDecision

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())));
}
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