1
1
import io.javalin.Javalin
2
2
import io.javalin.openapi.OpenApi
3
3
import io.javalin.openapi.plugin.OpenApiPlugin
4
+ import kong.unirest.Unirest
5
+ import org.assertj.core.api.Assertions.assertThat
4
6
import org.junit.jupiter.api.Test
5
- import org.junit.jupiter.api.assertDoesNotThrow
6
7
7
8
class OpenApiPluginTest {
8
9
@@ -13,8 +14,10 @@ class OpenApiPluginTest {
13
14
14
15
@Test
15
16
fun `should support schema modifications in definition configuration` () {
16
- assertDoesNotThrow {
17
- Javalin .create { config ->
17
+ val app =
18
+ Javalin .createAndStart { config ->
19
+ config.jetty.defaultPort = 0
20
+
18
21
config.registerPlugin(
19
22
OpenApiPlugin { openApiConfig ->
20
23
openApiConfig.withDefinitionConfiguration { _, def ->
@@ -25,21 +28,40 @@ class OpenApiPluginTest {
25
28
}
26
29
)
27
30
}
31
+
32
+ try {
33
+ val response = Unirest .get(" http://localhost:${app.port()} /openapi" )
34
+ .asString()
35
+ .body
36
+
37
+ assertThat(response).contains(""" "title" : "My API"""" )
38
+ } finally {
39
+ app.stop()
28
40
}
29
41
}
30
42
31
43
@Test
32
44
fun `should support empty definition configuration` () {
33
- assertDoesNotThrow {
34
- Javalin .create { config ->
35
- config.registerPlugin(
36
- OpenApiPlugin {
37
- it.withDefinitionConfiguration { _, _ ->
38
- /* do nothing */
39
- }
45
+ val app = Javalin .createAndStart { config ->
46
+ config.jetty.defaultPort = 0
47
+
48
+ config.registerPlugin(
49
+ OpenApiPlugin {
50
+ it.withDefinitionConfiguration { _, _ ->
51
+ /* do nothing */
40
52
}
41
- )
42
- }
53
+ }
54
+ )
55
+ }
56
+
57
+ try {
58
+ val response = Unirest .get(" http://localhost:${app.port()} /openapi" )
59
+ .asString()
60
+ .body
61
+
62
+ assertThat(response).contains(""" "title" : """"" )
63
+ } finally {
64
+ app.stop()
43
65
}
44
66
}
45
67
0 commit comments