Skip to content

Commit 51d813f

Browse files
committed
GH-237 Run OpenApiPlugin tests on a running server + bump JDK on CI to 21
1 parent a2546cc commit 51d813f

File tree

2 files changed

+35
-14
lines changed

2 files changed

+35
-14
lines changed

.github/workflows/gradle.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@ jobs:
1010
runs-on: ubuntu-latest
1111
strategy:
1212
matrix:
13-
# LTS and the latest one
14-
jdk: [ 17, 19 ]
13+
jdk: [ 17, 21 ]
1514
steps:
1615
- uses: actions/checkout@v2
1716
- name: Set up JDK

javalin-plugins/javalin-openapi-plugin/src/test/kotlin/OpenApiPluginTest.kt

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import io.javalin.Javalin
22
import io.javalin.openapi.OpenApi
33
import io.javalin.openapi.plugin.OpenApiPlugin
4+
import kong.unirest.Unirest
5+
import org.assertj.core.api.Assertions.assertThat
46
import org.junit.jupiter.api.Test
5-
import org.junit.jupiter.api.assertDoesNotThrow
67

78
class OpenApiPluginTest {
89

@@ -13,8 +14,10 @@ class OpenApiPluginTest {
1314

1415
@Test
1516
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+
1821
config.registerPlugin(
1922
OpenApiPlugin { openApiConfig ->
2023
openApiConfig.withDefinitionConfiguration { _, def ->
@@ -25,21 +28,40 @@ class OpenApiPluginTest {
2528
}
2629
)
2730
}
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()
2840
}
2941
}
3042

3143
@Test
3244
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 */
4052
}
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()
4365
}
4466
}
4567

0 commit comments

Comments
 (0)