use of com.optimizely.ab.event.LogEvent in project java-sdk by optimizely.
the class EventFactoryTest method createConversionEventExperimentStatusPrecedesForcedVariation.
/**
* Verify conversion event is always created.
*/
@Test
public void createConversionEventExperimentStatusPrecedesForcedVariation() {
EventType eventType;
if (datafileVersion == 4) {
eventType = validProjectConfig.getEventNameMapping().get(EVENT_PAUSED_EXPERIMENT_KEY);
} else {
eventType = validProjectConfig.getEventTypes().get(3);
}
String whitelistedUserId = PAUSED_EXPERIMENT_FORCED_VARIATION_USER_ID_CONTROL;
LogEvent conversionEvent = createConversionEvent(validProjectConfig, whitelistedUserId, eventType.getId(), eventType.getKey(), Collections.emptyMap(), Collections.emptyMap());
assertNotNull(conversionEvent);
}
use of com.optimizely.ab.event.LogEvent in project java-sdk by optimizely.
the class EventFactoryTest method createConversionEventAndroidTVClientEngineClientVersion.
/**
* Verify that supplying {@link ClientEngineInfo} with a Android TV client engine and client version results in
* conversion events being sent with the overriden values.
*/
@Test
public void createConversionEventAndroidTVClientEngineClientVersion() throws Exception {
String clientVersion = "0.0.0";
ClientEngineInfo.setClientEngine(EventBatch.ClientEngine.ANDROID_TV_SDK);
ProjectConfig projectConfig = validProjectConfigV2();
Attribute attribute = projectConfig.getAttributes().get(0);
EventType eventType = projectConfig.getEventTypes().get(0);
String userId = "userId";
Bucketer mockBucketAlgorithm = mock(Bucketer.class);
for (Experiment experiment : projectConfig.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(projectConfig, userId, eventType.getId(), eventType.getKey(), attributeMap, Collections.emptyMap());
EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
assertThat(conversion.getClientName(), is(EventBatch.ClientEngine.ANDROID_TV_SDK.getClientEngineValue()));
// assertThat(conversion.getClientVersion(), is(clientVersion));
}
use of com.optimizely.ab.event.LogEvent in project java-sdk by optimizely.
the class EventFactoryTest method createConversionEventReturnsNotNullWhenExperimentVariationMapIsEmpty.
/**
* Verify that supplying an empty Experiment Variation map returns an Event {@link LogEvent}.
*/
@Test
public void createConversionEventReturnsNotNullWhenExperimentVariationMapIsEmpty() {
EventType eventType = validProjectConfig.getEventTypes().get(0);
LogEvent conversionEvent = createConversionEvent(validProjectConfig, userId, eventType.getId(), eventType.getKey(), Collections.<String, String>emptyMap(), Collections.<String, String>emptyMap());
assertNotNull(conversionEvent);
}
use of com.optimizely.ab.event.LogEvent in project java-sdk by optimizely.
the class EventFactoryTest method createConversionEventPassingUserAgentAttribute.
/**
* Verify {@link com.optimizely.ab.event.internal.payload.EventBatch} event creation
* passing User Agent reserved attribute in attribute map and to check it exist in visitors.attributes
*/
@Test
public void createConversionEventPassingUserAgentAttribute() throws Exception {
// use the "valid" project config and its associated experiment, variation, and attributes
Attribute attribute = validProjectConfig.getAttributes().get(0);
EventType eventType = validProjectConfig.getEventTypes().get(0);
String userId = "userId";
Map<String, String> attributeMap = new HashMap<String, String>();
attributeMap.put(attribute.getKey(), AUDIENCE_GRYFFINDOR_VALUE);
attributeMap.put(ControlAttribute.USER_AGENT_ATTRIBUTE.toString(), "Chrome");
Map<String, Object> eventTagMap = new HashMap<String, Object>();
eventTagMap.put("boolean_param", false);
eventTagMap.put("string_param", "123");
LogEvent conversionEvent = createConversionEvent(validProjectConfig, userId, eventType.getId(), eventType.getKey(), attributeMap, eventTagMap);
// verify that the request endpoint is correct
assertThat(conversionEvent.getEndpointUrl(), is(EventFactory.EVENT_ENDPOINT));
EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
// verify payload information
assertThat(conversion.getVisitors().get(0).getVisitorId(), is(userId));
assertThat(conversion.getProjectId(), is(validProjectConfig.getProjectId()));
assertThat(conversion.getAccountId(), is(validProjectConfig.getAccountId()));
com.optimizely.ab.event.internal.payload.Attribute feature = new com.optimizely.ab.event.internal.payload.Attribute.Builder().setEntityId(attribute.getId()).setKey(attribute.getKey()).setType(com.optimizely.ab.event.internal.payload.Attribute.CUSTOM_ATTRIBUTE_TYPE).setValue(AUDIENCE_GRYFFINDOR_VALUE).build();
com.optimizely.ab.event.internal.payload.Attribute userAgentFeature = new com.optimizely.ab.event.internal.payload.Attribute.Builder().setEntityId(ControlAttribute.USER_AGENT_ATTRIBUTE.toString()).setKey(ControlAttribute.USER_AGENT_ATTRIBUTE.toString()).setType(com.optimizely.ab.event.internal.payload.Attribute.CUSTOM_ATTRIBUTE_TYPE).setValue("Chrome").build();
List<com.optimizely.ab.event.internal.payload.Attribute> expectedUserFeatures = new ArrayList<com.optimizely.ab.event.internal.payload.Attribute>();
expectedUserFeatures.add(userAgentFeature);
expectedUserFeatures.add(feature);
if (datafileVersion >= Integer.parseInt(ProjectConfig.Version.V4.toString())) {
expectedUserFeatures.add(getBotFilteringAttribute());
}
assertEquals(conversion.getVisitors().get(0).getAttributes(), expectedUserFeatures);
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getEntityId(), eventType.getId());
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getKey(), eventType.getKey());
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getRevenue(), null);
assertTrue(conversion.getVisitors().get(0).getAttributes().containsAll(expectedUserFeatures));
assertTrue(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getTags().equals(eventTagMap));
assertEquals(conversion.getAnonymizeIp(), validProjectConfig.getAnonymizeIP());
assertTrue(conversion.getEnrichDecisions());
assertEquals(conversion.getClientName(), EventBatch.ClientEngine.JAVA_SDK.getClientEngineValue());
assertEquals(conversion.getClientVersion(), BuildVersionInfo.VERSION);
}
use of com.optimizely.ab.event.LogEvent in project java-sdk by optimizely.
the class EventFactoryTest method createConversionEventForcedVariationBucketingPrecedesAudienceEval.
/**
* Verify that conversion event is always created.
*/
@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";
}
LogEvent conversionEvent = createConversionEvent(validProjectConfig, whitelistedUserId, eventType.getId(), eventType.getKey(), Collections.emptyMap(), Collections.emptyMap());
assertNotNull(conversionEvent);
}
Aggregations