Skip to content

Commit

Permalink
Add Notification timestamp to allow frontend display and easier handl…
Browse files Browse the repository at this point in the history
…ing (can be used as key when using React as frontend)
  • Loading branch information
agrancaric committed Jun 27, 2022
1 parent 7dc91bb commit 0d3d930
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;

import java.time.Instant;
import java.util.List;
import java.util.Map;

Expand Down Expand Up @@ -57,4 +58,8 @@ public class Notification {
*/
private final Map<String, ?> uxNotificationOptions;

/**
* Timestamp of the notification.
*/
private final Instant timestamp = Instant.now();
}
2 changes: 2 additions & 0 deletions nrich-webmvc-spring-boot-starter/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ dependencies {
runtimeOnly project(":nrich-logging-spring-boot-starter")
runtimeOnly project(":nrich-notification-spring-boot-starter")

runtimeOnly "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"

implementation "org.springframework.boot:spring-boot-autoconfigure"

testImplementation project(":nrich-logging-spring-boot-starter")
Expand Down
2 changes: 2 additions & 0 deletions nrich-webmvc/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ dependencies {
implementation "jakarta.validation:jakarta.validation-api"
implementation "org.springframework:spring-webmvc"

runtimeOnly "com.fasterxml.jackson.datatype:jackson-datatype-jsr310"

testAnnotationProcessor "org.projectlombok:lombok"
testCompileOnly "org.projectlombok:lombok"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class NotificationErrorHandlingRestControllerAdviceTest extends BaseControllerTe

private static final String NOTIFICATION_VALIDATION_ERROR_LIST_PATH = "$.notification.validationErrorList[0]";

private static final String NOTIFICATION_TIMESTAMP_PATH = "$.notification.timestamp";

@Test
void shouldResolveExceptionNotification() throws Exception {
// given
Expand All @@ -49,7 +51,8 @@ void shouldResolveExceptionNotification() throws Exception {
result.andExpect(status().isBadGateway())
.andExpect(jsonPath(NOTIFICATION_TITLE_PATH).value("Error"))
.andExpect(jsonPath(NOTIFICATION_CONTENT_PATH).value("Error message"))
.andExpect(jsonPath(NOTIFICATION_MESSAGE_LIST_PATH).value(startsWith("UUID")));
.andExpect(jsonPath(NOTIFICATION_MESSAGE_LIST_PATH).value(startsWith("UUID")))
.andExpect(jsonPath(NOTIFICATION_TIMESTAMP_PATH).isNotEmpty());
}

@Test
Expand Down

0 comments on commit 0d3d930

Please sign in to comment.