forked from LukasForst/ktor-openapi-generator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMinimalExampleTest.kt
47 lines (40 loc) · 1.64 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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import io.ktor.client.call.*
import io.ktor.client.plugins.contentnegotiation.*
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.serialization.jackson.*
import io.ktor.server.application.*
import io.ktor.server.testing.*
import org.junit.jupiter.api.Test
import kotlin.test.assertEquals
import kotlin.test.assertTrue
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")
val body = openapi.body<String>()
assertEquals(HttpStatusCode.OK, openapi.status)
assertTrue(body.isNotEmpty())
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()
)
}
@Test
fun `test forbidden route and respondWithStatus`(): Unit = testApplication {
application(Application::minimalExample)
val client = createClient { install(ContentNegotiation) { jackson() } }
val response = client.get("/forbidden/112") {
header(HttpHeaders.Accept, ContentType.Application.Pdf.toString())
header(HttpHeaders.ContentType, ContentType.Application.Pdf.toString())
}
assertEquals(Unit, response.body<Unit>())
}
}