I have upgraded Kotest from 5.9 to 6.0.0.M1. And b...
# kotest
m
I have upgraded Kotest from 5.9 to 6.0.0.M1. And before upgrade I had this Listener for wiremock:
Copy code
import com.github.tomakehurst.wiremock.WireMockServer
import com.github.tomakehurst.wiremock.client.WireMock.configureFor
import io.kotest.core.config.AbstractProjectConfig
import io.kotest.extensions.wiremock.ListenerMode
import io.kotest.extensions.wiremock.WireMockListener
import io.mockk.coEvery
import io.mockk.mockk
import no.nav.sokos.spk.mottak.security.AccessTokenClient

private const val WIREMOCK_SERVER_PORT = 9001

object WiremockListener : AbstractProjectConfig() {
    val wiremock = WireMockServer(WIREMOCK_SERVER_PORT)
    val accessTokenClient = mockk<AccessTokenClient>()

    private val wiremockListener = WireMockListener(wiremock, ListenerMode.PER_SPEC)

    override fun extensions() = listOf(wiremockListener)

    override suspend fun beforeProject() {
        configureFor(WIREMOCK_SERVER_PORT)
        coEvery { accessTokenClient.getSystemToken() } returns "token"
    }
}
And using it like this:
Copy code
internal class PdlServiceTest :
    FunSpec({

        val pdlService =
            PdlService(
                pdlUrl = wiremock.baseUrl(),
                accessTokenClient = WiremockListener.accessTokenClient,
            )

        test("hent identer fra PDL gir respons med identer") {

            val identerFunnetOkResponse = readFromResource("/pdl/hentIdenterBolkOkResponse.json")

            wiremock.stubFor(
                WireMock
                    .post(urlEqualTo("/graphql"))
                    .willReturn(
                        aResponse()
                            .withHeader(HttpHeaders.ContentType, APPLICATION_JSON.mimeType)
                            .withStatus(HttpStatusCode.OK.value)
                            .withBody(identerFunnetOkResponse),
                    ),
            )

            val response = pdlService.getIdenterBolk(listOf("12345678912", "01111953488", "40074203226"))

            response.size shouldBe 3
}
But now i get this error:
Copy code
> Task :test
no.nav.sokos.spk.mottak.pdl.PdlServiceTest > SpecInstantiationException FAILED
    java.lang.reflect.InvocationTargetException
        at java.base/java.lang.reflect.Constructor.newInstanceWithCaller(Constructor.java:502)
        at java.base/java.lang.reflect.Constructor.newInstance(Constructor.java:486)
        at kotlin.reflect.jvm.internal.calls.CallerImpl$Constructor.call(CallerImpl.kt:41)
        at kotlin.reflect.jvm.internal.KCallableImpl.call(KCallableImpl.kt:108)
        at io.kotest.engine.spec.InstantiateSpecKt.javaReflectNewInstance(instantiateSpec.kt:73)
        at io.kotest.engine.spec.InstantiateSpecKt.createAndInitializeSpec(instantiateSpec.kt:33)
        at io.kotest.engine.spec.InstantiateSpecKt.instantiate(instantiateSpec.kt:16)
        at io.kotest.engine.spec.SpecRefKt.instance(SpecRef.kt:14)
  .........................

        Caused by:
        java.lang.IllegalStateException: Not listening on HTTP port. Either HTTP is not enabled or the WireMock server is stopped.
            at com.github.tomakehurst.wiremock.common.ParameterUtils.checkState(ParameterUtils.java:54)
            at com.github.tomakehurst.wiremock.WireMockServer.port(WireMockServer.java:229)
            at com.github.tomakehurst.wiremock.WireMockServer.baseUrl(WireMockServer.java:253)
            at no.nav.sokos.spk.mottak.pdl.PdlServiceTest._init_$lambda$0(PdlServiceTest.kt:22)
            at io.kotest.core.spec.style.FunSpec.<init>(funSpec.kt:25)
            at no.nav.sokos.spk.mottak.pdl.PdlServiceTest.<init>(PdlServiceTest.kt:18)
What has been changed?
Its worked before upgrading to 6.0.0.M1
e
AbstractProjectConfig
is no longer automatically scanned for. You need to create a
kotest.properties
file in your test resources with
Copy code
kotest.framework.config.fqn=com.mypackage.WiremockListener
m
Ah ok, so thats the new way to do it in version 6.0 ?
e
It has existed for a long time. The breaking change in 6.0 is that scanning is disabled by default (not sure if you can re-enable it again somehow if you'd prefer that.. but you will have faster test startup times by migrating to the suggested solution)
👍 1
m
Thank you for helping me out 🙂