diff --git a/build.gradle.kts b/build.gradle.kts index c0f2ad153..8f1067a62 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -9,6 +9,7 @@ val prometheusVersion = "0.16.0" val micrometerVersion = "1.12.5" val kotestVersion = "5.8.1" val kotestExtensionsVersion = "2.0.0" +val h2Version = "2.2.224" val mockkVersion = "1.13.10" val slf4jVersion = "2.0.12" val logbackVersion = "1.5.4" @@ -19,7 +20,6 @@ val hikariVersion = "5.1.0" val flywayVersion = "10.10.0" val vaultJdbcVersion = "1.3.9" val jacksonVersion = "2.17.0" -val postgresEmbeddedVersion = "1.0.3" val kafkaVersion = "3.6.0" val avroVersion = "1.11.3" val confluentVersion = "7.6.0" @@ -126,13 +126,13 @@ dependencies { testImplementation(kotlin("test")) testImplementation("org.amshove.kluent:kluent:$kluentVersion") testImplementation("io.mockk:mockk:$mockkVersion") - testImplementation("com.opentable.components:otj-pg-embedded:$postgresEmbeddedVersion") testImplementation("org.jetbrains.kotlin:kotlin-test:$kotlinVersion") testImplementation("io.ktor:ktor-server-test-host-jvm:$ktorVersion") testImplementation("io.kotest:kotest-runner-junit5-jvm:$kotestVersion") testImplementation("io.kotest:kotest-assertions-core:$kotestVersion") testImplementation("io.kotest:kotest-property:$kotestVersion") testImplementation("io.kotest.extensions:kotest-assertions-ktor:$kotestExtensionsVersion") + testImplementation("com.h2database:h2:$h2Version") constraints { implementation("org.apache.zookeeper:zookeeper") { diff --git a/src/main/resources/db/migration/V12__Add_column_utsendt_varsel.sql b/src/main/resources/db/migration/V12__Add_column_utsendt_varsel.sql index 699b373bc..07787d5ab 100644 --- a/src/main/resources/db/migration/V12__Add_column_utsendt_varsel.sql +++ b/src/main/resources/db/migration/V12__Add_column_utsendt_varsel.sql @@ -1,7 +1,4 @@ -ALTER TABLE UTSENDT_VARSEL - ADD COLUMN narmesteleder_fnr varchar(11), - ADD COLUMN orgnummer varchar(9), - ADD COLUMN kanal varchar(50); - -ALTER TABLE UTSENDT_VARSEL - ALTER COLUMN aktor_id DROP NOT NULL; +ALTER TABLE UTSENDT_VARSEL ADD COLUMN narmesteleder_fnr varchar(11); +ALTER TABLE UTSENDT_VARSEL ADD COLUMN orgnummer varchar(9); +ALTER TABLE UTSENDT_VARSEL ADD COLUMN kanal varchar(50); +ALTER TABLE UTSENDT_VARSEL ALTER COLUMN aktor_id DROP NOT NULL; diff --git a/src/main/resources/db/migration/V23__Access_for_esyfo_analyse.sql b/src/main/resources/db/migration/V23__Access_for_esyfo_analyse.sql index 9a546f4a6..ce9bc3984 100644 --- a/src/main/resources/db/migration/V23__Access_for_esyfo_analyse.sql +++ b/src/main/resources/db/migration/V23__Access_for_esyfo_analyse.sql @@ -1,3 +1,6 @@ +/* +Removed to support H2 database + DO $$ BEGIN CREATE USER "esyfo-analyse"; @@ -7,3 +10,4 @@ END $$; GRANT SELECT ON ALL TABLES IN SCHEMA PUBLIC TO "esyfo-analyse"; +*/ \ No newline at end of file diff --git a/src/test/kotlin/no/nav/syfo/db/FodselsdatoDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/FodselsdatoDAOSpek.kt index a807005e6..83e0247e5 100644 --- a/src/test/kotlin/no/nav/syfo/db/FodselsdatoDAOSpek.kt +++ b/src/test/kotlin/no/nav/syfo/db/FodselsdatoDAOSpek.kt @@ -6,15 +6,11 @@ import org.amshove.kluent.* class FodselsdatoDAOSpek : DescribeSpec({ describe("FodselsdatoDAOSpek") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() beforeTest { embeddedDatabase.connection.dropData() } - afterTest { - embeddedDatabase.stop() - } - it("Should fetch birthdate") { val fodselsdato = "1988-01-01" embeddedDatabase.storeFodselsdato(arbeidstakerFnr1, fodselsdato) diff --git a/src/test/kotlin/no/nav/syfo/db/MikrofrontendSynlighetDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/MikrofrontendSynlighetDAOSpek.kt index 1297024eb..0adcba95e 100644 --- a/src/test/kotlin/no/nav/syfo/db/MikrofrontendSynlighetDAOSpek.kt +++ b/src/test/kotlin/no/nav/syfo/db/MikrofrontendSynlighetDAOSpek.kt @@ -13,16 +13,12 @@ import java.time.LocalDate class MikrofrontendSynlighetDAOSpek : DescribeSpec({ describe("MikrofrontendSynlighetDAOSpek") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() - afterTest { + beforeTest { embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - val mikrofrontendSynlighet1 = MikrofrontendSynlighet( arbeidstakerFnr1, Tjeneste.DIALOGMOTE, diff --git a/src/test/kotlin/no/nav/syfo/db/PlanlagtVarselDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/PlanlagtVarselDAOSpek.kt index 05c428192..267d98130 100644 --- a/src/test/kotlin/no/nav/syfo/db/PlanlagtVarselDAOSpek.kt +++ b/src/test/kotlin/no/nav/syfo/db/PlanlagtVarselDAOSpek.kt @@ -17,16 +17,12 @@ import java.time.LocalDate class PlanlagtVarselDAOSpek : DescribeSpec({ describe("PlanlagtVarselDAOSpek") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() - afterTest { + beforeTest { embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - it("Store and fetch PlanlagtVarsel") { val planlagtVarselToStore1 = PlanlagtVarsel( arbeidstakerFnr1, diff --git a/src/test/kotlin/no/nav/syfo/db/UtbetalingerDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/UtbetalingerDAOSpek.kt index a993aa0c9..53a77a177 100644 --- a/src/test/kotlin/no/nav/syfo/db/UtbetalingerDAOSpek.kt +++ b/src/test/kotlin/no/nav/syfo/db/UtbetalingerDAOSpek.kt @@ -17,20 +17,16 @@ import java.util.* class UtbetalingerDAOSpek : DescribeSpec({ describe("UtbetalingerDAOSpek") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val nowPlus1Day = now().plusDays(1) val nowPlus2Days = now().plusDays(2) val nowMinus1Day = now().minusDays(1) val nowMinus2Days = now().minusDays(2) - afterTest { + beforeTest { embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - it("Should include utbetaling with max date 14 days in the future, and gjenstående sykedager < 91") { val spleisUtbetaling = spleisUtbetaling(forelopigBeregnetSluttPaSykepenger = now().plusDays(14), gjenstaendeSykedager = 90) diff --git a/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt b/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt index faaa906f7..77026bd4e 100644 --- a/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt +++ b/src/test/kotlin/no/nav/syfo/db/UtsendtVarselFeiletDAOSpek.kt @@ -13,16 +13,12 @@ import java.util.* class UtsendtVarselFeiletDAOSpek : DescribeSpec({ describe("UtsendtVarselFeiletDAOSpek") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() - afterTest { + beforeTest { embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - it("Store ikke-utsendt varsel til NL i database") { val fnr = "12121212121" embeddedDatabase.storeUtsendtVarselFeilet(ikkeUtsendtVarsel(fnr)) diff --git a/src/test/kotlin/no/nav/syfo/service/DialogmoteInnkallingVarselServiceSpek.kt b/src/test/kotlin/no/nav/syfo/service/DialogmoteInnkallingVarselServiceSpek.kt index 7d44386f1..f5e1dc0b5 100644 --- a/src/test/kotlin/no/nav/syfo/service/DialogmoteInnkallingVarselServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/DialogmoteInnkallingVarselServiceSpek.kt @@ -31,7 +31,7 @@ class DialogmoteInnkallingVarselServiceSpek : DescribeSpec({ val brukernotifikasjonerService = mockk() val arbeidsgiverNotifikasjonService = mockk() val fysiskBrevUtsendingService = mockk() - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val fakeDialogmoterUrl = "http://localhost/dialogmoter" val journalpostUuid = "97b886fe-6beb-40df-af2b-04e504bc340c" val journalpostId = "1" @@ -59,14 +59,10 @@ class DialogmoteInnkallingVarselServiceSpek : DescribeSpec({ justRun { dittSykefravaerMeldingKafkaProducer.ferdigstillMelding(any(), any()) } coJustRun { fysiskBrevUtsendingService.sendBrev(any(), any(), DistibusjonsType.ANNET) } - afterTest { + beforeTest { embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - it("Non-reserved users should be notified externally") { coEvery { accessControlService.getUserAccessStatus(fnr1) } returns UserAccessStatus(fnr1, true) diff --git a/src/test/kotlin/no/nav/syfo/service/MerVeiledningVarselFinderSpek.kt b/src/test/kotlin/no/nav/syfo/service/MerVeiledningVarselFinderSpek.kt index b1293feb9..9b67780fa 100644 --- a/src/test/kotlin/no/nav/syfo/service/MerVeiledningVarselFinderSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/MerVeiledningVarselFinderSpek.kt @@ -26,7 +26,7 @@ import java.util.* class MerVeiledningVarselFinderSpek : DescribeSpec({ - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val sykmeldingerConsumerMock: SykmeldingerConsumer = mockk(relaxed = true) val sykmeldingServiceMockk = SykmeldingService(sykmeldingerConsumerMock) val pdlConsumerMockk: PdlConsumer = mockk(relaxed = true) @@ -65,15 +65,11 @@ class MerVeiledningVarselFinderSpek : DescribeSpec({ ) describe("MerVeiledningVarselFinderSpek") { - afterTest { + beforeTest { clearAllMocks() embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - it("Should send MER_VEILEDNING when it was not sent during past 3 months") { coEvery { pdlConsumerMockk.isBrukerYngreEnnGittMaxAlder(any(), any()) } returns true coEvery { sykmeldingServiceMockk.isPersonSykmeldtPaDato(LocalDate.now(), arbeidstakerFnr1) } returns true diff --git a/src/test/kotlin/no/nav/syfo/service/MikrofrontendServiceSpek.kt b/src/test/kotlin/no/nav/syfo/service/MikrofrontendServiceSpek.kt index 1c1a1b7ec..7dc67f889 100644 --- a/src/test/kotlin/no/nav/syfo/service/MikrofrontendServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/MikrofrontendServiceSpek.kt @@ -26,7 +26,7 @@ import kotlin.test.assertEquals import kotlin.test.assertFailsWith class MikrofrontendServiceSpek : DescribeSpec({ - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val minSideMicrofrontendKafkaProducer: MinSideMicrofrontendKafkaProducer = mockk(relaxed = true) val mikrofrontendDialogmoteService = MikrofrontendDialogmoteService(embeddedDatabase) val mikrofrontendAktivitetskravService = MikrofrontendAktivitetskravService(embeddedDatabase) @@ -37,15 +37,11 @@ class MikrofrontendServiceSpek : DescribeSpec({ embeddedDatabase ) - afterTest { + beforeTest { clearAllMocks() embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - describe("MikrofrontendServiceSpek") { justRun { minSideMicrofrontendKafkaProducer.sendRecordToMinSideTopic(any()) } diff --git a/src/test/kotlin/no/nav/syfo/service/OppfolgingsplanVarselServiceSpek.kt b/src/test/kotlin/no/nav/syfo/service/OppfolgingsplanVarselServiceSpek.kt index c470e99be..0d5e205f2 100644 --- a/src/test/kotlin/no/nav/syfo/service/OppfolgingsplanVarselServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/OppfolgingsplanVarselServiceSpek.kt @@ -24,7 +24,7 @@ class OppfolgingsplanVarselServiceSpek : DescribeSpec({ val brukernotifikasjonerService = mockk() val arbeidsgiverNotifikasjonService = mockk() val fysiskBrevUtsendingService = mockk() - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val fakeOppfolgingsplanerUrl = "http://localhost/oppfolgingsplaner" val senderFacade = SenderFacade( diff --git a/src/test/kotlin/no/nav/syfo/service/SenderFacadeSpek.kt b/src/test/kotlin/no/nav/syfo/service/SenderFacadeSpek.kt index 62e20324b..5e83f17ee 100644 --- a/src/test/kotlin/no/nav/syfo/service/SenderFacadeSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/SenderFacadeSpek.kt @@ -22,7 +22,7 @@ import java.util.* class SenderFacadeSpek : DescribeSpec({ describe("SenderFacadeSpek") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val arbeidsgiverNotifikasjonService: ArbeidsgiverNotifikasjonService = mockk(relaxed = true) val dineSykmeldteHendelseKafkaProducer: DineSykmeldteHendelseKafkaProducer = mockk(relaxed = true) @@ -86,16 +86,11 @@ class SenderFacadeSpek : DescribeSpec({ eksternReferanse = eksternRefDittSykefravaer, ) - afterTest { + beforeTest { clearAllMocks() embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - - it("Complete notifications for user") { embeddedDatabase.storeUtsendtVarsel(arbeidsgivernotifikasjonUtsendtVarsel) diff --git a/src/test/kotlin/no/nav/syfo/service/SykepengerMaxDateServiceSpek.kt b/src/test/kotlin/no/nav/syfo/service/SykepengerMaxDateServiceSpek.kt index 4b891aed9..d22cc68ba 100644 --- a/src/test/kotlin/no/nav/syfo/service/SykepengerMaxDateServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/SykepengerMaxDateServiceSpek.kt @@ -17,7 +17,7 @@ import kotlin.test.assertEquals class SykepengerMaxDateServiceSpek : DescribeSpec({ describe("SykepengerMaxDateService") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val pdlConsumer = mockk(relaxed = true) val sykepengerMaxDateService = SykepengerMaxDateService(embeddedDatabase, pdlConsumer) coEvery { pdlConsumer.hentPerson(any()) } returns PdlHentPerson( @@ -27,14 +27,10 @@ class SykepengerMaxDateServiceSpek : DescribeSpec({ foedsel = listOf(PdlFoedsel("1986-01-01")) ) ) - afterTest { + beforeTest { embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - it("Should store spleis utbetaling") { val utbetalingUtbetalt = UtbetalingSpleis( fødselsnummer = "123", diff --git a/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt b/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt index 3e873492b..a840ec760 100644 --- a/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt +++ b/src/test/kotlin/no/nav/syfo/service/TestdataResetServiceSpek.kt @@ -26,7 +26,7 @@ import java.util.* class TestdataResetServiceSpek : DescribeSpec({ describe("TestdataResetServiceSpek") { - val embeddedDatabase by lazy { EmbeddedDatabase() } + val embeddedDatabase = EmbeddedDatabase() val mikrofrontendService: MikrofrontendService = mockk(relaxed = true) val senderFacade: SenderFacade = mockk(relaxed = true) val testdataResetService = TestdataResetService(embeddedDatabase, mikrofrontendService, senderFacade) @@ -83,15 +83,10 @@ class TestdataResetServiceSpek : DescribeSpec({ val mikrofrontendSynlighet = MikrofrontendSynlighet(arbeidstakerFnr1, Tjeneste.DIALOGMOTE, LocalDate.now().plusWeeks(1)) - afterTest { + beforeTest { embeddedDatabase.connection.dropData() } - afterSpec { - embeddedDatabase.stop() - } - - it("Reset all testdata") { embeddedDatabase.storePlanlagtVarsel(planlagtVarsel) embeddedDatabase.storeUtsendtVarsel(utsendtVarsel) diff --git a/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt b/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt index 2afbd5cca..a59ce826e 100644 --- a/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt +++ b/src/test/kotlin/no/nav/syfo/testutil/EmbeddedDatabase.kt @@ -1,6 +1,7 @@ package no.nav.syfo.testutil -import com.opentable.db.postgres.embedded.EmbeddedPostgres +import com.zaxxer.hikari.HikariConfig +import com.zaxxer.hikari.HikariDataSource import no.nav.syfo.db.DatabaseInterface import org.flywaydb.core.Flyway import org.slf4j.Logger @@ -8,23 +9,32 @@ import org.slf4j.LoggerFactory import java.sql.Connection class EmbeddedDatabase : DatabaseInterface { - private val pg: EmbeddedPostgres - - override val connection: Connection - get() = pg.postgresDatabase.connection.apply { autoCommit = false } - override val log: Logger = LoggerFactory.getLogger(EmbeddedDatabase::class.qualifiedName) + private val dataSource: HikariDataSource init { - pg = EmbeddedPostgres.start() + val config = HikariConfig().apply { + jdbcUrl = "jdbc:h2:mem:lps-db;MODE=PostgreSQL;DB_CLOSE_DELAY=-1;" + username = "sa" + password = "" + maximumPoolSize = 2 + minimumIdle = 1 + isAutoCommit = false + transactionIsolation = "TRANSACTION_REPEATABLE_READ" + validate() + } - Flyway.configure().connectRetries(3).run { - dataSource(pg.postgresDatabase).load().migrate() + dataSource = HikariDataSource(config) + + Flyway.configure().dataSource(dataSource).load().apply { + migrate() + validate() } } - fun stop() { - pg.close() - } + override val connection: Connection + get() = dataSource.connection.apply { autoCommit = false } + override val log: Logger + get() = LoggerFactory.getLogger(EmbeddedDatabase::class.qualifiedName) } fun Connection.dropData() {