use of com.optimizely.ab.event.internal.payload.DecisionMetadata in project java-sdk by optimizely.
the class UserEventFactoryTest method setUp.
@Before
public void setUp() {
experiment = new Experiment(EXPERIMENT_ID, EXPERIMENT_KEY, LAYER_ID);
variation = new Variation(VARIATION_ID, VARIATION_KEY);
decisionMetadata = new DecisionMetadata("", EXPERIMENT_KEY, "experiment", VARIATION_KEY, true);
}
use of com.optimizely.ab.event.internal.payload.DecisionMetadata in project java-sdk by optimizely.
the class UserEventFactory method createImpressionEvent.
public static ImpressionEvent createImpressionEvent(@Nonnull ProjectConfig projectConfig, @Nullable Experiment activatedExperiment, @Nullable Variation variation, @Nonnull String userId, @Nonnull Map<String, ?> attributes, @Nonnull String flagKey, @Nonnull String ruleType, @Nonnull boolean enabled) {
if ((FeatureDecision.DecisionSource.ROLLOUT.toString().equals(ruleType) || variation == null) && !projectConfig.getSendFlagDecisions()) {
return null;
}
String variationKey = "";
String variationID = "";
String layerID = null;
String experimentId = null;
String experimentKey = "";
if (variation != null) {
variationKey = variation.getKey();
variationID = variation.getId();
layerID = activatedExperiment != null ? activatedExperiment.getLayerId() : "";
experimentId = activatedExperiment != null ? activatedExperiment.getId() : "";
experimentKey = activatedExperiment != null ? activatedExperiment.getKey() : "";
}
UserContext userContext = new UserContext.Builder().withUserId(userId).withAttributes(attributes).withProjectConfig(projectConfig).build();
DecisionMetadata metadata = new DecisionMetadata.Builder().setFlagKey(flagKey).setRuleKey(experimentKey).setRuleType(ruleType).setVariationKey(variationKey).setEnabled(enabled).build();
return new ImpressionEvent.Builder().withUserContext(userContext).withLayerId(layerID).withExperimentId(experimentId).withExperimentKey(experimentKey).withVariationId(variationID).withVariationKey(variationKey).withMetadata(metadata).build();
}
use of com.optimizely.ab.event.internal.payload.DecisionMetadata 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)));
}
use of com.optimizely.ab.event.internal.payload.DecisionMetadata 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