-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jan Kroken
committed
Nov 14, 2023
1 parent
aef73ef
commit 5c3d2c9
Showing
7 changed files
with
174 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
...v/pensjon/opptjening/omsorgsopptjening/bestem/pensjonsopptjening/brev/model/BrevClient.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model | ||
|
||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.external.PENBrevClient | ||
import java.time.Year | ||
|
||
interface BrevClient { | ||
fun sendBrev(sakId: String, fnr: String, omsorgsår: Int): Journalpost | ||
fun sendBrev(sakId: String, fnr: String, omsorgsår: Year, språk: PENBrevClient.BrevSpraak? = null): Journalpost | ||
} | ||
|
||
data class BrevClientException(val msg: String, val throwable: Throwable?): RuntimeException(msg, throwable) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
97 changes: 97 additions & 0 deletions
97
...on/opptjening/omsorgsopptjening/bestem/pensjonsopptjening/brev/external/BrevKlientTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.external | ||
|
||
import com.github.tomakehurst.wiremock.client.WireMock | ||
import com.github.tomakehurst.wiremock.client.WireMock.* | ||
import com.github.tomakehurst.wiremock.core.WireMockConfiguration | ||
import com.github.tomakehurst.wiremock.junit5.WireMockExtension | ||
import com.github.tomakehurst.wiremock.matching.UrlPattern | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.BrevClient | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.BrevClientException | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.model.Journalpost | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.common.SpringContextTest | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.utils.Mdc | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.CorrelationId | ||
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.InnlesingId | ||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.assertThrows | ||
import org.junit.jupiter.api.extension.RegisterExtension | ||
import org.springframework.beans.factory.annotation.Autowired | ||
import org.springframework.beans.factory.annotation.Value | ||
import org.springframework.http.HttpHeaders | ||
import java.time.LocalDate | ||
import java.time.Year | ||
import java.time.format.DateTimeFormatter | ||
import kotlin.test.Test | ||
import kotlin.test.assertEquals | ||
|
||
class BrevKlientTest( | ||
@Value("\${PEN_BASE_URL}") | ||
private val baseUrl: String, | ||
) : SpringContextTest.NoKafka() { | ||
|
||
@Autowired | ||
private lateinit var client: PENBrevClient | ||
|
||
companion object { | ||
@JvmField | ||
@RegisterExtension | ||
val wiremock = WireMockExtension.newInstance() | ||
.options(WireMockConfiguration.wireMockConfig().port(WIREMOCK_PORT)) | ||
.build()!! | ||
} | ||
|
||
@Test | ||
fun `kaster exception dersom kall ikke gikk bra`() { | ||
Mdc.scopedMdc(CorrelationId.generate()) { | ||
Mdc.scopedMdc(InnlesingId.generate()) { | ||
val url = baseUrl + PENBrevClient.sendBrevPath("42") | ||
println("Wiremock-path: ${url}") | ||
wiremock.givenThat( | ||
WireMock.post("*") | ||
// WireMock.post(WireMock.urlPathEqualTo(url)) | ||
.willReturn(WireMock.serverError()) | ||
) | ||
|
||
assertThrows<BrevClientException> { | ||
client.sendBrev( | ||
"42", | ||
"12345678912", | ||
Year.of(2020), | ||
) | ||
} | ||
} | ||
} | ||
} | ||
|
||
@Test | ||
fun `returnerer id for opprettet brev hvis kall går bra`() { | ||
val sakId = "42" | ||
Mdc.scopedMdc(CorrelationId.generate()) { correlationId -> | ||
Mdc.scopedMdc(InnlesingId.generate()) { innlesingId -> | ||
wiremock.givenThat( | ||
WireMock.post(UrlPattern.ANY) | ||
// WireMock.post(WireMock.urlPathEqualTo(PENBrevClient.sendBrevPath(sakId))) | ||
// .withHeader(HttpHeaders.AUTHORIZATION, equalTo("Bearer test.token.test")) | ||
// .withHeader(HttpHeaders.ACCEPT, equalTo("application/json")) | ||
// .withHeader(HttpHeaders.CONTENT_TYPE, equalTo("application/json")) | ||
// .withHeader("x-correlation-id", equalTo(correlationId.toString())) | ||
// .withHeader("X-Correlation-ID", equalTo(correlationId.toString())) | ||
// .withHeader("x-innlesing-id", equalTo(innlesingId.toString())) | ||
// .withRequestBody( | ||
// equalToJson( | ||
// """{"brevdata":{"aarInvilgetOmsorgspoeng":2020},"eksternReferanseId":"${'$'}{json-unit.any-string}"}""" | ||
// ) | ||
// ) | ||
.willReturn( | ||
WireMock.created() | ||
.withBody("""{"journalpostId":"123"}""") | ||
.withHeader(HttpHeaders.CONTENT_TYPE, "application/json") | ||
) | ||
) | ||
|
||
assertThat(client.sendBrev("42", "123451234512", Year.of(2020))) | ||
.isEqualTo(Journalpost("123")) | ||
} | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ing/omsorgsopptjening/bestem/pensjonsopptjening/brev/external/PENBrevSerializationTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
package no.nav.pensjon.opptjening.omsorgsopptjening.bestem.pensjonsopptjening.brev.external | ||
|
||
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.serialize | ||
import org.junit.jupiter.api.Test | ||
import java.time.Year | ||
|
||
class PENBrevSerializationTest { | ||
|
||
@Test | ||
fun testSerializeRegular() { | ||
val request = PENBrevClient.SendBrevRequest(omsorgsår = Year.of(2010), eksternReferanseId = "42") | ||
val json = serialize(request) | ||
println("2 $json") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters