From 3540738724fe319f189b8da51b36f95b189ca7b6 Mon Sep 17 00:00:00 2001 From: Ramin Esfandiari Date: Wed, 7 Aug 2024 10:35:46 +0200 Subject: [PATCH] Fjerner streng pattern fra zdt felter i CacheRequestDTO --- .../no/nav/cache/cache/CacheRequestDTO.kt | 12 +++--- .../no/nav/cache/cache/IntegrationTest.kt | 41 ++++++++++++++++++- 2 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/main/kotlin/no/nav/cache/cache/CacheRequestDTO.kt b/src/main/kotlin/no/nav/cache/cache/CacheRequestDTO.kt index 844951e..710e703 100644 --- a/src/main/kotlin/no/nav/cache/cache/CacheRequestDTO.kt +++ b/src/main/kotlin/no/nav/cache/cache/CacheRequestDTO.kt @@ -7,15 +7,15 @@ data class CacheRequestDTO( val nøkkelPrefiks: String, val verdi: String, val ytelse: Ytelse? = null, - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX", timezone = "UTC") val utløpsdato: ZonedDateTime, - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX", timezone = "UTC") val opprettet: ZonedDateTime? = null, - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX", timezone = "UTC") val endret: ZonedDateTime? = null + @JsonFormat(shape = JsonFormat.Shape.STRING) val utløpsdato: ZonedDateTime, + @JsonFormat(shape = JsonFormat.Shape.STRING) val opprettet: ZonedDateTime? = null, + @JsonFormat(shape = JsonFormat.Shape.STRING) val endret: ZonedDateTime? = null ) data class CacheResponseDTO( val nøkkel: String, val verdi: String, - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX", timezone = "UTC") val utløpsdato: ZonedDateTime, - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX", timezone = "UTC") val opprettet: ZonedDateTime? = null, - @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd'T'HH:mm:ss.SSSX", timezone = "UTC") val endret: ZonedDateTime? = null + @JsonFormat(shape = JsonFormat.Shape.STRING) val utløpsdato: ZonedDateTime, + @JsonFormat(shape = JsonFormat.Shape.STRING) val opprettet: ZonedDateTime? = null, + @JsonFormat(shape = JsonFormat.Shape.STRING) val endret: ZonedDateTime? = null ) diff --git a/src/test/kotlin/no/nav/cache/cache/IntegrationTest.kt b/src/test/kotlin/no/nav/cache/cache/IntegrationTest.kt index 9cd5f77..6a5fda7 100644 --- a/src/test/kotlin/no/nav/cache/cache/IntegrationTest.kt +++ b/src/test/kotlin/no/nav/cache/cache/IntegrationTest.kt @@ -27,10 +27,12 @@ import org.junit.jupiter.api.Assertions.assertNotNull import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.Test import org.junit.jupiter.api.extension.ExtendWith +import org.skyscreamer.jsonassert.JSONAssert import org.slf4j.LoggerFactory import org.springframework.beans.factory.annotation.Autowired import org.springframework.boot.test.context.SpringBootTest import org.springframework.boot.test.web.client.TestRestTemplate +import org.springframework.http.HttpHeaders import org.springframework.http.HttpStatus import org.springframework.http.MediaType import org.springframework.http.ProblemDetail @@ -107,6 +109,42 @@ internal class IntegrationTest { ) } + @Test + fun `Mellomlagring av json med forskjellige zdt formater skal ikke feile`() { + val requestEntity = RequestEntity.post(CACHE_PATH) + .headers(hentToken().tokenTilHeader()) + .header(HttpHeaders.CONTENT_TYPE, "application/json") + .body( + //language=JSON + """ + { + "ytelse": "PLEIEPENGER_SYKT_BARN", + "nøkkelPrefiks": "mellomlagring_psb", + "opprettet": "2024-08-06T10:23:15Z", + "utløpsdato": "2024-08-09T10:23:15.644978Z", + "endret": "2024-08-06T07:39:05.032Z", + "verdi": "{\"key\": \"val\"}" + } + """.trimIndent() + ) + + val response = restTemplate.postAndAssert( + request = requestEntity, + expectedStatus = HttpStatus.CREATED + ) + JSONAssert.assertEquals( + //language=JSON + """ + { + "nøkkel": "mellomlagring_psb_12345678910", + "verdi": "{\"key\": \"val\"}", + "utløpsdato": "2024-08-09T10:23:15.644978Z", + "opprettet": "2024-08-06T10:23:15Z", + "endret": "2024-08-06T07:39:05.032Z" + } + """.trimIndent(), response, true) + } + @Test fun `gitt cache lagres, forvent samme verdi ved henting`() { val postRequest = RequestEntity @@ -139,7 +177,8 @@ internal class IntegrationTest { expectedBody = cacheResponseDTO ) - val konsumertUtkast = utkastConsumer.hentMelding(Topics.K9_DITTNAV_VARSEL_UTKAST) { it == cacheInDB.utkastId }?.value() + val konsumertUtkast = + utkastConsumer.hentMelding(Topics.K9_DITTNAV_VARSEL_UTKAST) { it == cacheInDB.utkastId }?.value() logger.info("JSON UTKAST: {}", JSONObject(konsumertUtkast!!).toString(2)) assertThat(konsumertUtkast).isNotNull() }