Skip to content
This repository has been archived by the owner on Nov 5, 2024. It is now read-only.

Commit

Permalink
Interface, bønne og test for AktørIdCacheRepository
Browse files Browse the repository at this point in the history
  • Loading branch information
marenger committed Jan 12, 2023
1 parent 2dde4e6 commit 3d12581
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package no.nav.fo.veilarbregistrering.aktorIdCache

import no.nav.fo.veilarbregistrering.bruker.Foedselsnummer

interface AktorIdCacheRepository {

fun lagre(aktorIdCache: AktorIdCache)
fun hentAktørId(fnr: Foedselsnummer): AktorIdCache?
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package no.nav.fo.veilarbregistrering.db

import no.nav.fo.veilarbregistrering.aktorIdCache.AktorIdCacheRepository
import no.nav.fo.veilarbregistrering.arbeidssoker.formidlingsgruppe.FormidlingsgruppeRepository
import no.nav.fo.veilarbregistrering.arbeidssoker.meldekort.MeldekortRepository
import no.nav.fo.veilarbregistrering.db.aktorIdCache.AktorIdCacheRepositoryImpl
import no.nav.fo.veilarbregistrering.db.arbeidssoker.FormidlingsgruppeRepositoryImpl
import no.nav.fo.veilarbregistrering.db.arbeidssoker.MeldekortRepositoryImpl
import no.nav.fo.veilarbregistrering.db.migrering.konsument.MigrateRepositoryImpl
Expand Down Expand Up @@ -77,4 +79,9 @@ class RepositoryConfig {
fun migrateRepository(db: NamedParameterJdbcTemplate): MigrateRepository {
return MigrateRepositoryImpl(db)
}

@Bean
fun aktorIdCacheRepository(db: NamedParameterJdbcTemplate): AktorIdCacheRepository {
return AktorIdCacheRepositoryImpl(db)
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
package no.nav.fo.veilarbregistrering.db.aktorIdCache

import no.nav.fo.veilarbregistrering.aktorIdCache.AktorIdCache
import no.nav.fo.veilarbregistrering.aktorIdCache.AktorIdCacheRepository
import no.nav.fo.veilarbregistrering.bruker.Foedselsnummer
import no.nav.fo.veilarbregistrering.log.logger
import org.springframework.dao.DataIntegrityViolationException
import org.springframework.jdbc.core.RowMapper
import org.springframework.jdbc.core.namedparam.NamedParameterJdbcTemplate

class AktorIdCacheRepositoryImpl(private val db: NamedParameterJdbcTemplate) {
class AktorIdCacheRepositoryImpl(private val db: NamedParameterJdbcTemplate): AktorIdCacheRepository {

fun lagre(aktorIdCache: AktorIdCache){
override fun lagre(aktorIdCache: AktorIdCache) {
val params = mapOf(
"foedselsnummer" to aktorIdCache.foedselsnummer,
"aktor_id" to aktorIdCache.aktorId,
Expand All @@ -24,7 +25,7 @@ class AktorIdCacheRepositoryImpl(private val db: NamedParameterJdbcTemplate) {
}
}

fun hentAktørId(fnr: Foedselsnummer): AktorIdCache? {
override fun hentAktørId(fnr: Foedselsnummer): AktorIdCache? {
val sql = "SELECT * FROM aktor_id_cache WHERE foedselsnummer = :fnr"
val params = mapOf("fnr" to fnr.foedselsnummer)
return db.queryForObject(sql, params, aktorIdCacheRowMapper)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package no.nav.fo.veilarbregistrering.db

import no.nav.fo.veilarbregistrering.aktorIdCache.AktorIdCache
import no.nav.fo.veilarbregistrering.aktorIdCache.AktorIdCacheRepository
import no.nav.fo.veilarbregistrering.bruker.AktorId
import no.nav.fo.veilarbregistrering.bruker.Foedselsnummer
import no.nav.veilarbregistrering.integrasjonstest.db.DbContainerInitializer
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase
import org.springframework.boot.test.autoconfigure.jdbc.JdbcTest
import org.springframework.test.context.ActiveProfiles
import org.springframework.test.context.ContextConfiguration
import java.time.LocalDateTime
import kotlin.test.assertEquals
import kotlin.test.assertNotNull

@JdbcTest
@AutoConfigureTestDatabase(replace= AutoConfigureTestDatabase.Replace.NONE)
@ContextConfiguration(initializers = [DbContainerInitializer::class], classes = [ RepositoryConfig::class, DatabaseConfig::class ])
@ActiveProfiles("gcp")
class GcpAktorIdCacheRepositoryDbIntegrationTest(
@Autowired
private val aktorIdCacheRepository: AktorIdCacheRepository
) {

@Test
fun `skal hente aktørId basert på fødselsnummer`() {
val FOEDSELSNUMMER = Foedselsnummer("01234567890")
val AKTORID = AktorId("1000010000100")

aktorIdCacheRepository.lagre(AktorIdCache(FOEDSELSNUMMER.foedselsnummer, AKTORID.aktorId, LocalDateTime.now()))

val aktorIdCache = aktorIdCacheRepository.hentAktørId(FOEDSELSNUMMER)
assertNotNull(aktorIdCache)
assertEquals(AKTORID.aktorId, aktorIdCache.aktorId)
}
}

0 comments on commit 3d12581

Please sign in to comment.