use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method trackEvent_noEventTags.
@Test
public void trackEvent_noEventTags() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
Map<String, Object> attributes = Collections.singletonMap("gender", "f");
String eventKey = "event1";
OptimizelyUserContext user = optimizely.createUserContext(userId, attributes);
user.trackEvent(eventKey);
eventHandler.expectConversion(eventKey, userId, attributes);
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method trackEvent_emptyAttributes.
@Test
public void trackEvent_emptyAttributes() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String eventKey = "event1";
Map<String, ?> eventTags = Collections.singletonMap("name", "carrot");
OptimizelyUserContext user = optimizely.createUserContext(userId);
user.trackEvent(eventKey, eventTags);
eventHandler.expectConversion(eventKey, userId, Collections.emptyMap(), eventTags);
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method trackEvent.
// trackEvent
@Test
public void trackEvent() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
Map<String, Object> attributes = Collections.singletonMap("gender", "f");
String eventKey = "event1";
Map<String, Object> eventTags = Collections.singletonMap("name", "carrot");
OptimizelyUserContext user = optimizely.createUserContext(userId, attributes);
user.trackEvent(eventKey, eventTags);
eventHandler.expectConversion(eventKey, userId, attributes, eventTags);
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decideAll_allFlags.
@Test
public void decideAll_allFlags() {
optimizely = new Optimizely.Builder().withDatafile(datafile).withEventProcessor(new ForwardingEventProcessor(eventHandler, null)).build();
String flagKey1 = "feature_1";
String flagKey2 = "feature_2";
String flagKey3 = "feature_3";
Map<String, Object> attributes = Collections.singletonMap("gender", "f");
OptimizelyJSON variablesExpected1 = optimizely.getAllFeatureVariables(flagKey1, userId);
OptimizelyJSON variablesExpected2 = optimizely.getAllFeatureVariables(flagKey2, userId);
OptimizelyJSON variablesExpected3 = new OptimizelyJSON(Collections.emptyMap());
OptimizelyUserContext user = optimizely.createUserContext(userId, attributes);
Map<String, OptimizelyDecision> decisions = user.decideAll();
assertTrue(decisions.size() == 3);
assertEquals(decisions.get(flagKey1), new OptimizelyDecision("a", true, variablesExpected1, "exp_with_audience", flagKey1, user, Collections.emptyList()));
assertEquals(decisions.get(flagKey2), new OptimizelyDecision("variation_with_traffic", true, variablesExpected2, "exp_no_audience", flagKey2, user, Collections.emptyList()));
assertEquals(decisions.get(flagKey3), new OptimizelyDecision(null, false, variablesExpected3, null, flagKey3, user, Collections.emptyList()));
eventHandler.expectImpression("10390977673", "10389729780", userId, attributes);
eventHandler.expectImpression("10420810910", "10418551353", userId, attributes);
eventHandler.expectImpression(null, "", userId, attributes);
}
use of com.optimizely.ab.event.ForwardingEventProcessor in project java-sdk by optimizely.
the class OptimizelyUserContextTest method decide_sendEvent_rollout_withSendFlagDecisionsOff.
@Test
public void decide_sendEvent_rollout_withSendFlagDecisionsOff() {
String datafileWithSendFlagDecisionsOff = datafile.replace("\"sendFlagDecisions\": true", "\"sendFlagDecisions\": false");
optimizely = new Optimizely.Builder().withDatafile(datafileWithSendFlagDecisionsOff).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), false);
isListenerCalled = true;
});
String flagKey = "feature_3";
isListenerCalled = false;
user.decide(flagKey);
assertTrue(isListenerCalled);
// impression event not expected here
}
Aggregations