Skip to content

Commit 27e898b

Browse files
Update tests to check for context instead of contextKeys
Co-Authored-By: jbailey@launchdarkly.com <accounts@sidewaysgravity.com>
1 parent 578186c commit 27e898b

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ public static Matcher<JsonTestValue> isMigrationEvent(Event sourceEvent, LDValue
208208
return allOf(
209209
jsonProperty("kind", "migration_op"),
210210
jsonProperty("creationDate", (double)sourceEvent.getCreationDate()),
211-
hasContextKeys(sourceEvent)
211+
hasContext(sourceEvent)
212212
);
213213
}
214214

@@ -254,20 +254,28 @@ public static Matcher<JsonTestValue> isCustomEvent(Event.Custom sourceEvent) {
254254
jsonProperty("kind", "custom"),
255255
jsonProperty("creationDate", (double)sourceEvent.getCreationDate()),
256256
jsonProperty("key", sourceEvent.getKey()),
257-
hasContextKeys(sourceEvent),
257+
hasContext(sourceEvent),
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) {
263+
public static Matcher<JsonTestValue> hasContext(Event sourceEvent) {
264264
ObjectBuilder b = LDValue.buildObject();
265265
LDContext c = sourceEvent.getContext();
266266
for (int i = 0; i < c.getIndividualContextCount(); i++) {
267267
LDContext c1 = c.getIndividualContext(i);
268-
b.put(c1.getKind().toString(), c1.getKey());
268+
b.put("kind", c1.getKind().toString());
269+
b.put("key", c1.getKey());
270+
if (c1.getName() != null) {
271+
b.put("name", c1.getName());
272+
}
269273
}
270-
return jsonProperty("contextKeys", jsonEqualsValue(b.build()));
274+
return jsonProperty("context", jsonEqualsValue(b.build()));
275+
}
276+
277+
public static Matcher<JsonTestValue> hasContextKeys(Event sourceEvent) {
278+
return hasContext(sourceEvent);
271279
}
272280

273281
public static Matcher<JsonTestValue> hasInlineContext(LDValue inlineContext) {

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

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -46,22 +46,26 @@ public void allAttributesAreSerialized() throws Exception {
4646
}
4747

4848
@Test
49-
public void contextKeysAreSetInsteadOfContextWhenNotInlined() throws Exception {
50-
testContextKeysSerialization(
49+
public void contextIsAlwaysInlined() throws Exception {
50+
testContextSerialization(
5151
LDContext.create("userkey"),
52-
LDValue.buildObject().put("user", "userkey").build()
52+
LDValue.buildObject().put("kind", "user").put("key", "userkey").build()
5353
);
5454

55-
testContextKeysSerialization(
55+
testContextSerialization(
5656
LDContext.create(ContextKind.of("kind1"), "key1"),
57-
LDValue.buildObject().put("kind1", "key1").build()
57+
LDValue.buildObject().put("kind", "kind1").put("key", "key1").build()
5858
);
5959

60-
testContextKeysSerialization(
60+
testContextSerialization(
6161
LDContext.createMulti(
6262
LDContext.create(ContextKind.of("kind1"), "key1"),
6363
LDContext.create(ContextKind.of("kind2"), "key2")),
64-
LDValue.buildObject().put("kind1", "key1").put("kind2", "key2").build()
64+
LDValue.buildObject()
65+
.put("kind", "multi")
66+
.put("kind1", LDValue.buildObject().put("key", "key1").build())
67+
.put("kind2", LDValue.buildObject().put("key", "key2").build())
68+
.build()
6569
);
6670
}
6771

@@ -709,14 +713,14 @@ private LDValue getSingleOutputEvent(EventOutputFormatter f, Event event) throws
709713
return parseValue(w.toString()).get(0);
710714
}
711715

712-
private void testContextKeysSerialization(LDContext context, LDValue expectedJsonValue) throws IOException {
716+
private void testContextSerialization(LDContext context, LDValue expectedJsonValue) throws IOException {
713717
EventsConfiguration config = makeEventsConfig(false, null);
714718
EventOutputFormatter f = new EventOutputFormatter(config);
715719

716720
Event.Custom customEvent = customEvent(context, "eventkey").build();
717721
LDValue outputEvent = getSingleOutputEvent(f, customEvent);
718-
assertJsonEquals(expectedJsonValue, outputEvent.get("contextKeys"));
719-
assertJsonEquals(LDValue.ofNull(), outputEvent.get("context"));
722+
assertJsonEquals(expectedJsonValue, outputEvent.get("context"));
723+
assertJsonEquals(LDValue.ofNull(), outputEvent.get("contextKeys"));
720724
}
721725

722726
private void testInlineContextSerialization(LDContext context, LDValue expectedJsonValue, EventsConfiguration baseConfig) throws IOException {

0 commit comments

Comments
 (0)