From 0ca08ec643a2a5f319b788185d74aafbc154a847 Mon Sep 17 00:00:00 2001 From: Mikael Bjerga <6940327+bjerga@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:00:42 +0200 Subject: [PATCH] Flytt testkode til fellesmodul (#556) --- api/build.gradle.kts | 1 - build.gradle.kts | 9 ++------- .../inntektsmelding/db/RepositoryTest.kt | 2 +- .../db/SelvbestemtImRepoTest.kt | 2 +- .../exposed => exposed/test}/FunSpecWithDb.kt | 2 +- felles-test/build.gradle.kts | 18 ------------------ felles/build.gradle.kts | 15 +++++++++++++++ .../test/mock/RandomDigitStringKtTest.kt | 0 .../felles/test/json/ReadFail.kt | 0 .../felles/test/mock/GyldigData.kt | 0 .../felles/test/mock/MockData.kt | 0 .../felles/test/mock/MockInntektsmelding.kt | 0 .../felles/test/mock/MockRedis.kt | 0 .../felles/test/mock/MockRedisClient.kt | 0 .../felles/test/mock/RandomDigitString.kt | 0 .../felles/test/rapidsrivers/TestRapidUtils.kt | 0 integrasjonstest/build.gradle.kts | 7 ++++--- .../notifikasjon/db/SelvbestemtRepoTest.kt | 2 +- 18 files changed, 25 insertions(+), 33 deletions(-) rename felles-db-exposed/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/db/{test/exposed => exposed/test}/FunSpecWithDb.kt (97%) delete mode 100644 felles-test/build.gradle.kts rename {felles-test => felles}/src/test/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitStringKtTest.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/json/ReadFail.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/GyldigData.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockData.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockInntektsmelding.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedis.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedisClient.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitString.kt (100%) rename {felles-test/src/main => felles/src/testFixtures}/kotlin/no/nav/helsearbeidsgiver/felles/test/rapidsrivers/TestRapidUtils.kt (100%) diff --git a/api/build.gradle.kts b/api/build.gradle.kts index 9d6b35008..3ef745252 100644 --- a/api/build.gradle.kts +++ b/api/build.gradle.kts @@ -34,5 +34,4 @@ dependencies { testImplementation("io.ktor:ktor-server-test-host:$ktorVersion") testImplementation("io.lettuce:lettuce-core:$lettuceVersion") testImplementation("no.nav.security:mock-oauth2-server:$mockOauth2ServerVersion") - testImplementation(project(":felles-test")) } diff --git a/build.gradle.kts b/build.gradle.kts index 72b3664c6..79d81b7c6 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -66,7 +66,7 @@ subprojects { ) tasks { - if (!project.erFellesModul() && !project.erFellesDatabaseModul() && !project.erFellesTestModul()) { + if (!project.erFellesModul() && !project.erFellesDatabaseModul()) { named("jar") { archiveBaseName.set("app") @@ -116,9 +116,7 @@ subprojects { dependencies { if (!erFellesModul()) { implementation(project(":felles")) - } - if (!erFellesTestModul()) { - testImplementation(project(":felles-test")) + testImplementation(testFixtures(project(":felles"))) } implementation("no.nav.helsearbeidsgiver:domene-inntektsmelding:$hagDomeneInntektsmeldingVersion") @@ -272,9 +270,6 @@ fun Project.erFellesModul(): Boolean = fun Project.erFellesDatabaseModul(): Boolean = name == "felles-db-exposed" -fun Project.erFellesTestModul(): Boolean = - name == "felles-test" - fun List.containsAny(vararg others: String): Boolean = this.intersect(others.toSet()).isNotEmpty() diff --git a/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/RepositoryTest.kt b/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/RepositoryTest.kt index 2f4c7227e..024eb5fa2 100644 --- a/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/RepositoryTest.kt +++ b/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/RepositoryTest.kt @@ -9,7 +9,7 @@ import io.kotest.matchers.nulls.shouldBeNull import io.kotest.matchers.nulls.shouldNotBeNull import io.kotest.matchers.shouldBe import io.kotest.matchers.shouldNotBe -import no.nav.helsearbeidsgiver.felles.db.test.exposed.FunSpecWithDb +import no.nav.helsearbeidsgiver.felles.db.exposed.test.FunSpecWithDb import no.nav.helsearbeidsgiver.inntektsmelding.db.tabell.ForespoerselEntitet import no.nav.helsearbeidsgiver.inntektsmelding.db.tabell.InntektsmeldingEntitet import org.jetbrains.exposed.sql.Database diff --git a/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/SelvbestemtImRepoTest.kt b/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/SelvbestemtImRepoTest.kt index c645d2931..eb03ece59 100644 --- a/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/SelvbestemtImRepoTest.kt +++ b/db/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/db/SelvbestemtImRepoTest.kt @@ -9,7 +9,7 @@ import io.kotest.matchers.shouldNotBe import no.nav.helsearbeidsgiver.domene.inntektsmelding.v1.Inntekt import no.nav.helsearbeidsgiver.domene.inntektsmelding.v1.Inntektsmelding import no.nav.helsearbeidsgiver.domene.inntektsmelding.v1.Naturalytelse -import no.nav.helsearbeidsgiver.felles.db.test.exposed.FunSpecWithDb +import no.nav.helsearbeidsgiver.felles.db.exposed.test.FunSpecWithDb import no.nav.helsearbeidsgiver.felles.test.mock.mockInntektsmeldingV1 import no.nav.helsearbeidsgiver.inntektsmelding.db.tabell.SelvbestemtInntektsmeldingEntitet import no.nav.helsearbeidsgiver.utils.test.date.oktober diff --git a/felles-db-exposed/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/db/test/exposed/FunSpecWithDb.kt b/felles-db-exposed/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/db/exposed/test/FunSpecWithDb.kt similarity index 97% rename from felles-db-exposed/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/db/test/exposed/FunSpecWithDb.kt rename to felles-db-exposed/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/db/exposed/test/FunSpecWithDb.kt index 6d3115912..44849e1f7 100644 --- a/felles-db-exposed/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/db/test/exposed/FunSpecWithDb.kt +++ b/felles-db-exposed/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/db/exposed/test/FunSpecWithDb.kt @@ -1,4 +1,4 @@ -package no.nav.helsearbeidsgiver.felles.db.test.exposed +package no.nav.helsearbeidsgiver.felles.db.exposed.test import com.zaxxer.hikari.HikariConfig import io.kotest.core.spec.style.FunSpec diff --git a/felles-test/build.gradle.kts b/felles-test/build.gradle.kts deleted file mode 100644 index 1004c7dd4..000000000 --- a/felles-test/build.gradle.kts +++ /dev/null @@ -1,18 +0,0 @@ -val lettuceVersion: String by project -val kotestVersion: String by project -val ktorVersion: String by project -val mockkVersion: String by project -val rapidsAndRiversVersion: String by project -val utilsVersion: String by project - -dependencies { - api("com.github.navikt:rapids-and-rivers:$rapidsAndRiversVersion") - api("io.ktor:ktor-client-core:$ktorVersion") - - implementation("io.kotest:kotest-assertions-core:$kotestVersion") - implementation("io.kotest:kotest-runner-junit5:$kotestVersion") - implementation("io.mockk:mockk:$mockkVersion") - - implementation("io.lettuce:lettuce-core:$lettuceVersion") - implementation(testFixtures("no.nav.helsearbeidsgiver:utils:$utilsVersion")) -} diff --git a/felles/build.gradle.kts b/felles/build.gradle.kts index abd2cd04f..7041b1f47 100644 --- a/felles/build.gradle.kts +++ b/felles/build.gradle.kts @@ -1,10 +1,25 @@ +val kotestVersion: String by project val lettuceVersion: String by project +val mockkVersion: String by project val rapidsAndRiversVersion: String by project val slf4jVersion: String by project +val utilsVersion: String by project + +plugins { + id("java-test-fixtures") +} dependencies { api("com.github.navikt:rapids-and-rivers:$rapidsAndRiversVersion") api("org.slf4j:slf4j-api:$slf4jVersion") implementation("io.lettuce:lettuce-core:$lettuceVersion") + + testFixturesApi("com.github.navikt:rapids-and-rivers:$rapidsAndRiversVersion") + testFixturesApi("io.lettuce:lettuce-core:$lettuceVersion") + + testFixturesImplementation("io.kotest:kotest-assertions-core:$kotestVersion") + testFixturesImplementation("io.kotest:kotest-runner-junit5:$kotestVersion") + testFixturesImplementation("io.mockk:mockk:$mockkVersion") + testFixturesImplementation(testFixtures("no.nav.helsearbeidsgiver:utils:$utilsVersion")) } diff --git a/felles-test/src/test/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitStringKtTest.kt b/felles/src/test/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitStringKtTest.kt similarity index 100% rename from felles-test/src/test/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitStringKtTest.kt rename to felles/src/test/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitStringKtTest.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/json/ReadFail.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/json/ReadFail.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/json/ReadFail.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/json/ReadFail.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/GyldigData.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/GyldigData.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/GyldigData.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/GyldigData.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockData.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockData.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockData.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockData.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockInntektsmelding.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockInntektsmelding.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockInntektsmelding.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockInntektsmelding.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedis.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedis.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedis.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedis.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedisClient.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedisClient.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedisClient.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/MockRedisClient.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitString.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitString.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitString.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/mock/RandomDigitString.kt diff --git a/felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/rapidsrivers/TestRapidUtils.kt b/felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/rapidsrivers/TestRapidUtils.kt similarity index 100% rename from felles-test/src/main/kotlin/no/nav/helsearbeidsgiver/felles/test/rapidsrivers/TestRapidUtils.kt rename to felles/src/testFixtures/kotlin/no/nav/helsearbeidsgiver/felles/test/rapidsrivers/TestRapidUtils.kt diff --git a/integrasjonstest/build.gradle.kts b/integrasjonstest/build.gradle.kts index c0cae2da5..4f8aa4b89 100644 --- a/integrasjonstest/build.gradle.kts +++ b/integrasjonstest/build.gradle.kts @@ -18,9 +18,6 @@ dependencies { testImplementation(project(":brreg")) testImplementation(project(":db")) testImplementation(project(":distribusjon")) - testImplementation(project(":felles")) - testImplementation(project(":felles-db-exposed")) - testImplementation(project(":felles-test")) testImplementation(project(":forespoersel-besvart")) testImplementation(project(":forespoersel-marker-besvart")) testImplementation(project(":forespoersel-mottatt")) @@ -35,6 +32,10 @@ dependencies { testImplementation(project(":tilgangservice")) testImplementation(project(":trengerservice")) + testImplementation(project(":felles")) + testImplementation(project(":felles-db-exposed")) + + testImplementation(testFixtures(project(":felles"))) testImplementation(testFixtures(project(":felles-db-exposed"))) // Klienter diff --git a/notifikasjon/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/notifikasjon/db/SelvbestemtRepoTest.kt b/notifikasjon/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/notifikasjon/db/SelvbestemtRepoTest.kt index c48619eba..ebff30404 100644 --- a/notifikasjon/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/notifikasjon/db/SelvbestemtRepoTest.kt +++ b/notifikasjon/src/test/kotlin/no/nav/helsearbeidsgiver/inntektsmelding/notifikasjon/db/SelvbestemtRepoTest.kt @@ -4,7 +4,7 @@ import io.kotest.assertions.throwables.shouldThrowExactly import io.kotest.matchers.collections.shouldHaveSize import io.kotest.matchers.ints.shouldBeExactly import io.kotest.matchers.shouldBe -import no.nav.helsearbeidsgiver.felles.db.test.exposed.FunSpecWithDb +import no.nav.helsearbeidsgiver.felles.db.exposed.test.FunSpecWithDb import no.nav.helsearbeidsgiver.inntektsmelding.notifikasjon.sakLevetid import org.jetbrains.exposed.exceptions.ExposedSQLException import org.jetbrains.exposed.sql.Database