Skip to content

Commit

Permalink
Fix JacksonEvent to propagate ExternalOriginalTime if its set at the …
Browse files Browse the repository at this point in the history
…time of construction (#4489)

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

Signed-off-by: Krishna Kondaka <[email protected]>

* Added test

Signed-off-by: Krishna Kondaka <[email protected]>

* Fixed code coverage failure by adding more tests

Signed-off-by: Krishna Kondaka <[email protected]>

---------

Signed-off-by: Krishna Kondaka <[email protected]>
Co-authored-by: Krishna Kondaka <[email protected]>
  • Loading branch information
kkondaka and Krishna Kondaka authored May 2, 2024
1 parent 2345cb6 commit d6a8ae0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 0 deletions.
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

0 comments on commit d6a8ae0

Please sign in to comment.