Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix JacksonEvent to propagate ExternalOriginalTime if its set at the time of construction #4489

Merged
merged 3 commits into from
May 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ protected JacksonEvent(final Builder builder) {

this.jsonNode = getInitialJsonNode(builder.data);
this.eventHandle = new DefaultEventHandle(eventMetadata.getTimeReceived());
final Instant externalOriginationTime = this.eventMetadata.getExternalOriginationTime();
if (externalOriginationTime != null) {
eventHandle.setExternalOriginationTime(externalOriginationTime);
}
}

protected JacksonEvent(final JacksonEvent otherEvent) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -485,13 +485,15 @@ public void testBuild_withAttributes() {
public void testBuild_withAllMetadataFields() {

final Instant now = Instant.now().minusSeconds(1);
final Instant extTime = Instant.now().minusSeconds(10);
final Map<String, Object> testAttributes = new HashMap<>();
testAttributes.put(UUID.randomUUID().toString(), UUID.randomUUID());
testAttributes.put(UUID.randomUUID().toString(), UUID.randomUUID().toString());
final String emEventType = UUID.randomUUID().toString();

final EventMetadata metadata = DefaultEventMetadata.builder()
.withEventType(emEventType)
.withExternalOriginationTime(extTime)
.build();

event = JacksonEvent.builder()
Expand All @@ -504,6 +506,8 @@ public void testBuild_withAllMetadataFields() {
assertThat(event.getMetadata().getAttributes(), is(not(equalTo(testAttributes))));
assertThat(event.getMetadata().getTimeReceived(), is(not(equalTo(now))));
assertThat(event.getMetadata().getEventType(), is(equalTo(emEventType)));
assertThat(event.getMetadata().getExternalOriginationTime(), is(equalTo(extTime)));
assertThat(event.getEventHandle().getExternalOriginationTime(), is(equalTo(extTime)));
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public void extendedTest() throws Exception {
assertThat(e.getMetadata().getTags(), equalTo(tags));
assertThat(e.getMetadata().getAttributes(), equalTo(Map.of(attrKey, attrValue)));
assertThat(e.getMetadata().getExternalOriginationTime(), equalTo(origTime));
assertThat(e.getEventHandle().getExternalOriginationTime(), equalTo(origTime));
}
}

Expand Down
Loading