use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class JacksonSerializerTest method serializeConversion.
@Test
public void serializeConversion() throws IOException {
EventBatch conversion = generateConversion();
// can't compare JSON strings since orders could vary so compare objects instead
EventBatch actual = mapper.readValue(serializer.serialize(conversion), EventBatch.class);
EventBatch expected = mapper.readValue(generateConversionJson(), EventBatch.class);
assertThat(actual, is(expected));
}
use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class SerializerTestUtils method generateConversion.
static EventBatch generateConversion() {
EventBatch conversion = generateImpression();
conversion.setClientVersion("0.1.1");
conversion.setAnonymizeIp(true);
conversion.setRevision(revision);
return conversion;
}
use of com.optimizely.ab.event.internal.payload.EventBatch in project java-sdk by optimizely.
the class EventBuilder method createConversionEvent.
public LogEvent createConversionEvent(@Nonnull ProjectConfig projectConfig, @Nonnull Map<Experiment, Variation> experimentVariationMap, @Nonnull String userId, @Nonnull String eventId, @Nonnull String eventName, @Nonnull Map<String, String> attributes, @Nonnull Map<String, ?> eventTags) {
if (experimentVariationMap.isEmpty()) {
return null;
}
ArrayList<Decision> decisions = new ArrayList<Decision>();
for (Map.Entry<Experiment, Variation> entry : experimentVariationMap.entrySet()) {
Decision decision = new Decision(entry.getKey().getLayerId(), entry.getKey().getId(), entry.getValue().getId(), false);
decisions.add(decision);
}
EventType eventType = projectConfig.getEventNameMapping().get(eventName);
Event conversionEvent = new Event(System.currentTimeMillis(), UUID.randomUUID().toString(), eventType.getId(), eventType.getKey(), null, EventTagUtils.getRevenueValue(eventTags), eventTags, eventType.getKey(), EventTagUtils.getNumericValue(eventTags));
Snapshot snapshot = new Snapshot(decisions, Arrays.asList(conversionEvent));
Visitor visitor = new Visitor(userId, null, buildAttributeList(projectConfig, attributes), Arrays.asList(snapshot));
List<Visitor> visitors = Arrays.asList(visitor);
EventBatch eventBatch = new EventBatch(clientEngine.getClientEngineValue(), clientVersion, projectConfig.getAccountId(), visitors, projectConfig.getAnonymizeIP(), projectConfig.getProjectId(), projectConfig.getRevision());
String payload = this.serializer.serialize(eventBatch);
return new LogEvent(LogEvent.RequestMethod.POST, EVENT_ENDPOINT, Collections.<String, String>emptyMap(), payload);
}
Aggregations