Search in sources :

Example 16 with OptimizelyDecision

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

Example 17 with OptimizelyDecision

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

Example 18 with OptimizelyDecision

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);
}
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 19 with OptimizelyDecision

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

Example 20 with OptimizelyDecision

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)));
}
Also used : OptimizelyJSON(com.optimizely.ab.optimizelyjson.OptimizelyJSON) 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