Skip to content

Commit 04eb96b

Browse files
committed
address failing unit tests
1 parent 578186c commit 04eb96b

File tree

4 files changed

+18
-54
lines changed

4 files changed

+18
-54
lines changed

lib/shared/internal/src/test/java/com/launchdarkly/sdk/internal/events/BaseEventTest.java

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -203,12 +203,12 @@ public static Matcher<JsonTestValue> isIdentifyEvent(Event sourceEvent, LDValue
203203
);
204204
}
205205

206-
public static Matcher<JsonTestValue> isMigrationEvent(Event sourceEvent, LDValue context) {
206+
public static Matcher<JsonTestValue> isMigrationEvent(Event sourceEvent, LDValue inlineContext) {
207207
// Doesn't fully test an event, but makes sure it is a specific event.
208208
return allOf(
209209
jsonProperty("kind", "migration_op"),
210210
jsonProperty("creationDate", (double)sourceEvent.getCreationDate()),
211-
hasContextKeys(sourceEvent)
211+
hasInlineContext(inlineContext)
212212
);
213213
}
214214

@@ -248,28 +248,18 @@ private static Matcher<JsonTestValue> isFeatureOrDebugEvent(Event.FeatureRequest
248248
);
249249
}
250250

251-
public static Matcher<JsonTestValue> isCustomEvent(Event.Custom sourceEvent) {
251+
public static Matcher<JsonTestValue> isCustomEvent(Event.Custom sourceEvent, LDValue inlineContext) {
252252
boolean hasData = sourceEvent.getData() != null && !sourceEvent.getData().isNull();
253253
return allOf(
254254
jsonProperty("kind", "custom"),
255255
jsonProperty("creationDate", (double)sourceEvent.getCreationDate()),
256256
jsonProperty("key", sourceEvent.getKey()),
257-
hasContextKeys(sourceEvent),
257+
hasInlineContext(inlineContext),
258258
jsonProperty("data", hasData ? jsonEqualsValue(sourceEvent.getData()) : jsonUndefined()),
259259
jsonProperty("metricValue", sourceEvent.getMetricValue() == null ? jsonUndefined() : jsonEqualsValue(sourceEvent.getMetricValue()))
260260
);
261261
}
262262

263-
public static Matcher<JsonTestValue> hasContextKeys(Event sourceEvent) {
264-
ObjectBuilder b = LDValue.buildObject();
265-
LDContext c = sourceEvent.getContext();
266-
for (int i = 0; i < c.getIndividualContextCount(); i++) {
267-
LDContext c1 = c.getIndividualContext(i);
268-
b.put(c1.getKind().toString(), c1.getKey());
269-
}
270-
return jsonProperty("contextKeys", jsonEqualsValue(b.build()));
271-
}
272-
273263
public static Matcher<JsonTestValue> hasInlineContext(LDValue inlineContext) {
274264
return allOf(
275265
jsonProperty("context", jsonEqualsValue(inlineContext)),

lib/shared/internal/src/test/java/com/launchdarkly/sdk/internal/events/DefaultEventProcessorOutputTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,7 @@ public void customEventIsQueuedWithUser() throws Exception {
399399
}
400400

401401
assertThat(es.getEventsFromLastRequest(), contains(
402-
isCustomEvent(ce)
402+
isCustomEvent(ce, userJson)
403403
));
404404
}
405405

@@ -419,7 +419,7 @@ public void customEventWithNullContextOrInvalidContextDoesNotCauseError() throws
419419
}
420420

421421
assertThat(es.getEventsFromLastRequest(), contains(
422-
isCustomEvent(event3)
422+
isCustomEvent(event3, userJson)
423423
));
424424
}
425425

lib/shared/internal/src/test/java/com/launchdarkly/sdk/internal/events/DefaultEventProcessorTest.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ public void eventsAreFlushedAutomatically() throws Exception {
4444
// sendEvent calls, they might be in two
4545
List<JsonTestValue> payload1 = es.getEventsFromLastRequest();
4646
if (payload1.size() == 1) {
47-
assertThat(payload1, contains(isCustomEvent(event1)));
48-
assertThat(es.getEventsFromLastRequest(), contains(isCustomEvent(event2)));
47+
assertThat(payload1, contains(isCustomEvent(event1, userJson)));
48+
assertThat(es.getEventsFromLastRequest(), contains(isCustomEvent(event2, userJson)));
4949
} else {
50-
assertThat(payload1, contains(isCustomEvent(event1), isCustomEvent(event2)));
50+
assertThat(payload1, contains(isCustomEvent(event1, userJson), isCustomEvent(event2, userJson)));
5151
}
5252

5353
Event.Custom event3 = customEvent(user, "event3").build();
5454
ep.sendEvent(event3);
55-
assertThat(es.getEventsFromLastRequest(), contains(isCustomEvent(event3)));
55+
assertThat(es.getEventsFromLastRequest(), contains(isCustomEvent(event3, userJson)));
5656
}
5757

