1
1
package no.nav.helse.spesialist.e2etests
2
2
3
3
import com.github.navikt.tbd_libs.rapids_and_rivers.asLocalDateTime
4
+ import io.ktor.client.HttpClient
5
+ import io.ktor.client.engine.apache.Apache
4
6
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
5
7
import io.ktor.client.request.accept
6
8
import io.ktor.client.request.bearerAuth
7
9
import io.ktor.client.request.post
8
10
import io.ktor.client.request.setBody
9
- import io.ktor.http.ContentType.Application
11
+ import io.ktor.http.ContentType
10
12
import io.ktor.http.contentType
11
13
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
13
17
import kotliquery.queryOf
14
18
import kotliquery.sessionOf
15
19
import no.nav.helse.bootstrap.EnvironmentToggles
16
20
import no.nav.helse.modell.automatisering.Stikkprøver
17
21
import no.nav.helse.modell.oppgave.Egenskap
18
22
import no.nav.helse.modell.oppgave.Oppgave
23
+ import no.nav.helse.rapids_rivers.NaisEndpoints
24
+ import no.nav.helse.rapids_rivers.ktorApplication
19
25
import no.nav.helse.spesialist.api.bootstrap.Gruppe
20
26
import no.nav.helse.spesialist.api.bootstrap.Tilgangsgrupper
21
- import no.nav.helse.spesialist.api.objectMapper
22
27
import no.nav.helse.spesialist.api.testfixtures.ApiModuleIntegrationTestFixture
23
28
import no.nav.helse.spesialist.api.testfixtures.lagSaksbehandlerFraApi
24
29
import no.nav.helse.spesialist.bootstrap.Configuration
@@ -40,6 +45,7 @@ import org.junit.jupiter.api.Assertions.assertNotNull
40
45
import org.junit.jupiter.api.Assertions.assertTrue
41
46
import java.time.LocalDateTime
42
47
import java.util.UUID
48
+ import kotlin.random.Random
43
49
44
50
abstract class AbstractE2EIntegrationTest {
45
51
private val testPerson = TestPerson ()
@@ -92,10 +98,35 @@ abstract class AbstractE2EIntegrationTest {
92
98
),
93
99
rapidsConnection = testRapid,
94
100
)
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
+ }
95
125
}
96
126
97
127
init {
98
128
behovLøserStub.init (testPerson)
129
+ ktorApp.start()
99
130
}
100
131
101
132
protected val risikovurderingBehovLøser =
@@ -107,18 +138,10 @@ abstract class AbstractE2EIntegrationTest {
107
138
}
108
139
109
140
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 )
122
145
bearerAuth(ApiModuleIntegrationTestFixture .token(saksbehandler))
123
146
setBody(
124
147
mapOf (
0 commit comments