Skip to content

Commit 78e9f80

Browse files
MartinMekknavelgen
andcommittedMar 28, 2025··
♻️ Kjør én ekte ktor app for e2e tester
Co-authored-by: Svein Elgstøen <189128153+navelgen@users.noreply.github.com>
1 parent a059397 commit 78e9f80

File tree

1 file changed

+38
-15
lines changed

1 file changed

+38
-15
lines changed
 

‎spesialist-e2e-tests/src/test/kotlin/no/nav/helse/spesialist/e2etests/AbstractE2EIntegrationTest.kt

+38-15
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,29 @@
11
package no.nav.helse.spesialist.e2etests
22

33
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime
4+
import io.ktor.client.HttpClient
5+
import io.ktor.client.engine.apache.Apache
46
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
57
import io.ktor.client.request.accept
68
import io.ktor.client.request.bearerAuth
79
import io.ktor.client.request.post
810
import io.ktor.client.request.setBody
9-
import io.ktor.http.ContentType.Application
11+
import io.ktor.http.ContentType
1012
import io.ktor.http.contentType
1113
import io.ktor.serialization.jackson.JacksonConverter
12-
import io.ktor.server.testing.testApplication
14+
import io.micrometer.prometheusmetrics.PrometheusConfig
15+
import io.micrometer.prometheusmetrics.PrometheusMeterRegistry
16+
import kotlinx.coroutines.runBlocking
1317
import kotliquery.queryOf
1418
import kotliquery.sessionOf
1519
import no.nav.helse.bootstrap.EnvironmentToggles
1620
import no.nav.helse.modell.automatisering.Stikkprøver
1721
import no.nav.helse.modell.oppgave.Egenskap
1822
import no.nav.helse.modell.oppgave.Oppgave
23+
import no.nav.helse.rapids_rivers.NaisEndpoints
24+
import no.nav.helse.rapids_rivers.ktorApplication
1925
import no.nav.helse.spesialist.api.bootstrap.Gruppe
2026
import no.nav.helse.spesialist.api.bootstrap.Tilgangsgrupper
21-
import no.nav.helse.spesialist.api.objectMapper
2227
import no.nav.helse.spesialist.api.testfixtures.ApiModuleIntegrationTestFixture
2328
import no.nav.helse.spesialist.api.testfixtures.lagSaksbehandlerFraApi
2429
import no.nav.helse.spesialist.bootstrap.Configuration
@@ -40,6 +45,7 @@ import org.junit.jupiter.api.Assertions.assertNotNull
4045
import org.junit.jupiter.api.Assertions.assertTrue
4146
import java.time.LocalDateTime
4247
import java.util.UUID
48+
import kotlin.random.Random
4349

4450
abstract class AbstractE2EIntegrationTest {
4551
private val testPerson = TestPerson()
@@ -92,10 +98,35 @@ abstract class AbstractE2EIntegrationTest {
9298
),
9399
rapidsConnection = testRapid,
94100
)
101+
val port = Random.nextInt(10000, 20000)
102+
private val ktorApp = ktorApplication(
103+
meterRegistry = PrometheusMeterRegistry(PrometheusConfig.DEFAULT),
104+
naisEndpoints = NaisEndpoints.Default,
105+
port = port,
106+
aliveCheck = { true },
107+
readyCheck = { true },
108+
preStopHook = { },
109+
cioConfiguration = { },
110+
modules = listOf {
111+
rapidApp.ktorSetupCallback(this)
112+
}
113+
)
114+
private val httpClient: HttpClient =
115+
HttpClient(Apache) {
116+
install(ContentNegotiation) {
117+
register(ContentType.Application.Json, JacksonConverter())
118+
}
119+
engine {
120+
socketTimeout = 5_000
121+
connectTimeout = 5_000
122+
connectionRequestTimeout = 5_000
123+
}
124+
}
95125
}
96126

97127
init {
98128
behovLøserStub.init(testPerson)
129+
ktorApp.start()
99130
}
100131

101132
protected val risikovurderingBehovLøser =
@@ -107,18 +138,10 @@ abstract class AbstractE2EIntegrationTest {
107138
}
108139

109140
protected fun callGraphQL(operationName: String, variables: Map<String, Any>) {
110-
testApplication {
111-
application {
112-
rapidApp.ktorSetupCallback(this)
113-
}
114-
115-
createClient {
116-
install(ContentNegotiation) {
117-
register(Application.Json, JacksonConverter(objectMapper))
118-
}
119-
}.post("/graphql") {
120-
contentType(Application.Json)
121-
accept(Application.Json)
141+
runBlocking {
142+
httpClient.post("http://localhost:$port/graphql") {
143+
contentType(ContentType.Application.Json)
144+
accept(ContentType.Application.Json)
122145
bearerAuth(ApiModuleIntegrationTestFixture.token(saksbehandler))
123146
setBody(
124147
mapOf(

0 commit comments

Comments
 (0)
Please sign in to comment.