-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
5821159
commit 88c581f
Showing
17 changed files
with
496 additions
and
147 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
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
64 changes: 64 additions & 0 deletions
64
.../etterlatte-behandling-kafka/src/main/kotlin/no/nav/etterlatte/grunnlag/GrunnlagKlient.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,64 @@ | ||
package no.nav.etterlatte.grunnlag | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import io.ktor.client.HttpClient | ||
import io.ktor.client.request.post | ||
import io.ktor.client.request.setBody | ||
import io.ktor.http.ContentType | ||
import io.ktor.http.contentType | ||
import kotlinx.coroutines.runBlocking | ||
import no.nav.etterlatte.libs.common.grunnlag.Grunnlagsopplysning | ||
import no.nav.etterlatte.libs.common.grunnlag.NyePersonopplysninger | ||
import no.nav.etterlatte.libs.common.grunnlag.NyeSaksopplysninger | ||
import no.nav.etterlatte.libs.common.person.Folkeregisteridentifikator | ||
import no.nav.etterlatte.libs.common.sak.SakId | ||
import org.slf4j.LoggerFactory | ||
import java.util.UUID | ||
|
||
class GrunnlagKlient( | ||
private val klient: HttpClient, | ||
private val url: String, | ||
) { | ||
private val logger = LoggerFactory.getLogger(GrunnlagKlient::class.java) | ||
|
||
fun lagreNyePersonopplysninger( | ||
sakId: SakId, | ||
behandlingId: UUID, | ||
fnr: Folkeregisteridentifikator, | ||
nyeOpplysninger: List<Grunnlagsopplysning<JsonNode>>, | ||
) { | ||
logger.info("Lagrer nye personopplysninger på sak $sakId") | ||
|
||
runBlocking { | ||
klient.post("$url/grunnlag/person/behandling/$behandlingId/nye-opplysninger") { | ||
contentType(ContentType.Application.Json) | ||
setBody(NyePersonopplysninger(sakId, fnr, nyeOpplysninger)) | ||
} | ||
} | ||
} | ||
|
||
fun lagreNyeSaksopplysninger( | ||
sakId: SakId, | ||
behandlingId: UUID, | ||
nyeOpplysninger: List<Grunnlagsopplysning<JsonNode>>, | ||
) { | ||
logger.info("Lagrer nye saksopplysninger på sak $sakId") | ||
|
||
runBlocking { | ||
klient.post("$url/grunnlag/behandling/$behandlingId/nye-opplysninger") { | ||
contentType(ContentType.Application.Json) | ||
setBody(NyeSaksopplysninger(sakId, nyeOpplysninger)) | ||
} | ||
} | ||
} | ||
|
||
fun laasVersjonForBehandling(behandlingId: UUID) { | ||
logger.info("Låser grunnlagsversjon for behandling (id=$behandlingId)") | ||
|
||
runBlocking { | ||
klient.post("$url/grunnlag/behandling/$behandlingId/laas") { | ||
contentType(ContentType.Application.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
119 changes: 119 additions & 0 deletions
119
...behandling-kafka/src/test/kotlin/no/nav/etterlatte/grunnlag/GrunnlagHendelserRiverTest.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,119 @@ | ||
package no.nav.etterlatte.grunnlag | ||
|
||
import com.fasterxml.jackson.databind.JsonNode | ||
import io.mockk.mockk | ||
import io.mockk.slot | ||
import io.mockk.verify | ||
import no.nav.etterlatte.libs.common.grunnlag.Grunnlagsopplysning | ||
import no.nav.etterlatte.libs.common.grunnlag.opplysningstyper.Opplysningstype | ||
import no.nav.etterlatte.libs.common.objectMapper | ||
import no.nav.etterlatte.libs.common.rapidsandrivers.lagParMedEventNameKey | ||
import no.nav.etterlatte.libs.common.tidspunkt.Tidspunkt | ||
import no.nav.etterlatte.libs.common.toJsonNode | ||
import no.nav.etterlatte.libs.testdata.grunnlag.AVDOED_FOEDSELSNUMMER | ||
import no.nav.etterlatte.libs.testdata.grunnlag.statiskUuid | ||
import no.nav.etterlatte.rapidsandrivers.BEHANDLING_ID_KEY | ||
import no.nav.etterlatte.rapidsandrivers.EventNames | ||
import no.nav.etterlatte.rapidsandrivers.FNR_KEY | ||
import no.nav.etterlatte.rapidsandrivers.OPPLYSNING_KEY | ||
import no.nav.etterlatte.rapidsandrivers.SAK_ID_KEY | ||
import no.nav.helse.rapids_rivers.JsonMessage | ||
import no.nav.helse.rapids_rivers.testsupport.TestRapid | ||
import org.junit.jupiter.api.Assertions.assertEquals | ||
import org.junit.jupiter.api.BeforeAll | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.TestInstance | ||
import java.util.UUID | ||
|
||
@TestInstance(TestInstance.Lifecycle.PER_CLASS) | ||
internal class GrunnlagHendelserRiverTest { | ||
private val grunnlagKlientMock = mockk<GrunnlagKlient>(relaxed = true) | ||
|
||
private lateinit var inspector: TestRapid | ||
|
||
@BeforeAll | ||
fun beforeAll() { | ||
inspector = | ||
TestRapid().apply { | ||
GrunnlagHendelserRiver(this, grunnlagKlientMock) | ||
} | ||
} | ||
|
||
private val fnr = AVDOED_FOEDSELSNUMMER | ||
private val tidspunkt = Tidspunkt.now() | ||
private val kilde = Grunnlagsopplysning.Pdl(tidspunkt, null, null) | ||
private val nyOpplysning = | ||
Grunnlagsopplysning( | ||
id = statiskUuid, | ||
kilde = kilde, | ||
opplysningType = Opplysningstype.NAVN, | ||
meta = objectMapper.createObjectNode(), | ||
opplysning = "Ola".toJsonNode(), | ||
attestering = null, | ||
fnr = fnr, | ||
) | ||
|
||
@Test | ||
fun `Ny personopplysning sendes til grunnlag`() { | ||
val melding = | ||
JsonMessage | ||
.newMessage( | ||
mapOf( | ||
EventNames.NY_OPPLYSNING.lagParMedEventNameKey(), | ||
OPPLYSNING_KEY to listOf(nyOpplysning), | ||
FNR_KEY to fnr, | ||
SAK_ID_KEY to 1, | ||
BEHANDLING_ID_KEY to UUID.randomUUID(), | ||
), | ||
).toJson() | ||
|
||
inspector.sendTestMessage(melding) | ||
|
||
val opplysningSlot = slot<List<Grunnlagsopplysning<JsonNode>>>() | ||
|
||
verify { grunnlagKlientMock.lagreNyePersonopplysninger(any(), any(), any(), capture(opplysningSlot)) } | ||
|
||
with(opplysningSlot.captured.first()) { | ||
assertEquals(this.id, nyOpplysning.id) | ||
assertEquals(this.kilde, nyOpplysning.kilde) | ||
assertEquals(this.opplysningType, nyOpplysning.opplysningType) | ||
assertEquals(this.meta, nyOpplysning.meta) | ||
assertEquals(this.kilde, nyOpplysning.kilde) | ||
assertEquals(this.attestering, nyOpplysning.attestering) | ||
assertEquals(this.fnr!!.value, nyOpplysning.fnr!!.value) | ||
assertEquals(this.opplysning, nyOpplysning.opplysning) | ||
} | ||
} | ||
|
||
@Test | ||
fun `Ny saksopplysning sendes til grunnlag`() { | ||
val melding = | ||
JsonMessage | ||
.newMessage( | ||
mapOf( | ||
EventNames.NY_OPPLYSNING.lagParMedEventNameKey(), | ||
OPPLYSNING_KEY to listOf(nyOpplysning), | ||
// UTEN fnr for å trigge lagring til saksnivå | ||
SAK_ID_KEY to 1, | ||
BEHANDLING_ID_KEY to UUID.randomUUID(), | ||
), | ||
).toJson() | ||
|
||
inspector.sendTestMessage(melding) | ||
|
||
val opplysningSlot = slot<List<Grunnlagsopplysning<JsonNode>>>() | ||
|
||
verify { grunnlagKlientMock.lagreNyeSaksopplysninger(any(), any(), capture(opplysningSlot)) } | ||
|
||
with(opplysningSlot.captured.first()) { | ||
assertEquals(this.id, nyOpplysning.id) | ||
assertEquals(this.kilde, nyOpplysning.kilde) | ||
assertEquals(this.opplysningType, nyOpplysning.opplysningType) | ||
assertEquals(this.meta, nyOpplysning.meta) | ||
assertEquals(this.kilde, nyOpplysning.kilde) | ||
assertEquals(this.attestering, nyOpplysning.attestering) | ||
assertEquals(this.fnr!!.value, nyOpplysning.fnr!!.value) | ||
assertEquals(this.opplysning, nyOpplysning.opplysning) | ||
} | ||
} | ||
} |
Oops, something went wrong.