Skip to content

Commit 30bf387

Browse files
committed
Updating as per API changes. Need to fix some tests still.
1 parent 6e6555b commit 30bf387

File tree

9 files changed

+34
-37
lines changed

9 files changed

+34
-37
lines changed

core-api/src/main/java/com/optimizely/ab/event/internal/EventFactory.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,6 @@ public LogEvent createConversionEvent(@Nonnull ProjectConfig projectConfig,
110110
@Nonnull Map<String, ?> attributes,
111111
@Nonnull Map<String, ?> eventTags) {
112112

113-
ArrayList<Decision> decisions = new ArrayList<Decision>();
114-
115113
EventType eventType = projectConfig.getEventNameMapping().get(eventName);
116114

117115
Event conversionEvent = new Event.Builder()
@@ -126,9 +124,8 @@ public LogEvent createConversionEvent(@Nonnull ProjectConfig projectConfig,
126124
.build();
127125

128126
Snapshot snapshot = new Snapshot.Builder()
129-
.setDecisions(decisions)
130-
.setEvents(Collections.singletonList((conversionEvent)))
131-
.build();
127+
.setEvents(Collections.singletonList((conversionEvent)))
128+
.build();
132129

133130
Visitor visitor = new Visitor.Builder()
134131
.setVisitorId(userId)

core-api/src/main/java/com/optimizely/ab/event/internal/payload/EventBatch.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ public String getClientEngineValue() {
4444
@JsonProperty("account_id")
4545
String accountId;
4646
List<Visitor> visitors;
47+
@JsonProperty("enrich_decisions")
48+
Boolean enrichDecisions;
4749
@JsonProperty("anonymize_ip")
4850
Boolean anonymizeIp;
4951
@JsonProperty("client_name")
@@ -61,6 +63,7 @@ public EventBatch() {
6163
private EventBatch(String clientName, String clientVersion, String accountId, List<Visitor> visitors, Boolean anonymizeIp, String projectId, String revision) {
6264
this.accountId = accountId;
6365
this.visitors = visitors;
66+
this.enrichDecisions = true;
6467
this.anonymizeIp = anonymizeIp;
6568
this.clientName = clientName;
6669
this.clientVersion = clientVersion;
@@ -84,6 +87,12 @@ public void setVisitors(List<Visitor> visitors) {
8487
this.visitors = visitors;
8588
}
8689

90+
public Boolean getEnrichDecisions() { return enrichDecisions; }
91+
92+
public void setEnrichDecisions(Boolean enrichDecisions) {
93+
this.enrichDecisions = enrichDecisions;
94+
}
95+
8796
public Boolean getAnonymizeIp() {
8897
return anonymizeIp;
8998
}

core-api/src/main/java/com/optimizely/ab/event/internal/serializer/JsonSimpleSerializer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ private JSONObject serializeEventBatch(EventBatch eventBatch) {
4242
JSONObject jsonObject = new JSONObject();
4343

4444
jsonObject.put("account_id", eventBatch.getAccountId());
45+
jsonObject.put("enrich_decisions", eventBatch.getEnrichDecisions());
4546
jsonObject.put("visitors", serializeVisitors(eventBatch.getVisitors()));
4647
if (eventBatch.getAnonymizeIp() != null) jsonObject.put("anonymize_ip", eventBatch.getAnonymizeIp());
4748
if (eventBatch.getClientName() != null) jsonObject.put("client_name", eventBatch.getClientName());
@@ -50,7 +51,6 @@ private JSONObject serializeEventBatch(EventBatch eventBatch) {
5051
if (eventBatch.getRevision() != null) jsonObject.put("revision", eventBatch.getRevision());
5152

5253
return jsonObject;
53-
5454
}
5555

5656
private JSONArray serializeVisitors(List<Visitor> visitors) {
@@ -90,7 +90,7 @@ private JSONArray serializeSnapshots(List<Snapshot> snapshots) {
9090
private JSONObject serializeSnapshot(Snapshot snapshot) {
9191
JSONObject jsonObject = new JSONObject();
9292

93-
jsonObject.put("decisions", serializeDecisions(snapshot.getDecisions()));
93+
if (snapshot.getDecisions() != null) jsonObject.put("decisions", serializeDecisions(snapshot.getDecisions()));
9494
jsonObject.put("events", serializeEvents(snapshot.getEvents()));
9595

9696
return jsonObject;

core-api/src/test/java/com/optimizely/ab/event/internal/EventFactoryTest.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -500,8 +500,6 @@ public void createConversionEvent() throws Exception {
500500
attributeMap,
501501
eventTagMap);
502502

503-
List<Decision> expectedDecisions = new ArrayList<Decision>();
504-
505503
// verify that the request endpoint is correct
506504
assertThat(conversionEvent.getEndpointUrl(), is(EventFactory.EVENT_ENDPOINT));
507505

@@ -528,7 +526,6 @@ public void createConversionEvent() throws Exception {
528526
}
529527

530528
assertEquals(conversion.getVisitors().get(0).getAttributes(), expectedUserFeatures);
531-
assertThat(conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions(), containsInAnyOrder(expectedDecisions.toArray()));
532529
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getEntityId(), eventType.getId());
533530
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getKey(), eventType.getKey());
534531
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getRevenue(), null);
@@ -564,8 +561,6 @@ public void createConversionEventPassingUserAgentAttribute() throws Exception {
564561
attributeMap,
565562
eventTagMap);
566563

567-
List<Decision> expectedDecisions = new ArrayList<Decision>();
568-
569564
// verify that the request endpoint is correct
570565
assertThat(conversionEvent.getEndpointUrl(), is(EventFactory.EVENT_ENDPOINT));
571566

@@ -598,7 +593,6 @@ public void createConversionEventPassingUserAgentAttribute() throws Exception {
598593
}
599594

600595
assertEquals(conversion.getVisitors().get(0).getAttributes(), expectedUserFeatures);
601-
assertThat(conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions(), containsInAnyOrder(expectedDecisions.toArray()));
602596
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getEntityId(), eventType.getId());
603597
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getKey(), eventType.getKey());
604598
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getRevenue(), null);
@@ -877,8 +871,6 @@ public void createConversionEventWithBucketingId() throws Exception {
877871
attributeMap,
878872
eventTagMap);
879873

880-
List<Decision> expectedDecisions = new ArrayList<Decision>();
881-
882874
// verify that the request endpoint is correct
883875
assertThat(conversionEvent.getEndpointUrl(), is(EventFactory.EVENT_ENDPOINT));
884876

@@ -912,7 +904,6 @@ public void createConversionEventWithBucketingId() throws Exception {
912904
}
913905

914906
assertEquals(conversion.getVisitors().get(0).getAttributes(), expectedUserFeatures);
915-
assertThat(conversion.getVisitors().get(0).getSnapshots().get(0).getDecisions(), containsInAnyOrder(expectedDecisions.toArray()));
916907
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getEntityId(), eventType.getId());
917908
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getType(), eventType.getKey());
918909
assertEquals(conversion.getVisitors().get(0).getSnapshots().get(0).getEvents().get(0).getKey(), eventType.getKey());

core-api/src/test/java/com/optimizely/ab/event/internal/serializer/SerializerTestUtils.java

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,24 @@ static EventBatch generateImpressionWithSessionId() {
102102
}
103103

104104
static EventBatch generateConversion() {
105-
EventBatch conversion = generateImpression();
106-
conversion.setClientVersion("0.1.1");
107-
conversion.setAnonymizeIp(true);
108-
conversion.setRevision(revision);
105+
Snapshot snapshot = new Snapshot.Builder()
106+
.setEvents(events)
107+
.build();
109108

110-
return conversion;
109+
Visitor visitor = new Visitor.Builder()
110+
.setVisitorId(visitorId)
111+
.setAttributes(userFeatures)
112+
.setSnapshots(Collections.singletonList(snapshot))
113+
.build();
114+
115+
return new EventBatch.Builder()
116+
.setClientVersion("0.1.1")
117+
.setAccountId(accountId)
118+
.setVisitors(Collections.singletonList(visitor))
119+
.setAnonymizeIp(true)
120+
.setProjectId(projectId)
121+
.setRevision(revision)
122+
.build();
111123
}
112124

113125
static EventBatch generateConversionWithSessionId() {

core-api/src/test/resources/serializer/conversion-session-id.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
{
55
"snapshots": [
66
{
7-
"decisions": [
8-
{
9-
"variation_id": "4",
10-
"campaign_id": "2",
11-
"experiment_id": "5",
12-
"is_campaign_holdback": false
13-
}
14-
],
157
"events": [
168
{
179
"revenue": 5000,
@@ -39,6 +31,7 @@
3931
"client_name": "java-sdk",
4032
"client_version": "0.1.1",
4133
"anonymize_ip": true,
34+
"enrich_decisions": true,
4235
"project_id": "1",
4336
"revision": "1"
4437
}

core-api/src/test/resources/serializer/conversion.json

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
{
55
"snapshots": [
66
{
7-
"decisions": [
8-
{
9-
"variation_id": "4",
10-
"campaign_id": "2",
11-
"experiment_id": "5",
12-
"is_campaign_holdback": false
13-
}
14-
],
157
"events": [
168
{
179
"revenue": 5000,
@@ -38,6 +30,7 @@
3830
"client_name": "java-sdk",
3931
"client_version": "0.1.1",
4032
"anonymize_ip": true,
33+
"enrich_decisions": true,
4134
"project_id": "1",
4235
"revision": "1"
4336
}

core-api/src/test/resources/serializer/impression-session-id.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"client_name": "java-sdk",
4040
"client_version": "0.1.1",
4141
"anonymize_ip": true,
42+
"enrich_decisions": true,
4243
"project_id": "1",
4344
"revision": "1"
4445
}

core-api/src/test/resources/serializer/impression.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"client_name": "java-sdk",
3939
"client_version": "0.1.1",
4040
"anonymize_ip": true,
41+
"enrich_decisions": true,
4142
"project_id": "1",
4243
"revision": "1"
4344
}

0 commit comments

Comments
 (0)