use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class GsonSerializerTest method serializeImpressionWithSessionId.
@Test
public void serializeImpressionWithSessionId() throws IOException {
EventBatch impression = generateImpressionWithSessionId();
// can't compare JSON strings since orders could vary so compare objects instead
EventBatch actual = gson.fromJson(serializer.serialize(impression), EventBatch.class);
EventBatch expected = gson.fromJson(generateImpressionWithSessionIdJson(), EventBatch.class);
assertThat(actual, is(expected));
}
use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class EventBuilderTest method createConversionEventForcedVariationBucketingPrecedesAudienceEval.
/**
* Verify that precedence is given to forced variation bucketing over audience evaluation when constructing a
* conversion event.
*/
@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";
}
DecisionService decisionService = new DecisionService(new Bucketer(validProjectConfig), new NoOpErrorHandler(), validProjectConfig, mock(UserProfileService.class));
// attributes are empty so user won't be in the audience for experiment using the event, but bucketing
// will still take place
Map<Experiment, Variation> experimentVariationMap = createExperimentVariationMap(validProjectConfig, decisionService, eventType.getKey(), whitelistedUserId, Collections.<String, String>emptyMap());
LogEvent conversionEvent = builder.createConversionEvent(validProjectConfig, experimentVariationMap, whitelistedUserId, eventType.getId(), eventType.getKey(), Collections.<String, String>emptyMap(), Collections.<String, Object>emptyMap());
assertNotNull(conversionEvent);
EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
if (datafileVersion == 4) {
// 2 experiments use the event
// basic experiment has no audience
// user is whitelisted in to one audience
assertEquals(2, conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions().size());
} else {
assertEquals(1, conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions().size());
}
}
use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class SerializerTestUtils method generateImpressionWithSessionId.
static EventBatch generateImpressionWithSessionId() {
EventBatch impression = generateImpression();
impression.getVisitors().get(0).setSessionId(sessionId);
return impression;
}
use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class SerializerTestUtils method generateConversionWithSessionId.
static EventBatch generateConversionWithSessionId() {
EventBatch conversion = generateConversion();
conversion.getVisitors().get(0).setSessionId(sessionId);
return conversion;
}
use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class SerializerTestUtils method generateImpression.
static EventBatch generateImpression() {
Snapshot snapshot = new Snapshot(Arrays.asList(decision), events);
Visitor vistor = new Visitor(visitorId, null, userFeatures, Arrays.asList(snapshot));
EventBatch impression = new EventBatch(accountId, Arrays.asList(vistor), false, projectId, revision);
impression.setProjectId(projectId);
impression.setAccountId(accountId);
impression.setClientVersion("0.1.1");
impression.setAnonymizeIp(true);
impression.setRevision(revision);
return impression;
}
Aggregations