Search in sources :

Example 21 with OptimizelyJSON

use of com.optimizely.ab.optimizelyjson.OptimizelyJSON in project java-sdk by optimizely.

the class OptimizelyUserContextTest method decide_nullVariation.

@Test
public void decide_nullVariation() {
    optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
    String flagKey = "feature_3";
    OptimizelyJSON variablesExpected = new OptimizelyJSON(Collections.emptyMap());
    OptimizelyUserContext user = optimizely.createUserContext(userId);
    OptimizelyDecision decision = user.decide(flagKey);
    assertEquals(decision.getVariationKey(), null);
    assertFalse(decision.getEnabled());
    assertEquals(decision.getVariables().toMap(), variablesExpected.toMap());
    assertEquals(decision.getRuleKey(), null);
    assertEquals(decision.getFlagKey(), flagKey);
    assertEquals(decision.getUserContext(), user);
    assertTrue(decision.getReasons().isEmpty());
    DecisionMetadata metadata = new DecisionMetadata.Builder().setFlagKey(flagKey).setRuleKey("").setRuleType(FeatureDecision.DecisionSource.ROLLOUT.toString()).setVariationKey("").setEnabled(false).build();
    eventHandler.expectImpression(null, "", 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)

Aggregations

OptimizelyJSON (com.optimizely.ab.optimizelyjson.OptimizelyJSON)21 Test (org.junit.Test)17 OptimizelyDecision (com.optimizely.ab.optimizelydecision.OptimizelyDecision)9 ForwardingEventProcessor (com.optimizely.ab.event.ForwardingEventProcessor)5 FlagDecisionNotificationBuilder (com.optimizely.ab.notification.DecisionNotification.FlagDecisionNotificationBuilder)5 DecisionMetadata (com.optimizely.ab.event.internal.payload.DecisionMetadata)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)4 FeatureDecision (com.optimizely.ab.bucketing.FeatureDecision)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 OptimizelyUserContext (com.optimizely.ab.OptimizelyUserContext)2 VisibleForTesting (com.optimizely.ab.annotations.VisibleForTesting)1 ArrayList (java.util.ArrayList)1 Nullable (javax.annotation.Nullable)1