use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.
the class JacksonConfigParserTest method parseProjectConfigV3.
@Test
public void parseProjectConfigV3() throws Exception {
JacksonConfigParser parser = new JacksonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV3());
ProjectConfig expected = validProjectConfigV3();
verifyProjectConfig(actual, expected);
}
use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.
the class JacksonConfigParserTest method parseProjectConfigV2.
@Test
public void parseProjectConfigV2() throws Exception {
JacksonConfigParser parser = new JacksonConfigParser();
ProjectConfig actual = parser.parseProjectConfig(validConfigJsonV2());
ProjectConfig expected = validProjectConfigV2();
verifyProjectConfig(actual, expected);
}
use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.
the class OptimizelyTest method trackEventEndToEnd.
/**
* Verify that the {@link Optimizely#track(String, String)} call correctly builds a V2 event and passes it
* through {@link EventHandler#dispatchEvent(LogEvent)}.
*/
@Test
public void trackEventEndToEnd() throws Exception {
EventType eventType;
String datafile;
ProjectConfig config;
if (datafileVersion >= 4) {
config = spy(validProjectConfig);
eventType = validProjectConfig.getEventNameMapping().get(EVENT_BASIC_EVENT_KEY);
datafile = validDatafile;
} else {
config = spy(noAudienceProjectConfig);
eventType = noAudienceProjectConfig.getEventTypes().get(0);
datafile = noAudienceDatafile;
}
List<Experiment> allExperiments = config.getExperiments();
EventBuilder eventBuilder = new EventBuilder();
DecisionService spyDecisionService = spy(new DecisionService(mockBucketer, mockErrorHandler, config, null));
Optimizely optimizely = Optimizely.builder(datafile, mockEventHandler).withDecisionService(spyDecisionService).withEventBuilder(eventBuilder).withConfig(noAudienceProjectConfig).withErrorHandler(mockErrorHandler).build();
// call the bucket function.
for (Experiment experiment : allExperiments) {
when(mockBucketer.bucket(experiment, testUserId)).thenReturn(experiment.getVariations().get(0));
}
// call track
optimizely.track(eventType.getKey(), testUserId);
// verify that the bucketing algorithm was called only on experiments corresponding to the specified goal.
List<Experiment> experimentsForEvent = config.getExperimentsForEventKey(eventType.getKey());
for (Experiment experiment : allExperiments) {
if (experiment.isRunning() && experimentsForEvent.contains(experiment)) {
verify(spyDecisionService).getVariation(experiment, testUserId, Collections.<String, String>emptyMap());
verify(config).getForcedVariation(experiment.getKey(), testUserId);
} else {
verify(spyDecisionService, never()).getVariation(experiment, testUserId, Collections.<String, String>emptyMap());
}
}
// verify that dispatchEvent was called
verify(mockEventHandler).dispatchEvent(any(LogEvent.class));
}
use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.
the class EventBuilderTest method createImpressionEventAndroidClientEngineClientVersion.
/**
* Verify that supplying {@link EventBuilder} with a custom client engine and client version results in impression
* events being sent with the overriden values.
*/
@Test
public void createImpressionEventAndroidClientEngineClientVersion() throws Exception {
EventBuilder builder = new EventBuilder(EventBatch.ClientEngine.ANDROID_SDK, "0.0.0");
ProjectConfig projectConfig = validProjectConfigV2();
Experiment activatedExperiment = projectConfig.getExperiments().get(0);
Variation bucketedVariation = activatedExperiment.getVariations().get(0);
Attribute attribute = projectConfig.getAttributes().get(0);
String userId = "userId";
Map<String, String> attributeMap = Collections.singletonMap(attribute.getKey(), "value");
LogEvent impressionEvent = builder.createImpressionEvent(projectConfig, activatedExperiment, bucketedVariation, userId, attributeMap);
EventBatch impression = gson.fromJson(impressionEvent.getBody(), EventBatch.class);
assertThat(impression.getClientName(), is(EventBatch.ClientEngine.ANDROID_SDK.getClientEngineValue()));
assertThat(impression.getClientVersion(), is("0.0.0"));
}
use of com.optimizely.ab.config.ProjectConfig in project java-sdk by optimizely.
the class EventBuilderTest method createConversionEventAndroidTVClientEngineClientVersion.
/**
* Verify that supplying {@link EventBuilder} 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";
EventBuilder builder = new EventBuilder(EventBatch.ClientEngine.ANDROID_TV_SDK, clientVersion);
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)).thenReturn(experiment.getVariations().get(0));
}
Map<String, String> attributeMap = Collections.singletonMap(attribute.getKey(), "value");
List<Experiment> experimentList = projectConfig.getExperimentsForEventKey(eventType.getKey());
Map<Experiment, Variation> experimentVariationMap = new HashMap<Experiment, Variation>(experimentList.size());
for (Experiment experiment : experimentList) {
experimentVariationMap.put(experiment, experiment.getVariations().get(0));
}
LogEvent conversionEvent = builder.createConversionEvent(projectConfig, experimentVariationMap, userId, eventType.getId(), eventType.getKey(), attributeMap, Collections.<String, Object>emptyMap());
EventBatch conversion = gson.fromJson(conversionEvent.getBody(), EventBatch.class);
assertThat(conversion.getClientName(), is(EventBatch.ClientEngine.ANDROID_TV_SDK.getClientEngineValue()));
assertThat(conversion.getClientVersion(), is(clientVersion));
}
Aggregations