5858
Event.Custom ce = customEvent(user, "eventkey").build();
@@ -62,7 +62,7 @@ public void eventsAreFlushedAutomatically() throws Exception {
6262
}
6363

6464
assertThat(es.getEventsFromLastRequest(), contains(
65-
isCustomEvent(ce)
65+
isCustomEvent(ce, userJson)
6666
));
6767
}
6868

@@ -85,7 +85,7 @@ public void eventsAreNotFlushedWhenNotConnected() throws Exception {
8585
ep.setOffline(false);
8686

8787
List<JsonTestValue> payload1 = es.getEventsFromLastRequest();
88-
assertThat(payload1, contains(isCustomEvent(event1), isCustomEvent(event2)));
88+
assertThat(payload1, contains(isCustomEvent(event1, userJson), isCustomEvent(event2, userJson)));
8989
}
9090
}
9191

lib/shared/internal/src/test/java/com/launchdarkly/sdk/internal/events/EventOutputTest.java

Lines changed: 6 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -45,26 +45,6 @@ public void allAttributesAreSerialized() throws Exception {
4545
defaultEventsConfig());
4646
}
4747

48-
@Test
49-
public void contextKeysAreSetInsteadOfContextWhenNotInlined() throws Exception {
50-
testContextKeysSerialization(
51-
LDContext.create("userkey"),
52-
LDValue.buildObject().put("user", "userkey").build()
53-
);
54-
55-
testContextKeysSerialization(
56-
LDContext.create(ContextKind.of("kind1"), "key1"),
57-
LDValue.buildObject().put("kind1", "key1").build()
58-
);
59-
60-
testContextKeysSerialization(
61-
LDContext.createMulti(
62-
LDContext.create(ContextKind.of("kind1"), "key1"),
63-
LDContext.create(ContextKind.of("kind2"), "key2")),
64-
LDValue.buildObject().put("kind1", "key1").put("kind2", "key2").build()
65-
);
66-
}
67-
6848
@Test
6949
public void allAttributesPrivateMakesAttributesPrivate() throws Exception {
7050
// We test this behavior in more detail in EventContextFormatterTest, but here we're verifying that the
@@ -709,25 +689,19 @@ private LDValue getSingleOutputEvent(EventOutputFormatter f, Event event) throws
709689
return parseValue(w.toString()).get(0);
710690
}
711691

712-
private void testContextKeysSerialization(LDContext context, LDValue expectedJsonValue) throws IOException {
713-
EventsConfiguration config = makeEventsConfig(false, null);
714-
EventOutputFormatter f = new EventOutputFormatter(config);
715-
716-
Event.Custom customEvent = customEvent(context, "eventkey").build();
717-
LDValue outputEvent = getSingleOutputEvent(f, customEvent);
718-
assertJsonEquals(expectedJsonValue, outputEvent.get("contextKeys"));
719-
assertJsonEquals(LDValue.ofNull(), outputEvent.get("context"));
720-
}
721-
722692
private void testInlineContextSerialization(LDContext context, LDValue expectedJsonValue, EventsConfiguration baseConfig) throws IOException {
723693
EventsConfiguration config = makeEventsConfig(baseConfig.allAttributesPrivate, baseConfig.privateAttributes);
724694
EventOutputFormatter f = new EventOutputFormatter(config);
725695

726-
Event.FeatureRequest featureEvent = featureEvent(context, FLAG_KEY).build();
727-
LDValue outputEvent = getSingleOutputEvent(f, featureEvent);
696+
Event.Custom customEvent = customEvent(context, FLAG_KEY).build();
697+
LDValue outputEvent = getSingleOutputEvent(f, customEvent);
728698
assertJsonEquals(LDValue.ofNull(), outputEvent.get("contextKeys"));
729699
assertJsonEquals(expectedJsonValue, outputEvent.get("context"));
730700

701+
Event.FeatureRequest featureEvent = featureEvent(context, FLAG_KEY).build();
702+
outputEvent = getSingleOutputEvent(f, featureEvent);
703+
assertJsonEquals(LDValue.ofNull(), outputEvent.get("contextKeys"));
704+
assertJsonEquals(expectedJsonValue, outputEvent.get("context"));
731705

732706
Event.Identify identifyEvent = identifyEvent(context);
733707
outputEvent = getSingleOutputEvent(f, identifyEvent);

0 commit comments

Comments
 (0)