use of com.optimizely.ab.error.NoOpErrorHandler in project java-sdk by optimizely.
the class OptimizelyTest method getVariationWithUnknownExperimentKeyAndNoOpErrorHandler.
/**
* Verify that {@link Optimizely#getVariation(String, String)} handles the case where an unknown experiment
* (i.e., not in the config) is passed through and a {@link NoOpErrorHandler} is used by default.
*/
@Test
public void getVariationWithUnknownExperimentKeyAndNoOpErrorHandler() throws Exception {
Experiment unknownExperiment = createUnknownExperiment();
Optimizely optimizely = Optimizely.builder(noAudienceDatafile, mockEventHandler).withErrorHandler(new NoOpErrorHandler()).build();
logbackVerifier.expectMessage(Level.ERROR, "Experiment \"unknown_experiment\" is not in the datafile");
// since we use a NoOpErrorHandler, we should fail and return null
Variation actualVariation = optimizely.getVariation(unknownExperiment.getKey(), testUserId);
// verify that null is returned, as no project config was available
assertNull(actualVariation);
}
use of com.optimizely.ab.error.NoOpErrorHandler in project java-sdk by optimizely.
the class EventBuilderTest method createConversionEventForcedVariationBucketingPrecedesAudienceEval.
/**
* Verify that precedence is given to forced variation bucketing over audience evaluation when constructing a
* conversion event.
*/
@Test
public void createConversionEventForcedVariationBucketingPrecedesAudienceEval() {
EventType eventType;
String whitelistedUserId;
if (datafileVersion == 4) {
eventType = validProjectConfig.getEventNameMapping().get(EVENT_BASIC_EVENT_KEY);
whitelistedUserId = MULTIVARIATE_EXPERIMENT_FORCED_VARIATION_USER_ID_GRED;
} else {
eventType = validProjectConfig.getEventTypes().get(0);
whitelistedUserId = "testUser1";
}
DecisionService decisionService = new DecisionService(new Bucketer(validProjectConfig), new NoOpErrorHandler(), validProjectConfig, mock(UserProfileService.class));
// attributes are empty so user won't be in the audience for experiment using the event, but bucketing
// will still take place
Map<Experiment, Variation> experimentVariationMap = createExperimentVariationMap(validProjectConfig, decisionService, eventType.getKey(), whitelistedUserId, Collections.<String, String>emptyMap());
LogEvent conversionEvent = builder.createConversionEvent(validProjectConfig, experimentVariationMap, whitelistedUserId, eventType.getId(), eventType.getKey(), Collections.<String, String>emptyMap(), Collections.<String, Object>emptyMap());
assertNotNull(conversionEvent);
EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
if (datafileVersion == 4) {
// 2 experiments use the event
// basic experiment has no audience
// user is whitelisted in to one audience
assertEquals(2, conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions().size());
} else {
assertEquals(1, conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions().size());
}
}
use of com.optimizely.ab.error.NoOpErrorHandler in project java-sdk by optimizely.
the class OptimizelyTest method trackEventWithUnknownEventKeyAndNoOpErrorHandler.
/**
* Verify that {@link Optimizely#track(String, String)} handles the case where an unknown event type
* (i.e., not in the config) is passed through and a {@link NoOpErrorHandler} is used by default.
*/
@Test
public void trackEventWithUnknownEventKeyAndNoOpErrorHandler() throws Exception {
EventType unknownEventType = createUnknownEventType();
Optimizely optimizely = Optimizely.builder(validDatafile, mockEventHandler).withConfig(validProjectConfig).withErrorHandler(new NoOpErrorHandler()).build();
logbackVerifier.expectMessage(Level.ERROR, "Event \"unknown_event_type\" is not in the datafile.");
logbackVerifier.expectMessage(Level.INFO, "Not tracking event \"unknown_event_type\" for user \"userId\".");
optimizely.track(unknownEventType.getKey(), testUserId);
// verify that we did NOT dispatch an event
verify(mockEventHandler, never()).dispatchEvent(any(LogEvent.class));
}
Aggregations