forked from LukasForst/ktor-openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 1
/
MinimalExampleTest.kt
33 lines (29 loc) · 1.24 KB
/
MinimalExampleTest.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import io.ktor.client.call.body
import io.ktor.client.plugins.contentnegotiation.ContentNegotiation
import io.ktor.client.request.get
import io.ktor.client.request.header
import io.ktor.client.request.post
import io.ktor.client.request.setBody
import io.ktor.http.ContentType
import io.ktor.http.HttpHeaders
import io.ktor.http.HttpStatusCode
import io.ktor.serialization.jackson.jackson
import io.ktor.server.application.Application
import io.ktor.server.testing.testApplication
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
class MinimalExampleTest {
@Test
fun `test that minimal example works`(): Unit = testApplication {
application(Application::minimalExample)
val client = createClient { install(ContentNegotiation) { jackson() } }
val openapi = client.get("/openapi.json")
assertEquals(HttpStatusCode.OK, openapi.status)
val response = client.post("/example/world") {
header(HttpHeaders.ContentType, ContentType.Application.Json.toString())
setBody(SomeRequest(foo = "hello from body"))
}
assertEquals(HttpStatusCode.OK, response.status)
assertEquals(SomeResponse(bar = "Hello world! From body: hello from body."), response.body())
}
}