Search in sources :

Example 31 with EventBatch

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));
}
Also used : EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Test(org.junit.Test)

Example 32 with EventBatch

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;
}
Also used : EventBatch(com.optimizely.ab.event.internal.payload.EventBatch)

Example 33 with EventBatch

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);
}
Also used : Visitor(com.optimizely.ab.event.internal.payload.Visitor) EventType(com.optimizely.ab.config.EventType) LogEvent(com.optimizely.ab.event.LogEvent) Experiment(com.optimizely.ab.config.Experiment) ArrayList(java.util.ArrayList) Decision(com.optimizely.ab.event.internal.payload.Decision) Snapshot(com.optimizely.ab.event.internal.payload.Snapshot) Event(com.optimizely.ab.event.internal.payload.Event) LogEvent(com.optimizely.ab.event.LogEvent) Variation(com.optimizely.ab.config.Variation) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Map(java.util.Map)

Aggregations

EventBatch (com.optimizely.ab.event.internal.payload.EventBatch)33 Test (org.junit.Test)27 LogEvent (com.optimizely.ab.event.LogEvent)13 Experiment (com.optimizely.ab.config.Experiment)12 Variation (com.optimizely.ab.config.Variation)12 Attribute (com.optimizely.ab.config.Attribute)9 EventType (com.optimizely.ab.config.EventType)7 Bucketer (com.optimizely.ab.bucketing.Bucketer)6 ProjectConfig (com.optimizely.ab.config.ProjectConfig)6 Decision (com.optimizely.ab.event.internal.payload.Decision)6 DecisionService (com.optimizely.ab.bucketing.DecisionService)5 UserProfileService (com.optimizely.ab.bucketing.UserProfileService)5 NoOpErrorHandler (com.optimizely.ab.error.NoOpErrorHandler)5 HashMap (java.util.HashMap)5 ErrorHandler (com.optimizely.ab.error.ErrorHandler)4 JSONObject (org.json.JSONObject)4 JSONObject (org.json.simple.JSONObject)4 Snapshot (com.optimizely.ab.event.internal.payload.Snapshot)3 Visitor (com.optimizely.ab.event.internal.payload.Visitor)3 ArrayList (java.util.ArrayList)3