@@ -17,6 +17,7 @@ import io.ktor.client.request.post
1717import io.ktor.client.request.setBody
1818import io.ktor.client.statement.HttpResponse
1919import io.ktor.client.statement.bodyAsText
20+ import io.ktor.client.statement.request
2021import io.ktor.http.ContentType.Application.Json
2122import io.ktor.http.HttpStatusCode
2223import io.ktor.http.contentType
@@ -343,29 +344,45 @@ class CPARepoIntegrationTest : PostgresOracleTest() {
343344 }
344345
345346 @Test
346- fun `Henter latest updated timestamp` () = cpaRepoTestApp {
347+ fun `Henter latest updated timestamp (deprecated endpoint - redirected) ` () = cpaRepoTestApp {
347348 val httpClient = createClient {
348349 install(ContentNegotiation ) {
349350 json()
350351 }
351352 installCpaRepoAuthentication()
352353 }
354+ val latestTimestamp = setupLatestTimestampsTest(httpClient)
355+ val responseMedSiste = httpClient.get(" /cpa/timestamps/latest" )
356+ assertEquals(" /cpa/timestamps/last_updated/latest" , responseMedSiste.request.url.encodedPath)
357+ assertEquals(latestTimestamp.toString(), responseMedSiste.bodyAsText())
358+ }
353359
354- // Oppdatér CPA 35065 med gårdagens dato
355- val updatedTimestamp1 = Instant .now().minus(1 , ChronoUnit .DAYS ).truncatedTo(ChronoUnit .SECONDS )
356- postCpaRequest(httpClient, updatedTimestamp1, " nav-qass-35065.xml" )
357-
358- // Oppdatér CPA 31162 med dato forgårs
359- val updatedTimestamp2 = Instant .now().minus(2 , ChronoUnit .DAYS ).truncatedTo(ChronoUnit .SECONDS )
360- postCpaRequest(httpClient, updatedTimestamp2, " nav-qass-31162.xml" )
360+ @Test
361+ fun `Henter latest updated timestamp` () = cpaRepoTestApp {
362+ val httpClient = createClient {
363+ install(ContentNegotiation ) {
364+ json()
365+ }
366+ installCpaRepoAuthentication()
367+ }
368+ val latestTimestamp = setupLatestTimestampsTest(httpClient)
369+ val responseMedSiste = httpClient.get(" /cpa/timestamps/last_updated/latest" )
370+ assertEquals(latestTimestamp.toString(), responseMedSiste.bodyAsText())
371+ }
361372
362- // Slett den siste CPA'ene slik at vi kun har to CPA'er i databasen
363- val deleteResponse = httpClient.delete(" /cpa/delete/multiple_channels_and_multiple_endpoints" )
364- assertEquals(HttpStatusCode .OK , deleteResponse.status)
373+ @Test
374+ fun `Henter timestamps map (deprecated endpoint - redirected)` () = cpaRepoTestApp {
375+ val httpClient = createClient {
376+ install(ContentNegotiation ) {
377+ json()
378+ }
379+ installCpaRepoAuthentication()
380+ }
381+ val updatedTimestamp = Instant .now().minus(1 , ChronoUnit .DAYS ).truncatedTo(ChronoUnit .SECONDS )
382+ postCpaRequest(httpClient, updatedTimestamp, " nav-qass-35065.xml" )
365383
366- // Forvent at update-datoen til CPA 35065 blir returnert
367- val responseMedSiste = httpClient.get(" /cpa/timestamps/latest" )
368- assertEquals(updatedTimestamp1.toString(), responseMedSiste.bodyAsText())
384+ val response = httpClient.get(" /cpa/timestamps" )
385+ assertEquals(" /cpa/timestamps/last_updated" , response.request.url.encodedPath)
369386 }
370387
371388 @Test
@@ -379,21 +396,22 @@ class CPARepoIntegrationTest : PostgresOracleTest() {
379396 val updatedTimestamp = Instant .now().minus(1 , ChronoUnit .DAYS ).truncatedTo(ChronoUnit .SECONDS )
380397 postCpaRequest(httpClient, updatedTimestamp, " nav-qass-35065.xml" )
381398
382- val responseMedAlle = httpClient.get(" /cpa/timestamps" ).body<Map <String , String >>()
383- assertNotNull(responseMedAlle)
399+ val response = httpClient.get(" /cpa/timestamps/last_updated" )
400+ val responseMap = response.body<Map <String , String >>()
401+ assertNotNull(responseMap)
384402 assertEquals(
385403 postgresTestSetup.timestamp.toString(),
386- responseMedAlle [" nav:qass:31162" ],
404+ responseMap [" nav:qass:31162" ],
387405 " CPA 31162 skal ha timestamp fra postgresTestSetup"
388406 )
389407 assertEquals(
390408 updatedTimestamp.toString(),
391- responseMedAlle [" nav:qass:35065" ],
409+ responseMap [" nav:qass:35065" ],
392410 " CPA 35065 skal ha timestamp satt av testen"
393411 )
394412 assertEquals(
395413 postgresTestSetup.timestamp.toString(),
396- responseMedAlle [" multiple_channels_and_multiple_endpoints" ],
414+ responseMap [" multiple_channels_and_multiple_endpoints" ],
397415 " CPA multiple_channels_and_multiple_endpoints skal ha timestamp fra postgresTestSetup"
398416 )
399417 }
@@ -749,6 +767,22 @@ class CPARepoIntegrationTest : PostgresOracleTest() {
749767 return postResponse
750768 }
751769
770+ private suspend fun setupLatestTimestampsTest (httpClient : HttpClient ): Instant {
771+ // Oppdatér CPA 35065 med gårdagens dato
772+ val updatedTimestamp1 = Instant .now().minus(1 , ChronoUnit .DAYS ).truncatedTo(ChronoUnit .SECONDS )
773+ postCpaRequest(httpClient, updatedTimestamp1, " nav-qass-35065.xml" )
774+
775+ // Oppdatér CPA 31162 med dato forgårs
776+ val updatedTimestamp2 = Instant .now().minus(2 , ChronoUnit .DAYS ).truncatedTo(ChronoUnit .SECONDS )
777+ postCpaRequest(httpClient, updatedTimestamp2, " nav-qass-31162.xml" )
778+
779+ // Slett den siste CPA'en slik at vi kun har to CPA'er i databasen
780+ val deleteResponse = httpClient.delete(" /cpa/delete/multiple_channels_and_multiple_endpoints" )
781+ assertEquals(HttpStatusCode .OK , deleteResponse.status)
782+
783+ return updatedTimestamp1
784+ }
785+
752786 private suspend fun getLastUsedMap (httpClient : HttpClient ): Map <String , String ?> {
753787 val lastUsedResponse = httpClient.get(" /cpa/timestamps/last_used" )
754788 assertEquals(HttpStatusCode .OK , lastUsedResponse.status, " Expected OK status for /cpa/timestamps/last_used" )
0 commit comments