Search in sources :

Example 11 with Bucketer

use of com.optimizely.ab.bucketing.Bucketer in project java-sdk by optimizely.

the class EventFactoryTest method createConversionEventAndroidClientEngineClientVersion.

/**
 * Verify that supplying {@link ClientEngineInfo} with a custom client engine and client version results in conversion
 * events being sent with the overriden values.
 */
@Test
public void createConversionEventAndroidClientEngineClientVersion() throws Exception {
    ClientEngineInfo.setClientEngine(EventBatch.ClientEngine.ANDROID_SDK);
    Attribute attribute = validProjectConfig.getAttributes().get(0);
    EventType eventType = validProjectConfig.getEventTypes().get(0);
    Bucketer mockBucketAlgorithm = mock(Bucketer.class);
    for (Experiment experiment : validProjectConfig.getExperiments()) {
        when(mockBucketAlgorithm.bucket(experiment, userId, validProjectConfig)).thenReturn(DecisionResponse.responseNoReasons(experiment.getVariations().get(0)));
    }
    Map<String, String> attributeMap = Collections.singletonMap(attribute.getKey(), "value");
    LogEvent conversionEvent = createConversionEvent(validProjectConfig, userId, eventType.getId(), eventType.getKey(), attributeMap, Collections.emptyMap());
    EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
    assertThat(conversion.getClientName(), is(EventBatch.ClientEngine.ANDROID_SDK.getClientEngineValue()));
// assertThat(conversion.getClientVersion(), is("0.0.0"));
}
Also used : ControlAttribute(com.optimizely.ab.internal.ControlAttribute) LogEvent(com.optimizely.ab.event.LogEvent) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Bucketer(com.optimizely.ab.bucketing.Bucketer) Test(org.junit.Test)

Example 12 with Bucketer

use of com.optimizely.ab.bucketing.Bucketer in project java-sdk by optimizely.

the class EventFactoryTest method createConversionParamsWithEventMetrics.

/**
 * Verify that "revenue" and "value" are properly recorded in a conversion request as {@link com.optimizely.ab.event.internal.payload.Event} objects.
 * "revenue" is fixed-point and "value" is floating-point.
 */
@Test
public void createConversionParamsWithEventMetrics() throws Exception {
    Long revenue = 1234L;
    Double value = 13.37;
    // use the "valid" project config and its associated experiment, variation, and attributes
    Attribute attribute = validProjectConfig.getAttributes().get(0);
    EventType eventType = validProjectConfig.getEventTypes().get(0);
    Bucketer mockBucketAlgorithm = mock(Bucketer.class);
    // Bucket to the first variation for all experiments.
    for (Experiment experiment : validProjectConfig.getExperiments()) {
        when(mockBucketAlgorithm.bucket(experiment, userId, validProjectConfig)).thenReturn(DecisionResponse.responseNoReasons(experiment.getVariations().get(0)));
    }
    Map<String, String> attributeMap = Collections.singletonMap(attribute.getKey(), "value");
    Map<String, Object> eventTagMap = new HashMap<String, Object>();
    eventTagMap.put(ReservedEventKey.REVENUE.toString(), revenue);
    eventTagMap.put(ReservedEventKey.VALUE.toString(), value);
    LogEvent conversionEvent = createConversionEvent(validProjectConfig, userId, eventType.getId(), eventType.getKey(), attributeMap, eventTagMap);
    EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
    // we're not going to verify everything, only the event metrics
    assertThat(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getRevenue().longValue(), is(revenue));
    assertThat(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getValue().doubleValue(), is(value));
}
Also used : ControlAttribute(com.optimizely.ab.internal.ControlAttribute) LogEvent(com.optimizely.ab.event.LogEvent) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Bucketer(com.optimizely.ab.bucketing.Bucketer) Test(org.junit.Test)

Aggregations

Bucketer (com.optimizely.ab.bucketing.Bucketer)12 LogEvent (com.optimizely.ab.event.LogEvent)12 Test (org.junit.Test)12 EventType (com.optimizely.ab.config.EventType)9 Experiment (com.optimizely.ab.config.Experiment)9 Variation (com.optimizely.ab.config.Variation)9 EventBatch (com.optimizely.ab.event.internal.payload.EventBatch)9 DecisionService (com.optimizely.ab.bucketing.DecisionService)6 UserProfileService (com.optimizely.ab.bucketing.UserProfileService)6 NoOpErrorHandler (com.optimizely.ab.error.NoOpErrorHandler)6 Attribute (com.optimizely.ab.config.Attribute)5 ErrorHandler (com.optimizely.ab.error.ErrorHandler)5 HashMap (java.util.HashMap)5 ControlAttribute (com.optimizely.ab.internal.ControlAttribute)3 Decision (com.optimizely.ab.event.internal.payload.Decision)2 ArrayList (java.util.ArrayList)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ProjectConfig (com.optimizely.ab.config.ProjectConfig)1 EventBuilder (com.optimizely.ab.event.internal.EventBuilder)1 EventBuilderTest.createExperimentVariationMap (com.optimizely.ab.event.internal.EventBuilderTest.createExperimentVariationMap)1