use of com.optimizely.ab.error.RaiseExceptionErrorHandler in project java-sdk by optimizely.
the class OptimizelyTest method trackEventWithUnknownEventKeyAndRaiseExceptionErrorHandler.
/**
* 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 RaiseExceptionErrorHandler} is provided.
*/
@Test
public void trackEventWithUnknownEventKeyAndRaiseExceptionErrorHandler() throws Exception {
thrown.expect(UnknownEventTypeException.class);
EventType unknownEventType = createUnknownEventType();
Optimizely optimizely = Optimizely.builder(validDatafile, mockEventHandler).withConfig(validProjectConfig).withErrorHandler(new RaiseExceptionErrorHandler()).build();
// since we use a RaiseExceptionErrorHandler, we should throw an error
optimizely.track(unknownEventType.getKey(), testUserId);
}
use of com.optimizely.ab.error.RaiseExceptionErrorHandler in project java-sdk by optimizely.
the class OptimizelyTest method activateWithEmptyUserId.
/**
* Verify that {@link Optimizely#activate(String, String)} doesn't return a variation when provided an empty string.
*/
@Test
public void activateWithEmptyUserId() throws Exception {
Experiment experiment = noAudienceProjectConfig.getExperiments().get(0);
String experimentKey = experiment.getKey();
Optimizely optimizely = Optimizely.builder(noAudienceDatafile, mockEventHandler).withConfig(noAudienceProjectConfig).withErrorHandler(new RaiseExceptionErrorHandler()).build();
logbackVerifier.expectMessage(Level.ERROR, "Non-empty user ID required");
logbackVerifier.expectMessage(Level.INFO, "Not activating user for experiment \"" + experimentKey + "\".");
assertNull(optimizely.activate(experimentKey, ""));
}
use of com.optimizely.ab.error.RaiseExceptionErrorHandler in project java-sdk by optimizely.
the class OptimizelyTest method activateWhenExperimentIsNotInProject.
/**
* Verify the case were {@link Optimizely#activate(Experiment, String)} is called with an {@link Experiment}
* that is not present in the current {@link ProjectConfig}. We should NOT throw an error in that case.
*
* This may happen if an experiment is retrieved from the project config, the project config is updated and the
* referenced experiment removed, then activate is called given the now removed experiment.
* Could also happen if an experiment was manually created and passed through.
*/
@Test
public void activateWhenExperimentIsNotInProject() throws Exception {
Experiment unknownExperiment = createUnknownExperiment();
Variation bucketedVariation = unknownExperiment.getVariations().get(0);
Optimizely optimizely = Optimizely.builder(validDatafile, mockEventHandler).withBucketing(mockBucketer).withConfig(validProjectConfig).withErrorHandler(new RaiseExceptionErrorHandler()).build();
when(mockBucketer.bucket(unknownExperiment, testUserId)).thenReturn(bucketedVariation);
optimizely.activate(unknownExperiment, testUserId);
}
Aggregations