use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_sendEvent_rollout_withSendFlagDecisionsOn.
@Test
public void decide_sendEvent_rollout_withSendFlagDecisionsOn() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
Map<String, Object> attributes = Collections.singletonMap("gender", "f");
OptimizelyUserContext user = optimizely.createUserContext(userId, attributes);
optimizely.addDecisionNotificationHandler(decisionNotification -> {
Assert.assertEquals(decisionNotification.getDecisionInfo().get(DECISION_EVENT_DISPATCHED), true);
isListenerCalled = true;
});
String flagKey = "feature_3";
String experimentId = null;
String variationId = null;
isListenerCalled = false;
user.decide(flagKey);
assertTrue(isListenerCalled);
eventHandler.expectImpression(null, "", userId, attributes);
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_rollout.
@Test
public void decide_rollout() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String flagKey = "feature_1";
String experimentKey = "18322080788";
String variationKey = "18257766532";
String experimentId = "18322080788";
String variationId = "18257766532";
OptimizelyJSON variablesExpected = optimizely.getAllFeatureVariables(flagKey, userId);
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertEquals(decision.getVariationKey(), variationKey);
assertTrue(decision.getEnabled());
assertEquals(decision.getVariables().toMap(), variablesExpected.toMap());
assertEquals(decision.getRuleKey(), experimentKey);
assertEquals(decision.getFlagKey(), flagKey);
assertEquals(decision.getUserContext(), user);
assertTrue(decision.getReasons().isEmpty());
DecisionMetadata metadata = new DecisionMetadata.Builder().setFlagKey(flagKey).setRuleKey(experimentKey).setRuleType(FeatureDecision.DecisionSource.ROLLOUT.toString()).setVariationKey(variationKey).setEnabled(true).build();
eventHandler.expectImpression(experimentId, variationId, userId, Collections.emptyMap(), metadata);
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_featureTest.
// decide
@Test
public void decide_featureTest() {
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";
OptimizelyJSON variablesExpected = optimizely.getAllFeatureVariables(flagKey, userId);
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey);
assertEquals(decision.getVariationKey(), variationKey);
assertTrue(decision.getEnabled());
assertEquals(decision.getVariables().toMap(), variablesExpected.toMap());
assertEquals(decision.getRuleKey(), experimentKey);
assertEquals(decision.getFlagKey(), flagKey);
assertEquals(decision.getUserContext(), user);
assertTrue(decision.getReasons().isEmpty());
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);
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_doNotSendEvent_withOption.
@Test
public void decide_doNotSendEvent_withOption() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String flagKey = "feature_2";
OptimizelyUserContext user = optimizely.createUserContext(userId);
OptimizelyDecision decision = user.decide(flagKey, Arrays.asList(OptimizelyDecideOption.DISABLE_DECISION_EVENT));
assertEquals(decision.getVariationKey(), "variation_with_traffic");
// impression event not expected here
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method setForcedDecisionsAndCallDecideFlagToDecision.
/**
****************************************[START DECIDE TESTS WITH FDs]*****************************************
*/
@Test
public void setForcedDecisionsAndCallDecideFlagToDecision() {
String flagKey = "feature_1";
String variationKey = "a";
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, null);
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 = "10389729780";
String experimentId = "";
DecisionMetadata metadata = new DecisionMetadata.Builder().setFlagKey(flagKey).setRuleKey("").setRuleType("feature-test").setVariationKey(variationKey).setEnabled(true).build();
eventHandler.expectImpression(experimentId, variationId, userId, Collections.emptyMap(), metadata);
assertNotNull(decision);
assertTrue(decision.getReasons().contains(String.format("Variation (%s) is mapped to flag (%s) and user (%s) in the forced decision map.", variationKey, flagKey, userId)));
}
Aggregations