Skip to content

Commit

Permalink
Mp 449 Ta i bruk versjon 2 av Arena ORDS meldeplikt endepunkter (#91)
Browse files Browse the repository at this point in the history
* Tar i bruk versjon 2 av Arena ORDS meldeplikt endepunkter
  • Loading branch information
audun-persson authored Nov 9, 2022
1 parent 18d8759 commit 8943639
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ class ArenaOrdsService(

suspend fun hentMeldekort(fnr: String): OrdsStringResponse {
val execResult: Result<HttpResponse> = runCatching {
ordsClient.request("${env.ordsUrl}$ARENA_ORDS_HENT_MELDEKORT$fnr") {
setupOrdsRequest()
ordsClient.request("${env.ordsUrl}$ARENA_ORDS_HENT_MELDEKORT") {
setupOrdsRequestFnr(fnr)
}
}

Expand All @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -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(
Expand All @@ -85,14 +87,16 @@ class ArenaOrdsServiceTest {

@Test
fun `test hent historiskeMeldekort returns OK status`() {
val xmlString = """<Person><personId>1</personId><Etternavn>test</Etternavn><Fornavn>test</Fornavn><Maalformkode>test</Maalformkode><Meldeform>test</Meldeform><meldekortListe/><antallGjenstaaendeFeriedager>10</antallGjenstaaendeFeriedager><fravaerListe/></Person>"""
val xmlString =
"""<Person><personId>1</personId><Etternavn>test</Etternavn><Fornavn>test</Fornavn><Maalformkode>test</Maalformkode><Meldeform>test</Meldeform><meldekortListe/><antallGjenstaaendeFeriedager>10</antallGjenstaaendeFeriedager><fravaerListe/></Person>"""
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()
)

Expand All @@ -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)
}
Expand Down Expand Up @@ -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()
)

Expand Down Expand Up @@ -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()
)

Expand Down Expand Up @@ -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()
)

Expand Down

0 comments on commit 8943639

Please sign in to comment.