Skip to content

Commit

Permalink
endret henting av pensjonspoeng til å bruke post-kall
Browse files Browse the repository at this point in the history
  • Loading branch information
jankroken-nav committed Aug 2, 2024
1 parent 29e0083 commit d6c7348
Show file tree
Hide file tree
Showing 7 changed files with 147 additions and 59 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.godskriv.external

data class HentPensjonspoengListeRequest(
val fnr : String,
val fomAr: Int? = null,
val tomAr: Int? = null,
val pensjonspoengType : String? = null,
)
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,19 @@ internal class PoppClient(
}

override fun hentPensjonspoengForOmsorgstype(fnr: String, år: Int, type: DomainOmsorgstype): Pensjonspoeng.Omsorg {
val url = "$baseUrl/pensjonspoeng?fomAr=$år&tomAr=$år&pensjonspoengType=${PoppOmsorgType.from(type)}"
val url = "$baseUrl/pensjonspoeng/hent"
try {
return restTemplate.exchange(
url,
HttpMethod.GET,
HttpMethod.POST,
HttpEntity(
null,
HentPensjonspoengListeRequest(
fnr = fnr,
fomAr = år,
tomAr = år,
pensjonspoengType = PoppOmsorgType.from(type).toString(),
),
HttpHeaders().apply {
add("fnr", fnr)
add("Nav-Call-Id", Mdc.getCorrelationId())
add("Nav-Consumer-Id", "omsorgsopptjening-bestem-pensjonsopptjening")
add(CorrelationId.identifier, Mdc.getCorrelationId())
Expand Down Expand Up @@ -112,15 +116,19 @@ internal class PoppClient(
}

override fun hentPensjonspoengForInntekt(fnr: String, år: Int): Pensjonspoeng.Inntekt {
val url = "$baseUrl/pensjonspoeng?fomAr=$år&tomAr=$år&pensjonspoengType=${PoppOmsorgType.PPI}"
val url = "$baseUrl/pensjonspoeng/hent"
try {
return restTemplate.exchange(
url,
HttpMethod.GET,
HttpMethod.POST,
HttpEntity(
null,
HentPensjonspoengListeRequest(
fnr = fnr,
fomAr = år,
tomAr = år,
pensjonspoengType = "PPI",
),
HttpHeaders().apply {
add("fnr", fnr)
add("Nav-Call-Id", Mdc.getCorrelationId())
add("Nav-Consumer-Id", "omsorgsopptjening-bestem-pensjonsopptjening")
add(CorrelationId.identifier, Mdc.getCorrelationId())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening

import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.equalToJson
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.Brev
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.BrevService
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.repository.BrevRepository
Expand Down Expand Up @@ -86,8 +87,16 @@ class AdministrasjonsTest : SpringContextTest.NoKafka() {
fun lagreOgProsesserMeldingSomGirBrev(): UUID {
wiremock.ingenPensjonspoeng("12345678910") //mor
wiremock.givenThat(
WireMock.get(WireMock.urlPathEqualTo(POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo("04010012797")) //far
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(
equalToJson(
"""{
"fnr": "04010012797"
}
""".trimIndent(),
true, false,
)
)
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand Down Expand Up @@ -416,7 +425,7 @@ class AdministrasjonsTest : SpringContextTest.NoKafka() {
.withHeader("X-Correlation-ID", WireMock.equalTo(correlationId.toString()))
.withHeader("x-innlesing-id", WireMock.equalTo(innlesingId.toString()))
.withRequestBody(
WireMock.equalToJson(
equalToJson(
"""
{
"versjon":2,
Expand Down Expand Up @@ -580,7 +589,7 @@ class AdministrasjonsTest : SpringContextTest.NoKafka() {
.withHeader("X-Correlation-ID", WireMock.equalTo(correlationId.toString()))
.withHeader("x-innlesing-id", WireMock.equalTo(innlesingId.toString()))
.withRequestBody(
WireMock.equalToJson(
equalToJson(
"""
{
"versjon":2,
Expand Down Expand Up @@ -662,7 +671,7 @@ class AdministrasjonsTest : SpringContextTest.NoKafka() {
.withHeader("X-Correlation-ID", WireMock.equalTo(correlationId.toString()))
.withHeader("x-innlesing-id", WireMock.equalTo(innlesingId.toString()))
.withRequestBody(
WireMock.equalToJson(
equalToJson(
"""
{
"versjon":2,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev

import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.equalToJson
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.Brev
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.repository.BrevRepository
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.common.SpringContextTest
Expand Down Expand Up @@ -62,8 +63,12 @@ internal class BrevopprettelseTest : SpringContextTest.NoKafka() {
fun `innvilget omsorgsopptjening for barn over 6 år skal sende brev dersom omsorgsyter ikke mottok omsorgspoeng i året før omsorgsåret`() {
wiremock.ingenPensjonspoeng("12345678910") //mor
wiremock.givenThat(
WireMock.get(WireMock.urlPathEqualTo(POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo("04010012797")) //far
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(equalToJson("""
{
"fnr" : "04010012797"
}
""".trimIndent(), false, true))
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand Down Expand Up @@ -131,9 +136,13 @@ internal class BrevopprettelseTest : SpringContextTest.NoKafka() {
@Test
fun `innvilget omsorgsopptjening for barn over 6 år skal sende brev dersom omsorgsyters omsorgspoeng som godskrives er høyere enn annen forelders pensjonspoeng for inntekt i omsorgsåret`() {
wiremock.givenThat(
WireMock.get(WireMock.urlPathEqualTo(POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo("12345678910")) //mor
.withQueryParam("fomAr", WireMock.equalTo("2019"))
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(equalToJson("""
{
"fnr": "12345678910",
"fomAr": 2019
}
""".trimIndent(), false, true))
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand All @@ -154,8 +163,12 @@ internal class BrevopprettelseTest : SpringContextTest.NoKafka() {
)

wiremock.givenThat(
WireMock.get(WireMock.urlPathEqualTo(POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo("04010012797")) //far
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(equalToJson("""
{
"fnr" : "04010012797"
}
""".trimIndent(), false, true))
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand Down Expand Up @@ -217,9 +230,13 @@ internal class BrevopprettelseTest : SpringContextTest.NoKafka() {
@Test
fun `innvilget omsorgsopptjening for barn over 6 år skal ikke sende brev dersom omsorgsyters omsorgspoeng som godskrives er lavere enn annen forelders pensjonspoeng for inntekt i omsorgsåret`() {
wiremock.givenThat(
WireMock.get(WireMock.urlPathEqualTo(POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo("12345678910")) //mor
.withQueryParam("fomAr", WireMock.equalTo("2019"))
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(equalToJson("""
{
"fnr" : "12345678910",
"fomAr": 2019
}
""".trimIndent(), false, true))
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand All @@ -240,8 +257,12 @@ internal class BrevopprettelseTest : SpringContextTest.NoKafka() {
)

wiremock.givenThat(
WireMock.get(WireMock.urlPathEqualTo(POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo("04010012797")) //far
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(equalToJson("""
{
"fnr" : "04010012797"
}
""".trimIndent(), false, true))
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand Down Expand Up @@ -307,8 +328,12 @@ internal class BrevopprettelseTest : SpringContextTest.NoKafka() {
fun `innvilget omsorgsopptjening for barn over 6 år skal bare sende 1 brev`() {
wiremock.ingenPensjonspoeng("12345678910") //mor
wiremock.givenThat(
WireMock.get(WireMock.urlPathEqualTo(POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo("04010012797")) //far
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(equalToJson("""
{
"fnr" : "04010012797"
}
""".trimIndent(), false, true))
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ import com.fasterxml.jackson.databind.JsonNode
import com.fasterxml.jackson.module.kotlin.readValue
import com.github.tomakehurst.wiremock.client.ResponseDefinitionBuilder
import com.github.tomakehurst.wiremock.client.WireMock
import com.github.tomakehurst.wiremock.client.WireMock.equalToJson
import com.github.tomakehurst.wiremock.common.FileSource
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.extension.Parameters
import com.github.tomakehurst.wiremock.extension.ResponseDefinitionTransformer
import com.github.tomakehurst.wiremock.http.Request
import com.github.tomakehurst.wiremock.http.ResponseDefinition
import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.common.SpringContextTest.Companion.POPP_PENSJONSPOENG_PATH
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.mapper

/**
Expand Down Expand Up @@ -80,8 +82,12 @@ fun WireMockExtension.stubForPdlTransformer() {

fun WireMockExtension.ingenPensjonspoeng(fnr: String){
this.stubFor(
WireMock.get(WireMock.urlPathEqualTo(SpringContextTest.POPP_PENSJONSPOENG_PATH))
.withHeader("fnr", WireMock.equalTo(fnr))
WireMock.post(WireMock.urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent"))
.withRequestBody(equalToJson("""
{
"fnr" : "$fnr"
}
""".trimIndent(), true, true))
.willReturn(
WireMock.aResponse()
.withHeader("Content-Type", "application/json")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.persongrunnlag.model

import com.github.tomakehurst.wiremock.client.WireMock.aResponse
import com.github.tomakehurst.wiremock.client.WireMock.equalTo
import com.github.tomakehurst.wiremock.client.WireMock.get
import com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor
import com.github.tomakehurst.wiremock.client.WireMock.urlEqualTo
import com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo
import com.github.tomakehurst.wiremock.client.WireMock.*
import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.common.SpringContextTest
Expand Down Expand Up @@ -40,7 +35,7 @@ class HentPensjonspoengClientTest : SpringContextTest.NoKafka() {
Mdc.scopedMdc(CorrelationId.generate()) { correlationId ->
Mdc.scopedMdc(InnlesingId.generate()) { innsendingId ->
wiremock.givenThat(
get(urlPathEqualTo(POPP_PENSJONSPOENG_PATH)).willReturn(
post(urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent")).willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(
Expand Down Expand Up @@ -133,8 +128,16 @@ class HentPensjonspoengClientTest : SpringContextTest.NoKafka() {
)

wiremock.verify(
getRequestedFor(urlEqualTo("/api/pensjonspoeng?fomAr=2022&tomAr=2022&pensjonspoengType=OBO6H"))
.withHeader("fnr", equalTo("12345"))
postRequestedFor(urlEqualTo("/api/pensjonspoeng/hent"))
.withRequestBody(equalToJson(
"""
{
"fnr" : "12345",
"fomAr": 2022,
"tomAr": 2022,
"pensjonspoengType": "OBO6H"
}
""".trimIndent()))
.withHeader("Nav-Call-Id", equalTo(correlationId.toString()))
.withHeader("Nav-Consumer-Id", equalTo("omsorgsopptjening-bestem-pensjonsopptjening"))
.withHeader("x-correlation-id", equalTo(correlationId.toString()))
Expand All @@ -145,8 +148,16 @@ class HentPensjonspoengClientTest : SpringContextTest.NoKafka() {
)

wiremock.verify(
getRequestedFor(urlEqualTo("/api/pensjonspoeng?fomAr=2023&tomAr=2023&pensjonspoengType=PPI"))
.withHeader("fnr", equalTo("12345"))
postRequestedFor(urlEqualTo("/api/pensjonspoeng/hent"))
.withRequestBody(equalToJson(
"""
{
"fnr" : "12345",
"fomAr": 2023,
"tomAr": 2023,
"pensjonspoengType": "PPI"
}
""".trimIndent()))
.withHeader("Nav-Call-Id", equalTo(correlationId.toString()))
.withHeader("Nav-Consumer-Id", equalTo("omsorgsopptjening-bestem-pensjonsopptjening"))
.withHeader("x-correlation-id", equalTo(correlationId.toString()))
Expand All @@ -164,15 +175,15 @@ class HentPensjonspoengClientTest : SpringContextTest.NoKafka() {
Mdc.scopedMdc(CorrelationId.generate()) {
Mdc.scopedMdc(InnlesingId.generate()) {
wiremock.givenThat(
get(urlPathEqualTo(POPP_PENSJONSPOENG_PATH)).willReturn(
post(urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent")).willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(
"""
{
"pensjonspoeng": null
}
""".trimIndent()
{
"pensjonspoeng": null
}
""".trimIndent()
)
)
)
Expand Down Expand Up @@ -242,7 +253,7 @@ class HentPensjonspoengClientTest : SpringContextTest.NoKafka() {
Mdc.scopedMdc(CorrelationId.generate()) {
Mdc.scopedMdc(InnlesingId.generate()) {
wiremock.givenThat(
get(urlPathEqualTo(POPP_PENSJONSPOENG_PATH)).willReturn(
post(urlPathEqualTo("$POPP_PENSJONSPOENG_PATH/hent")).willReturn(
aResponse()
.withHeader("Content-Type", "application/json")
.withBody(
Expand Down
Loading

0 comments on commit d6c7348

Please sign in to comment.