Skip to content
This repository has been archived by the owner on Jun 25, 2024. It is now read-only.

Commit

Permalink
Merge pull request #68 from patientsknowbest/feature/phr-8877-add-cor…
Browse files Browse the repository at this point in the history
…relationid-method

Add method to create a UUID if no correlationId is present [PHR-8877]
  • Loading branch information
r-oylo authored Sep 29, 2021
2 parents 634a556 + 75d0575 commit 3266596
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public Optional<UUID> maybeGet() {
return Optional.ofNullable(StringUtils.trimToNull(MDC.get(CORRELATION_ID))).map(UUID::fromString);
}

public UUID getOrDefault() {
return maybeGet().orElse(getAlternativeUUID());
}

public void putIfAbsent(UUID value) {
if (get() == null) {
put(value);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ void testCorrelationIdAsUUIDIsPutAndRead() {
assertThat(expected, sameBeanAs(actual));
}

@Test
void testCorrelationIdIsCreatedIfAbsent() {
// GIVEN
UUID actual = randomUUID();
when(underTest.getAlternativeUUID()).thenReturn(actual);

// WHEN
UUID expected = underTest.getOrDefault();

// THEN
assertThat(expected, sameBeanAs(actual));
}

@Test
void testCorrelationIdAsUUIDIsPutOnlyIfAbsentAndRead() {
// GIVEN
Expand Down

0 comments on commit 3266596

Please sign in to comment.