Skip to content

Commit

Permalink
Dont require correlation/innlesing when initiating
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob-meidell committed Aug 28, 2023
1 parent cd04d47 commit 1e08065
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import pensjon.opptjening.azure.ad.client.TokenProvider
import reactor.core.publisher.Mono
import java.time.LocalDate
import java.time.Month
import java.util.UUID
import java.util.function.Predicate

/**
Expand Down Expand Up @@ -46,8 +47,7 @@ class BarnetrygdClient(
return webClient
.post()
.uri("/api/ekstern/pensjon/bestill-personer-med-barnetrygd/$ar")
.header(CorrelationId.identifier, Mdc.getCorrelationId())
.header(InnlesingId.identifier, Mdc.getInnlesingId())
.header(CorrelationId.identifier, UUID.randomUUID().toString())
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenProvider.getToken())
.body(
Expand Down Expand Up @@ -105,6 +105,7 @@ class BarnetrygdClient(
.post()
.uri("/api/ekstern/pensjon/hent-barnetrygd")
.header(CorrelationId.identifier, Mdc.getCorrelationId())
.header(InnlesingId.identifier, Mdc.getInnlesingId())
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON_VALUE)
.header(HttpHeaders.AUTHORIZATION, "Bearer " + tokenProvider.getToken())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.junit.jupiter.api.extension.RegisterExtension
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.http.HttpHeaders
import org.springframework.http.MediaType
import org.testcontainers.shaded.org.bouncycastle.crypto.tls.ConnectionEnd.client

class BarnetrygdClientTest : SpringContextTest.NoKafka() {

Expand All @@ -30,38 +31,32 @@ class BarnetrygdClientTest : SpringContextTest.NoKafka() {

@Test
fun `returner ok dersom kall til hent-barnetrygdmottakere går bra`() {
Mdc.scopedMdc(CorrelationId.generate()) {
Mdc.scopedMdc(InnlesingId.generate()) {
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/bestill-personer-med-barnetrygd/2020"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
.willReturn(WireMock.aResponse().withStatus(202).withBody("123enfinid"))
)

client.hentBarnetrygdmottakere(ar = 2020).also {
assertEquals(HentBarnetygdmottakereResponse.Ok("123enfinid", 2020), it)
}
}
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/bestill-personer-med-barnetrygd/2020"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
.willReturn(WireMock.aResponse().withStatus(202).withBody("123enfinid"))
)

client.hentBarnetrygdmottakere(ar = 2020).also {
assertEquals(HentBarnetygdmottakereResponse.Ok("123enfinid", 2020), it)
}
}

@Test
fun `returner feil med diverse informasjon dersom kall til hent-barnetrygdmottakere gir 500`() {
Mdc.scopedMdc(CorrelationId.generate()) {
Mdc.scopedMdc(InnlesingId.generate()) {
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/bestill-personer-med-barnetrygd/2020"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
.willReturn(
WireMock.serverError()
.withBody(
"""
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/bestill-personer-med-barnetrygd/2020"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
.willReturn(
WireMock.serverError()
.withBody(
"""
[
{
"data": {
Expand All @@ -74,46 +69,40 @@ class BarnetrygdClientTest : SpringContextTest.NoKafka() {
}
]
""".trimIndent()
)
)
)

client.hentBarnetrygdmottakere(ar = 2020).also {
assertEquals(
HentBarnetygdmottakereResponse.Feil(
500,
"""[InternalServerErrorResponse(data={key=value}, status=FEILET, melding=Her ble det bare krøll, frontendMelding=test, stacktrace=null)]"""
), it
)
}
}
)

client.hentBarnetrygdmottakere(ar = 2020).also {
assertEquals(
HentBarnetygdmottakereResponse.Feil(
500,
"""[InternalServerErrorResponse(data={key=value}, status=FEILET, melding=Her ble det bare krøll, frontendMelding=test, stacktrace=null)]"""
), it
)
}
}

@Test
fun `returner feil dersom kall til hent-barnetrygdmottakere gir andre feil enn 500`() {
Mdc.scopedMdc(CorrelationId.generate()) {
Mdc.scopedMdc(InnlesingId.generate()) {
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/bestill-personer-med-barnetrygd/2020"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
.willReturn(
WireMock.forbidden().withBody("Forbidden!")
)
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/bestill-personer-med-barnetrygd/2020"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
.willReturn(
WireMock.forbidden().withBody("Forbidden!")
)

client.hentBarnetrygdmottakere(ar = 2020).also {
assertEquals(
HentBarnetygdmottakereResponse.Feil(
403,
"Forbidden!"
), it
)
}
}
)

client.hentBarnetrygdmottakere(ar = 2020).also {
assertEquals(
HentBarnetygdmottakereResponse.Feil(
403,
"Forbidden!"
), it
)
}
}

Expand All @@ -124,6 +113,7 @@ class BarnetrygdClientTest : SpringContextTest.NoKafka() {
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/hent-barnetrygd"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(InnlesingId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
Expand Down Expand Up @@ -171,6 +161,7 @@ class BarnetrygdClientTest : SpringContextTest.NoKafka() {
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/hent-barnetrygd"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(InnlesingId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
Expand Down Expand Up @@ -211,6 +202,7 @@ class BarnetrygdClientTest : SpringContextTest.NoKafka() {
wiremock.stubFor(
WireMock.post(WireMock.urlPathEqualTo("/api/ekstern/pensjon/hent-barnetrygd"))
.withHeader(CorrelationId.identifier, AnythingPattern())
.withHeader(InnlesingId.identifier, AnythingPattern())
.withHeader(HttpHeaders.CONTENT_TYPE, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.ACCEPT, equalTo(MediaType.APPLICATION_JSON_VALUE))
.withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test"))
Expand Down

0 comments on commit 1e08065

Please sign in to comment.