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