From f27958c71731c0813a6bbb09c51ab2e1ceaf9a33 Mon Sep 17 00:00:00 2001 From: Jan Kroken Date: Mon, 25 Sep 2023 09:21:33 +0200 Subject: [PATCH] =?UTF-8?q?overv=C3=A5king=20-=20p=C3=A5g=C3=A5ende=20impl?= =?UTF-8?q?ementering?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build.gradle.kts | 4 ++- .../barnetrygd/domain/StatusService.kt | 27 +++++++++++++++++++ .../BarnetrygdInnlesingRepository.kt | 7 +++++ .../barnetrygd/domain/StatusServiceTest.kt | 26 ++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusService.kt create mode 100644 src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusServiceTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index 18f5444..0955dac 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -8,10 +8,11 @@ val hibernateValidatorVersion = "8.0.0.Final" val logbackEncoderVersion = "7.2" val postgresqlVersion = "42.5.1" val flywayCoreVersion = "9.11.0" -val testcontainersVersion = "1.17.6" +val testcontainersVersion = "1.19.0" val jacksonVersion = "2.14.1" val springKafkaTestVersion = "3.0.5" val azureAdClient = "0.0.7" +val assertjVersion = "3.24.2" plugins { kotlin("jvm") version "1.8.0" @@ -68,6 +69,7 @@ dependencies { testImplementation("org.testcontainers:postgresql:$testcontainersVersion") testImplementation("org.springframework.kafka:spring-kafka-test:$springKafkaTestVersion") testImplementation("org.mockito.kotlin:mockito-kotlin:5.1.0") + testImplementation("org.assertj:assertj-core:$assertjVersion") } tasks.test { diff --git a/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusService.kt b/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusService.kt new file mode 100644 index 0000000..82d0335 --- /dev/null +++ b/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusService.kt @@ -0,0 +1,27 @@ +package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.domain + +import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.repository.BarnetrygdInnlesingRepository +import org.slf4j.LoggerFactory +import org.springframework.stereotype.Service +import org.springframework.transaction.support.TransactionTemplate + +@Service +class StatusService( + private val repo: BarnetrygdInnlesingRepository, + private val transactionTemplate: TransactionTemplate, +) { + companion object { + private val log = LoggerFactory.getLogger(this::class.java) + } + + fun checkStatus(): ApplicationStatus { + if (repo.finnSisteInnlesing() == null) return ApplicationStatus.IkkeKjort + return ApplicationStatus.Feil(listOf("a", "b")) + } +} + +sealed class ApplicationStatus { + object OK : ApplicationStatus() + object IkkeKjort : ApplicationStatus() + class Feil(val feil: List) : ApplicationStatus() +} \ No newline at end of file diff --git a/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/repository/BarnetrygdInnlesingRepository.kt b/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/repository/BarnetrygdInnlesingRepository.kt index 2236c26..3576db7 100644 --- a/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/repository/BarnetrygdInnlesingRepository.kt +++ b/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/repository/BarnetrygdInnlesingRepository.kt @@ -68,6 +68,13 @@ class BarnetrygdInnlesingRepository( ).singleOrNull() } + fun finnSisteInnlesing(): BarnetrygdInnlesing? { + return jdbcTemplate.query( + """select * from innlesing order by forespurt_tidspunkt desc limit 1""", + InnlesingRowMapper() + ).singleOrNull() + } + fun invalider(id: UUID) { jdbcTemplate.update( """delete from innlesing where id = :id""", diff --git a/src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusServiceTest.kt b/src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusServiceTest.kt new file mode 100644 index 0000000..af67c91 --- /dev/null +++ b/src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/StatusServiceTest.kt @@ -0,0 +1,26 @@ +package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.domain + +import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.SpringContextTest +import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.repository.BarnetrygdInnlesingRepository +import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.repository.BarnetrygdmottakerRepository +import org.assertj.core.api.Assertions.assertThat +import org.junit.jupiter.api.Test +import org.springframework.beans.factory.annotation.Autowired + +class StatusServiceTest: SpringContextTest.NoKafka() { + + @Autowired + private lateinit var innlesingRepository: BarnetrygdInnlesingRepository + + @Autowired + private lateinit var barnetrygdmottakerRepository: BarnetrygdmottakerRepository + + @Autowired + private lateinit var statusService: StatusService + + @Test + fun testFantIngenInnlesninger() { + val status = statusService.checkStatus() + assertThat(status).isEqualTo(ApplicationStatus.IkkeKjort) + } +} \ No newline at end of file