Skip to content

Commit

Permalink
process-metoden kaller nå PDL
Browse files Browse the repository at this point in the history
  • Loading branch information
jankroken-nav committed Oct 13, 2024
1 parent 2ad4a28 commit ecd5a95
Show file tree
Hide file tree
Showing 9 changed files with 123 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,9 @@ class BarnetrygdmottakerService(

val filter = GyldigÅrsintervallFilter(barnetrygdmottakerUtenPdlData.år)

// val person = pdlService.hentPerson(barnetrygdmottaker.ident)
val personId = pdlService.hentPerson(barnetrygdmottaker.ident)
// temporary
val personId =
PersonId(barnetrygdmottakerUtenPdlData.ident, setOf(barnetrygdmottakerUtenPdlData.ident))
// val personId = PersonId(barnetrygdmottakerUtenPdlData.ident, setOf(barnetrygdmottakerUtenPdlData.ident))
println("%%% PERSON: $personId")

val barnetrygdmottaker = barnetrygdmottakerUtenPdlData.withPerson(personId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class PdlClient(
PdlQuery(graphqlQuery.hentPersonQuery(), FnrVariables(ident = fnr)),
HttpHeaders().apply {
add("Nav-Call-Id", Mdc.getCorrelationId().toString())
add("Nav-Consumer-Id", "omsorgsopptjening-bestem-pensjonsopptjening")
add("Nav-Consumer-Id", "omsorgsopptjening-start-innlesning")
add("Tema", "PEN")
add(CorrelationId.identifier, Mdc.getCorrelationId().toString())
add(InnlesingId.identifier, Mdc.getInnlesingId().toString())
Expand All @@ -50,7 +50,7 @@ class PdlClient(
HttpMethod.POST,
URI.create(pdlUrl)
)

// restTemplate.interceptors = listOf(RestTemplateLoggingInterceptor())
val response = restTemplate.exchange(
entity,
PdlResponse::class.java
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.external.pdl
import org.springframework.http.HttpRequest
import org.springframework.http.client.ClientHttpRequestExecution
import org.springframework.http.client.ClientHttpRequestInterceptor
import org.springframework.http.client.ClientHttpResponse
import org.springframework.util.StreamUtils
import java.nio.charset.StandardCharsets

class RestTemplateLoggingInterceptor : ClientHttpRequestInterceptor {
override fun intercept(
request: HttpRequest,
body: ByteArray,
execution: ClientHttpRequestExecution
): ClientHttpResponse {
val response = execution.execute(request, body)
println("Response Body: " + StreamUtils.copyToString(response.body, StandardCharsets.UTF_8))
return response
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.bar
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.barnetrygd.`hent-barnetrygd ok - ingen perioder`
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.repository.BarnetrygdInnlesingRepository
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.repository.BarnetrygdmottakerRepository
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.pdl.pdl
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.pdl.`pdl fnr ett i bruk`
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.pdl.`pdl fnr fra query`
import org.apache.kafka.clients.producer.ProducerRecord
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Assertions.assertInstanceOf
Expand Down Expand Up @@ -126,7 +128,8 @@ class BarnetrygdmottakerServiceTest : SpringContextTest.NoKafka() {
)
)

wiremock.`pdl fnr ett i bruk`()
// wiremock.pdl("12345678910", listOf("12345678910"))
wiremock.`pdl fnr fra query`()
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/hent-barnetrygd"))
.inScenario("feilOgFerdig")
Expand Down Expand Up @@ -332,7 +335,8 @@ class BarnetrygdmottakerServiceTest : SpringContextTest.NoKafka() {
CompletableFuture.completedFuture(it.arguments[0])
}

wiremock.`pdl fnr ett i bruk`()
// wiremock.pdl("12345678911", listOf("12345678911"))
wiremock.`pdl fnr fra query`()
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/hent-barnetrygd"))
.withRequestBody(equalToJson("""{"ident":"12345678911","fraDato":"2023-01-01"}"""))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ internal class PdlServiceTest : SpringContextTest.NoKafka() {
.withHeader("Authorization", WireMock.equalTo("Bearer $MOCK_TOKEN"))
.withHeader("Accept", WireMock.equalTo("application/json"))
.withHeader("Content-Type", WireMock.equalTo("application/json"))
.withHeader("Nav-Consumer-Id", WireMock.equalTo("omsorgsopptjening-bestem-pensjonsopptjening"))
.withHeader("Nav-Consumer-Id", WireMock.equalTo("omsorgsopptjening-start-innlesning"))
.withHeader("Tema", WireMock.equalTo("PEN"))
.withHeader(
"x-correlation-id",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@ fun WireMockExtension.pdl(fnr: String, historiske: List<String>): StubMapping {
)
}

fun WireMockExtension.`pdl fnr fra query`(): StubMapping {
return this.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/graphql"))
.willReturn(
WireMock.aResponse()
.withTransformers("response-template")
.withHeader("Content-Type", "application/json")
.withStatus(202)
.withBodyFile(
"pdl/fnr_fra_query.json"
)
)
)
}

fun WireMockExtension.`pdl bad request`(): StubMapping {
return this.pdlResponse("error_bad_request.json")
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.external.pdl

import com.github.tomakehurst.wiremock.core.WireMockConfiguration
import com.github.tomakehurst.wiremock.junit5.WireMockExtension
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.CorrelationId
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.InnlesingId
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.Mdc
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.SpringContextTest
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.external.pdl.PdlService
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.extension.RegisterExtension
import org.springframework.beans.factory.annotation.Autowired

class WiremockScenarioTest : SpringContextTest.NoKafka() {

companion object {
@JvmField
@RegisterExtension
val wiremock = WireMockExtension.newInstance()
.options(WireMockConfiguration.wireMockConfig().port(WIREMOCK_PORT))
.build()!!
}

@Autowired
lateinit var pdlService: PdlService

@Test
fun `wiremock fnr fra query returnerer riktig fnr`() {
val fnr = "91929394959"
wiremock.`pdl fnr fra query`()

val person =
Mdc.scopedMdc(CorrelationId.generate()) {
Mdc.scopedMdc(InnlesingId.generate()) {
pdlService.hentPerson(fnr)
}
}
assertThat(person.fnr).isEqualTo(fnr)
}
}
18 changes: 18 additions & 0 deletions src/test/resources/__files/pdl/fnr_fra_query.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{#assign fnr}}{{regexExtract request.body '"(variables)"\:\{"ident"\:"([^"]+)"' 'parts'}}{{/assign}}
{
"data": {
"hentPerson": {
"folkeregisteridentifikator": [
{
"identifikasjonsnummer": "{{parts.1}}",
"status": "I_BRUK",
"type": "FNR",
"metadata": {
"historisk": false,
"master": "FREG"
}
}
]
}
}
}
19 changes: 19 additions & 0 deletions src/test/resources/__files/pdl/fnr_fra_query_backup.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"variables":{"ident":"91929394959"}}
{{#assign fnr}}{{regexExtract request.body '(pdlPerson)\(([^)]+)' 'parts'}}{{/assign}}
{
"data": {
"hentPerson": {
"folkeregisteridentifikator": [
{
"identifikasjonsnummer": "{{request.body}}",
"status": "I_BRUK",
"type": "FNR",
"metadata": {
"historisk": false,
"master": "FREG"
}
}
]
}
}
}

0 comments on commit ecd5a95

Please sign in to comment.