Search in sources :

Example 6 with EventBatch

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

Example 7 with EventBatch

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());
    }
}
Also used : EventType(com.optimizely.ab.config.EventType) LogEvent(com.optimizely.ab.event.LogEvent) Experiment(com.optimizely.ab.config.Experiment) NoOpErrorHandler(com.optimizely.ab.error.NoOpErrorHandler) UserProfileService(com.optimizely.ab.bucketing.UserProfileService) Variation(com.optimizely.ab.config.Variation) EventBatch(com.optimizely.ab.event.internal.payload.EventBatch) Bucketer(com.optimizely.ab.bucketing.Bucketer) DecisionService(com.optimizely.ab.bucketing.DecisionService) Test(org.junit.Test)

Example 8 with EventBatch

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

Example 9 with EventBatch

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

Example 10 with EventBatch

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

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