Search in sources :

Example 6 with RaiseExceptionErrorHandler

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);
}
Also used : EventType(com.optimizely.ab.config.EventType) RaiseExceptionErrorHandler(com.optimizely.ab.error.RaiseExceptionErrorHandler) Test(org.junit.Test)

Example 7 with RaiseExceptionErrorHandler

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, ""));
}
Also used : Experiment(com.optimizely.ab.config.Experiment) RaiseExceptionErrorHandler(com.optimizely.ab.error.RaiseExceptionErrorHandler) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 8 with RaiseExceptionErrorHandler

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);
}
Also used : Experiment(com.optimizely.ab.config.Experiment) RaiseExceptionErrorHandler(com.optimizely.ab.error.RaiseExceptionErrorHandler) Variation(com.optimizely.ab.config.Variation) Test(org.junit.Test)

Aggregations

RaiseExceptionErrorHandler (com.optimizely.ab.error.RaiseExceptionErrorHandler)8 Test (org.junit.Test)8 Experiment (com.optimizely.ab.config.Experiment)7 Variation (com.optimizely.ab.config.Variation)3 Matchers.anyString (org.mockito.Matchers.anyString)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 EventType (com.optimizely.ab.config.EventType)2 LogEvent (com.optimizely.ab.event.LogEvent)2 EventBuilder (com.optimizely.ab.event.internal.EventBuilder)2 EventBuilderTest.createExperimentVariationMap (com.optimizely.ab.event.internal.EventBuilderTest.createExperimentVariationMap)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2