Search in sources :

Example 16 with ForwardingEventProcessor

use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.

the class OptimizelyUserContextTest method setForcedDecisionsAndCallDecideDeliveryRuleToDecision.

@Test
public void setForcedDecisionsAndCallDecideDeliveryRuleToDecision() {
    String flagKey = "feature_1";
    String ruleKey = "3332020515";
    String variationKey = "3324490633";
    optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
    OptimizelyUserContext optimizelyUserContext = new OptimizelyUserContext(optimizely, userId, Collections.emptyMap());
    OptimizelyDecisionContext optimizelyDecisionContext = new OptimizelyDecisionContext(flagKey, ruleKey);
    OptimizelyForcedDecision optimizelyForcedDecision = new OptimizelyForcedDecision(variationKey);
    optimizelyUserContext.setForcedDecision(optimizelyDecisionContext, optimizelyForcedDecision);
    assertEquals(variationKey, optimizelyUserContext.getForcedDecision(optimizelyDecisionContext).getVariationKey());
    optimizely.addDecisionNotificationHandler(decisionNotification -> {
        Assert.assertEquals(decisionNotification.getDecisionInfo().get(DECISION_EVENT_DISPATCHED), true);
        isListenerCalled = true;
    });
    isListenerCalled = false;
    // Test to confirm decide uses proper FD
    OptimizelyDecision decision = optimizelyUserContext.decide(flagKey, Arrays.asList(OptimizelyDecideOption.INCLUDE_REASONS));
    assertTrue(isListenerCalled);
    String variationId = "3324490633";
    String experimentId = "3332020515";
    eventHandler.expectImpression(experimentId, variationId, userId, Collections.emptyMap());
    assertNotNull(decision);
    assertTrue(decision.getReasons().contains(String.format("Variation (%s) is mapped to flag (%s), rule (%s) and user (%s) in the forced decision map.", variationKey, flagKey, ruleKey, userId)));
}
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 17 with ForwardingEventProcessor

use of com.optimizely.ab.event.ForwardingEventProcessor 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

ForwardingEventProcessor (com.optimizely.ab.event.ForwardingEventProcessor)17 FlagDecisionNotificationBuilder (com.optimizely.ab.notification.DecisionNotification.FlagDecisionNotificationBuilder)17 Test (org.junit.Test)17 OptimizelyDecision (com.optimizely.ab.optimizelydecision.OptimizelyDecision)10 DecisionMetadata (com.optimizely.ab.event.internal.payload.DecisionMetadata)5 OptimizelyJSON (com.optimizely.ab.optimizelyjson.OptimizelyJSON)5