From 894363917736f0a15b20d5dd7bdb7e96c7dcca47 Mon Sep 17 00:00:00 2001 From: Audun Persson <42343764+audun-persson@users.noreply.github.com> Date: Wed, 9 Nov 2022 10:37:50 +0100 Subject: [PATCH] Mp 449 Ta i bruk versjon 2 av Arena ORDS meldeplikt endepunkter (#91) * Tar i bruk versjon 2 av Arena ORDS meldeplikt endepunkter --- .../service/ArenaOrdsService.kt | 17 +++++++++---- .../meldekortservice/utils/Utils.kt | 12 +++++----- .../config/CallLoggingPluginTest.kt | 2 +- .../service/ArenaOrdsServiceTest.kt | 24 +++++++++++-------- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/main/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsService.kt b/src/main/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsService.kt index a467a4ee..d5ac28ff 100644 --- a/src/main/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsService.kt +++ b/src/main/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsService.kt @@ -27,8 +27,8 @@ class ArenaOrdsService( suspend fun hentMeldekort(fnr: String): OrdsStringResponse { val execResult: Result = runCatching { - ordsClient.request("${env.ordsUrl}$ARENA_ORDS_HENT_MELDEKORT$fnr") { - setupOrdsRequest() + ordsClient.request("${env.ordsUrl}$ARENA_ORDS_HENT_MELDEKORT") { + setupOrdsRequestFnr(fnr) } } @@ -42,10 +42,10 @@ class ArenaOrdsService( suspend fun hentHistoriskeMeldekort(fnr: String, antallMeldeperioder: Int): Person { val person: String = ordsClient.get( - "${env.ordsUrl}$ARENA_ORDS_HENT_HISTORISKE_MELDEKORT$fnr" + + "${env.ordsUrl}$ARENA_ORDS_HENT_HISTORISKE_MELDEKORT" + "$ARENA_ORDS_MELDEPERIODER_PARAM$antallMeldeperioder" ) { - setupOrdsRequest() + setupOrdsRequestFnr(fnr) }.body() return mapFraXml(person, Person::class.java) @@ -76,12 +76,19 @@ class ArenaOrdsService( return 0 } - private fun HttpRequestBuilder.setupOrdsRequest(meldekortId: Long? = null) { + private fun HttpRequestBuilder.setupOrdsRequestFnr(fnr: String? = null) { + return setupOrdsRequest(null, fnr) + } + + private fun HttpRequestBuilder.setupOrdsRequest(meldekortId: Long? = null, fnr: String? = null) { headers.append("Accept", "application/xml; charset=UTF-8") headers.append("Authorization", "Bearer ${hentToken().accessToken}") if (meldekortId != null) { headers.append("meldekortId", meldekortId.toString()) } + if (fnr != null) { + headers.append("fnr", fnr) + } } private fun hentToken(): AccessToken { diff --git a/src/main/kotlin/no/nav/meldeplikt/meldekortservice/utils/Utils.kt b/src/main/kotlin/no/nav/meldeplikt/meldekortservice/utils/Utils.kt index 86b02878..4a215682 100644 --- a/src/main/kotlin/no/nav/meldeplikt/meldekortservice/utils/Utils.kt +++ b/src/main/kotlin/no/nav/meldeplikt/meldekortservice/utils/Utils.kt @@ -59,13 +59,13 @@ internal const val WEBLOGIC_PING_PATH = "$API_PATH/weblogic" internal const val KONTROLL_KONTROLL = "/api/v1/kontroll" -internal const val ARENA_ORDS_API_V1 = "/api/v1/meldeplikt" +internal const val ARENA_ORDS_API_MELDEPLIKT_V2 = "/api/v2/meldeplikt" internal const val ARENA_ORDS_TOKEN_PATH = "/api/oauth/token" -internal const val ARENA_ORDS_HENT_MELDEKORT = "$ARENA_ORDS_API_V1/meldekort?fnr=" -internal const val ARENA_ORDS_HENT_HISTORISKE_MELDEKORT = "$ARENA_ORDS_API_V1/meldekort/historiske?fnr=" -internal const val ARENA_ORDS_MELDEPERIODER_PARAM = "&antMeldeperioder=" -internal const val ARENA_ORDS_HENT_MELDEKORTDETALJER = "$ARENA_ORDS_API_V1/meldekort/detaljer?meldekortId=" -internal const val ARENA_ORDS_KOPIER_MELDEKORT = "$ARENA_ORDS_API_V1/meldekort/kopi" +internal const val ARENA_ORDS_HENT_MELDEKORT = "$ARENA_ORDS_API_MELDEPLIKT_V2/meldekort" +internal const val ARENA_ORDS_HENT_HISTORISKE_MELDEKORT = "$ARENA_ORDS_API_MELDEPLIKT_V2/meldekort/historiske?" +internal const val ARENA_ORDS_MELDEPERIODER_PARAM = "antMeldeperioder=" +internal const val ARENA_ORDS_HENT_MELDEKORTDETALJER = "$ARENA_ORDS_API_MELDEPLIKT_V2/meldekort/detaljer?meldekortId=" +internal const val ARENA_ORDS_KOPIER_MELDEKORT = "$ARENA_ORDS_API_MELDEPLIKT_V2/meldekort/kopi" internal const val SBL_ARBEID_USERNAME = "srvSBLArbeid.username" internal const val SBL_ARBEID_PASSWORD = "srvSBLArbeid.password" diff --git a/src/test/kotlin/no/nav/meldeplikt/meldekortservice/config/CallLoggingPluginTest.kt b/src/test/kotlin/no/nav/meldeplikt/meldekortservice/config/CallLoggingPluginTest.kt index 7e2ad96f..3b9fa25f 100644 --- a/src/test/kotlin/no/nav/meldeplikt/meldekortservice/config/CallLoggingPluginTest.kt +++ b/src/test/kotlin/no/nav/meldeplikt/meldekortservice/config/CallLoggingPluginTest.kt @@ -96,7 +96,7 @@ class CallLoggingPluginTest : TestBase() { "\n" + "$json\n" val expectedUtRequest = "" + - "GET https://dummyurl.nav.no:443/api/v1/meldeplikt/meldekort/detaljer?meldekortId=1\n" + + "GET https://dummyurl.nav.no:443/api/v2/meldeplikt/meldekort/detaljer?meldekortId=1\n" + "Accept: [application/xml; charset=UTF-8,application/json]\n" + "Authorization: Bearer $DUMMY_TOKEN\n" + "Accept-Charset: UTF-8\n" + diff --git a/src/test/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsServiceTest.kt b/src/test/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsServiceTest.kt index b51bc6b1..59718182 100644 --- a/src/test/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsServiceTest.kt +++ b/src/test/kotlin/no/nav/meldeplikt/meldekortservice/service/ArenaOrdsServiceTest.kt @@ -32,9 +32,11 @@ class ArenaOrdsServiceTest { val client = HttpClient(MockEngine) { engine { addHandler { request -> - if (request.url.encodedPath.contains("/api/v1/meldeplikt/meldekort") - && request.url.host.contains("dummyurl.nav.no") - ) { + if (request.url.toString() == "https://dummyurl.nav.no/api/v2/meldeplikt/meldekort") { + assertEquals(HttpMethod.Get, request.method) + assertEquals("Bearer $DUMMY_TOKEN", request.headers["Authorization"]) + assertEquals(fnr, request.headers["fnr"]) + respond( defaultObjectMapper.writeValueAsString(response), headers = headersOf(HttpHeaders.ContentType, ContentType.Application.Json.toString()) @@ -61,7 +63,7 @@ class ArenaOrdsServiceTest { val client = HttpClient(MockEngine) { engine { addHandler { request -> - if (request.url.encodedPath.contains("/api/v1/meldeplikt/meldekort/12345678") + if (request.url.encodedPath.contains("/api/v2/meldeplikt/meldekort/12345678") && request.url.host.contains("dummyurl.nav.no") ) { respond( @@ -85,14 +87,16 @@ class ArenaOrdsServiceTest { @Test fun `test hent historiskeMeldekort returns OK status`() { - val xmlString = """1testtesttesttest10""" + val xmlString = + """1testtesttesttest10""" val client = HttpClient(MockEngine) { engine { addHandler { request -> assertEquals(HttpMethod.Get, request.method) assertEquals("Bearer $DUMMY_TOKEN", request.headers["Authorization"]) + assertEquals(fnr, request.headers["fnr"]) assertEquals( - "https://dummyurl.nav.no/api/v1/meldeplikt/meldekort/historiske?fnr=1234&antMeldeperioder=10", + "https://dummyurl.nav.no/api/v2/meldeplikt/meldekort/historiske?antMeldeperioder=10", request.url.toString() ) @@ -105,7 +109,7 @@ class ArenaOrdsServiceTest { val arenaOrdsService = ArenaOrdsService(client) runBlocking { - val actualResponse = arenaOrdsService.hentHistoriskeMeldekort("1234", 10) + val actualResponse = arenaOrdsService.hentHistoriskeMeldekort(fnr, 10) assertEquals(1, actualResponse.personId) } @@ -141,7 +145,7 @@ class ArenaOrdsServiceTest { assertEquals(HttpMethod.Get, request.method) assertEquals("Bearer $DUMMY_TOKEN", request.headers["Authorization"]) assertEquals( - "https://dummyurl.nav.no/api/v1/meldeplikt/meldekort/detaljer?meldekortId=1", + "https://dummyurl.nav.no/api/v2/meldeplikt/meldekort/detaljer?meldekortId=1", request.url.toString() ) @@ -169,7 +173,7 @@ class ArenaOrdsServiceTest { assertEquals("Bearer $DUMMY_TOKEN", request.headers["Authorization"]) assertEquals("123", request.headers["meldekortId"]) assertEquals( - "https://dummyurl.nav.no/api/v1/meldeplikt/meldekort/kopi", + "https://dummyurl.nav.no/api/v2/meldeplikt/meldekort/kopi", request.url.toString() ) @@ -198,7 +202,7 @@ class ArenaOrdsServiceTest { assertEquals("Bearer $DUMMY_TOKEN", request.headers["Authorization"]) assertEquals("123", request.headers["meldekortId"]) assertEquals( - "https://dummyurl.nav.no/api/v1/meldeplikt/meldekort/kopi", + "https://dummyurl.nav.no/api/v2/meldeplikt/meldekort/kopi", request.url.toString() )