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"));
}
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));
}
Aggregations